Skip to content

Commit

Permalink
fix(agoric): convey tx opts to agoric wallet and subcommands (#9559)
Browse files Browse the repository at this point in the history
closes: #9554

## Description


Propagate tx options to `agoric wallet` and the relevant subcommands.
  • Loading branch information
michaelfig authored and mhofman committed Jun 22, 2024
1 parent 478af2f commit 5d4bc6b
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ const SLEEP_SECONDS = 3;
* @returns {Promise<import('commander').Command>}
*/
export const makeWalletCommand = async command => {
const wallet = command('wallet')
.description('wallet commands')
.option('--home <dir>', 'agd application home directory')
.option(
'--keyring-backend <os|file|test>',
'keyring\'s backend (os|file|test) (default "os")',
);
/**
* @param {import('commander').Command} baseCmd
*/
const withSharedTxOptions = baseCmd =>
baseCmd
.option('--home <dir>', 'agd application home directory')
.option(
'--keyring-backend <os|file|test>',
'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]',
Expand All @@ -51,8 +58,14 @@ export const makeWalletCommand = async command => {
.option('--spend', 'confirm you want to spend')
.option('--nickname <string>', '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, {
Expand Down Expand Up @@ -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]',
Expand All @@ -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], {
Expand Down

0 comments on commit 5d4bc6b

Please sign in to comment.