Skip to content

Commit

Permalink
feat(cli): wallet provision
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 15, 2022
1 parent 77cf5da commit cda3377
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
39 changes: 38 additions & 1 deletion packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,50 @@ import { makeRpcUtils, networkConfig } from '../lib/rpc.js';
import { getWalletState } from '../lib/wallet.js';

import { makeLeaderOptions } from '../lib/casting.js';
import { execSwingsetTransaction, normalizeAddress } from '../lib/chain.js';
import {
execSwingsetTransaction,
fetchSwingsetParams,
normalizeAddress,
} from '../lib/chain.js';

const SLEEP_SECONDS = 3;

export const makeWalletCommand = async () => {
const wallet = new Command('wallet').description('wallet commands');

wallet
.command('provision')
.description('provision a Smart Wallet')
.requiredOption(
'--account [address]',
'address literal or name',
normalizeAddress,
)
.option('--spend', 'confirm you want to spend')
.option('--nickname [string]', 'nickname to use', 'my-wallet')
.action(function () {
const { account, nickname, spend } = this.opts();
if (spend) {
const tx = `provision-one ${nickname} ${account} SMART_WALLET`;
execSwingsetTransaction(tx, networkConfig, account);
} else {
const params = fetchSwingsetParams(networkConfig);
assert(
params.power_flag_fees.length === 1,
'multiple power_flag_fees not supported',
);
const { fee: fees } = params.power_flag_fees[0];
const nf = new Intl.NumberFormat('en-US');
const costs = fees
.map(f => `${nf.format(Number(f.amount))} ${f.denom}`)
.join(' + ');
process.stdout.write(`Provisioning a wallet costs ${costs}\n`);
process.stdout.write(
`To really provision, repeat this command with --spend\n`,
);
}
});

wallet
.command('send')
.description('send a prepared offer')
Expand Down
24 changes: 23 additions & 1 deletion packages/agoric-cli/src/lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ export const normalizeAddress = literalOrName => {
};
harden(normalizeAddress);

export const execSwingsetTransaction = (swingsetArgs, net, from, dryRun) => {
/**
* SECURITY: closes over process and child_process
*
* @param {string} swingsetArgs
* @param {import('./rpc').MinimalNetworkConfig} net
* @param {string} from
* @param {boolean} [dryRun]
*/
export const execSwingsetTransaction = (
swingsetArgs,
net,
from,
dryRun = false,
) => {
const { chainName, rpcAddrs } = net;

const cmd = `agd --node=${rpcAddrs[0]} --chain-id=${chainName} --from=${from} tx swingset ${swingsetArgs}`;
Expand All @@ -30,3 +43,12 @@ export const execSwingsetTransaction = (swingsetArgs, net, from, dryRun) => {
}
};
harden(execSwingsetTransaction);

// xxx rpc should be able to query this by HTTP without shelling out
export const fetchSwingsetParams = net => {
const { chainName, rpcAddrs } = net;
const cmd = `agd --node=${rpcAddrs[0]} --chain-id=${chainName} query swingset params --output --json`;
const buffer = execSync(cmd);
return JSON.parse(buffer.toString());
};
harden(fetchSwingsetParams);
6 changes: 2 additions & 4 deletions packages/agoric-cli/test/agops-governance-smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ make scenario2-setup scenario2-run-chain-psm
cd packages/cosmic-swingset
# Fund the pool
make fund-provision-pool
# Copy the agoric address from your keplr wallet or 'agd keys list', starts with 'agoric1'
KEY=<yoursBech32>
# Provision your wallet
make ACCT_ADDR=$KEY AGORIC_POWERS=SMART_WALLET fund-acct provision-acct
agoric wallet provision --account <key-name>
# verify
agoric wallet list
agoric wallet show --from \$KEY
agoric wallet show --from <key-name>
"
exit 1
fi
Expand Down
12 changes: 5 additions & 7 deletions packages/agoric-cli/test/agops-perf-smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ cd packages/cosmic-swingset
make scenario2-setup scenario2-run-chain-psm
# (new tab)
# Fund the pool (addr is a magic string)
make SOLO_COINS=1234000000ibc/usdc1234 ACCT_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346 fund-acct
# Provision your wallet
cd packages/cosmic-swingset
# Copy the agoric address from your keplr wallet or 'agd keys list', starts with 'agoric1'
WALLET_ADDR=<yours>
make ACCT_ADDR=$WALLET_ADDR AGORIC_POWERS=SMART_WALLET fund-acct provision-acct
# Fund the pool
make fund-provision-pool
# Provision your wallet
agoric wallet provision --account <key-name>
# verify
agoric wallet list
agoric wallet show --from $WALLET_ADDR
agoric wallet show --from <key-name>
"
exit 1
fi
Expand Down

0 comments on commit cda3377

Please sign in to comment.