From 20df4b2eaaca59c004c117b5d3eebe0f9018e329 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Fri, 21 Jun 2024 12:01:37 -0600 Subject: [PATCH 1/2] fix(agoric): convey tx opts to `agoric wallet` and subcommands --- packages/agoric-cli/src/commands/wallet.js | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/agoric-cli/src/commands/wallet.js b/packages/agoric-cli/src/commands/wallet.js index 10bed0a0ee3..b9031fc27d2 100644 --- a/packages/agoric-cli/src/commands/wallet.js +++ b/packages/agoric-cli/src/commands/wallet.js @@ -29,19 +29,25 @@ 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")', + ); + + 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]', @@ -110,8 +116,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]', From b6dc686d8f9c95777db79f526ec2fefce1e8dd41 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Fri, 21 Jun 2024 22:39:51 -0600 Subject: [PATCH 2/2] fixup! fix(agoric): convey tx opts to `agoric wallet` and subcommands --- packages/agoric-cli/src/commands/wallet.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/agoric-cli/src/commands/wallet.js b/packages/agoric-cli/src/commands/wallet.js index b9031fc27d2..8fc3405fbf6 100644 --- a/packages/agoric-cli/src/commands/wallet.js +++ b/packages/agoric-cli/src/commands/wallet.js @@ -39,6 +39,7 @@ export const makeWalletCommand = async command => { '--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', @@ -57,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, { @@ -126,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], {