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
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],
stdin=subprocess.PIPE,
["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],
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
stderr=subprocess.STDOUT
)
process.stdin.write('\n') # For yes prompt
process.stdin.flush()
process.stdin.write(passphrase + '\n') # For passphrase
process.stdin.flush()
# Wait for the process to finish
stdout, stderr = process.communicate()
print(stdout)
print(stderr)
print(f"STDOUT: {stdout}")
print(f"STDERR: {stderr}")
if process.returncode != 0:
return {"status": "Error: " + stderr}
txhash = stdout.split(" hash ")[1].split("\n")[0]
return {"status": f"Error: {stderr}", "txid": None}
txhash:str = stdout.split(" hash ")[1]
txhash = txhash.split("\n")[0].rstrip('.')
return {"status": "Success", "txid": txhash}
def list(params, authentication):

View File

@ -1,6 +1,6 @@
const { NodeClient, WalletClient } = require('hsd/lib/client');
const Network = require('hsd/lib/protocol/network.js');
const passwordPrompt = require('password-prompt');
const readline = require("readline");
class Context {
constructor(
@ -64,14 +64,4 @@ exports.Context = Context;
exports.staticPassphraseGetter = function (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',
)
.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
.command('create-external-lock <name>')
@ -155,7 +156,7 @@ function getContext(opts) {
opts.network,
opts.walletId,
opts.apiKey,
opts.passphrase ? promptPassphraseGetter() : staticPassphraseGetter(null),
opts.passphrase = staticPassphraseGetter(opts.password),
opts.httphost,
);
}
@ -261,11 +262,6 @@ async function viewExternalLock(name) {
async function transferLock(name) {
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.');
const lockTransfer = await transferNameLock(context, name);
await db.putLockTransfer(lockTransfer);