Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(agoric): convey tx opts to agoric wallet and subcommands #9559

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading