From 5d4bc6b6439a23b99931df3285f2ecd4e75feebf Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Sat, 22 Jun 2024 00:29:55 -0600 Subject: [PATCH] fix(agoric): convey tx opts to `agoric wallet` and subcommands (#9559) closes: #9554 ## Description Propagate tx options to `agoric wallet` and the relevant subcommands. --- packages/agoric-cli/src/commands/wallet.js | 48 +++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/agoric-cli/src/commands/wallet.js b/packages/agoric-cli/src/commands/wallet.js index 10bed0a0ee3..8fc3405fbf6 100644 --- a/packages/agoric-cli/src/commands/wallet.js +++ b/packages/agoric-cli/src/commands/wallet.js @@ -29,19 +29,26 @@ const SLEEP_SECONDS = 3; * @returns {Promise} */ export const makeWalletCommand = async command => { - const wallet = command('wallet') - .description('wallet commands') - .option('--home ', 'agd application home directory') - .option( - '--keyring-backend ', - 'keyring\'s backend (os|file|test) (default "os")', - ); + /** + * @param {import('commander').Command} baseCmd + */ + const withSharedTxOptions = baseCmd => + baseCmd + .option('--home ', 'agd application home directory') + .option( + '--keyring-backend ', + 'keyring\'s backend (os|file|test) (default "os")', + ); + /** @typedef {{home?: string, keyringBackend: 'os' | 'file' | 'test'}} SharedTxOptions */ + + const wallet = withSharedTxOptions(command('wallet')).description( + 'wallet commands', + ); const normalizeAddress = literalOrName => normalizeAddressWithOptions(literalOrName, wallet.opts()); - wallet - .command('provision') + withSharedTxOptions(wallet.command('provision')) .description('provision a Smart Wallet') .requiredOption( '--account [address]', @@ -51,8 +58,14 @@ export const makeWalletCommand = async command => { .option('--spend', 'confirm you want to spend') .option('--nickname ', 'nickname to use', 'my-wallet') .action(function (opts) { - const { account, nickname, spend } = opts; - const { home, keyringBackend: backend } = wallet.opts(); + /** @typedef {{account: string, spend?: boolean, nickname: 'my-wallet' | string }} Opts */ + const { + account, + nickname, + spend, + home, + keyringBackend: backend, + } = /** @type {SharedTxOptions & Opts} */ ({ ...wallet.opts(), ...opts }); const tx = ['provision-one', nickname, account, 'SMART_WALLET']; if (spend) { execSwingsetTransaction(tx, { @@ -110,8 +123,7 @@ export const makeWalletCommand = async command => { console.log(offerObj.offer.id); }); - wallet - .command('send') + withSharedTxOptions(wallet.command('send')) .description('send a prepared offer') .requiredOption( '--from [address]', @@ -121,8 +133,14 @@ export const makeWalletCommand = async command => { .requiredOption('--offer [filename]', 'path to file with prepared offer') .option('--dry-run', 'spit out the command instead of running it') .action(function (opts) { - const { dryRun, from, offer } = opts; - const { home, keyringBackend: backend } = wallet.opts(); + /** @typedef {{ from: string, offer: string, dryRun: boolean }} Opts */ + const { + dryRun, + from, + offer, + home, + keyringBackend: backend, + } = /** @type {SharedTxOptions & Opts} */ ({ ...wallet.opts(), ...opts }); const offerBody = fs.readFileSync(offer).toString(); execSwingsetTransaction(['wallet-action', '--allow-spend', offerBody], {