fix: Update shakedex js to not require user input

This commit is contained in:
Nathan Woodburn 2025-01-30 22:02:33 +11:00
parent c00603c020
commit ba7a73d1a9
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 15 additions and 33 deletions

View File

@ -139,27 +139,23 @@ def startListingTransfer(params, authentication):
# node node_modules/shakedex/bin/shakedex transfer-lock domain -n main -w wallet -a key -p ./data --httphost host # node node_modules/shakedex/bin/shakedex transfer-lock domain -n main -w wallet -a key -p ./data --httphost host
process = subprocess.Popen( process = subprocess.Popen(
["node", f"{path}/node_modules/shakedex/bin/shakedex", "transfer-lock", domain, "-n", "main", "-w", wallet, "-a", api_key, "-p", f"{path}/data", "--httphost", host], ["node", f"{path}/node_modules/shakedex/bin/shakedex", "transfer-lock", domain, "-n", "main", "-w", wallet, "-a", api_key, "-p", f"{path}/data", "--httphost", host, "-P", passphrase],
stdin=subprocess.PIPE, text=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.STDOUT
text=True
) )
process.stdin.write('\n') # For yes prompt # Wait for the process to finish
process.stdin.flush()
process.stdin.write(passphrase + '\n') # For passphrase
process.stdin.flush()
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
print(stdout)
print(stderr) print(f"STDOUT: {stdout}")
print(f"STDERR: {stderr}")
if process.returncode != 0: if process.returncode != 0:
return {"status": "Error: " + stderr} return {"status": f"Error: {stderr}", "txid": None}
txhash = stdout.split(" hash ")[1].split("\n")[0]
txhash:str = stdout.split(" hash ")[1]
txhash = txhash.split("\n")[0].rstrip('.')
return {"status": "Success", "txid": txhash} return {"status": "Success", "txid": txhash}
def list(params, authentication): def list(params, authentication):

View File

@ -1,6 +1,6 @@
const { NodeClient, WalletClient } = require('hsd/lib/client'); const { NodeClient, WalletClient } = require('hsd/lib/client');
const Network = require('hsd/lib/protocol/network.js'); const Network = require('hsd/lib/protocol/network.js');
const passwordPrompt = require('password-prompt'); const readline = require("readline");
class Context { class Context {
constructor( constructor(
@ -65,13 +65,3 @@ exports.Context = Context;
exports.staticPassphraseGetter = function (passphrase) { exports.staticPassphraseGetter = function (passphrase) {
return () => new Promise((resolve) => resolve(passphrase)); return () => new Promise((resolve) => resolve(passphrase));
}; };
function noopPassphraseGetter() {
return new Promise((resolve) => resolve(null));
}
exports.promptPassphraseGetter = function (
prefix = '>> Please enter your passphrase: '
) {
return () => new Promise((resolve) => resolve(passwordPrompt(prefix)));
};

View File

@ -53,7 +53,8 @@ program
'https://api.shakedex.com', 'https://api.shakedex.com',
) )
.option('--no-passphrase', 'Disable prompts for the wallet passphrase.') .option('--no-passphrase', 'Disable prompts for the wallet passphrase.')
.option('-H, --httphost <host>', 'HSD Host.', '127.0.0.1'); .option('-H, --httphost <host>', 'HSD Host.', '127.0.0.1')
.option('-P --password <password','Password for wallet.');
program program
.command('create-external-lock <name>') .command('create-external-lock <name>')
@ -155,7 +156,7 @@ function getContext(opts) {
opts.network, opts.network,
opts.walletId, opts.walletId,
opts.apiKey, opts.apiKey,
opts.passphrase ? promptPassphraseGetter() : staticPassphraseGetter(null), opts.passphrase = staticPassphraseGetter(opts.password),
opts.httphost, opts.httphost,
); );
} }
@ -261,11 +262,6 @@ async function viewExternalLock(name) {
async function transferLock(name) { async function transferLock(name) {
const {db, context} = await setupCLI(); const {db, context} = await setupCLI();
await confirm(
`Your name ${name} will be transferred to a locking script. ` +
'This can be undone, but requires additional on-chain transactions. Do you wish to continue?',
);
log('Performing locking script transfer.'); log('Performing locking script transfer.');
const lockTransfer = await transferNameLock(context, name); const lockTransfer = await transferNameLock(context, name);
await db.putLockTransfer(lockTransfer); await db.putLockTransfer(lockTransfer);