Skip to content

Commit

Permalink
feat(agops): gov keyring option
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 29, 2023
1 parent 46a12a2 commit cc61e93
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@agoric/casting": "^0.4.2",
"@agoric/cosmic-proto": "^0.3.0",
"@agoric/ertp": "^0.16.2",
"@agoric/governance": "^0.10.3",
"@agoric/inter-protocol": "^0.16.1",
"@agoric/internal": "^0.3.2",
"@agoric/network": "^0.1.0",
Expand All @@ -63,6 +64,7 @@
"@endo/init": "^0.5.59",
"@endo/marshal": "^0.8.8",
"@endo/nat": "^4.1.30",
"@endo/patterns": "^0.2.6",
"@endo/promise-kit": "^0.2.59",
"@iarna/toml": "^2.2.3",
"anylogger": "^0.21.0",
Expand Down
58 changes: 44 additions & 14 deletions packages/agoric-cli/src/commands/gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const collectValues = (val, memo) => {
return memo;
};

const defaultKeyring = process.env.AGORIC_KEYRING_BACKEND || 'test';

/**
* @param {import('anylogger').Logger} _logger
* @param {{
Expand Down Expand Up @@ -47,10 +49,18 @@ export const makeGovCommand = (_logger, io = {}) => {
// backwards compatibility with less general "ec" command. To make this work
// the new CLI options default to the values used for Economic Committee
cmd.alias('ec');
cmd.option(
'--keyring-backend <os|file|test>',
`keyring's backend (os|file|test) (default "${defaultKeyring}")`,
defaultKeyring,
);

/** @param {string} literalOrName */
const normalizeAddress = literalOrName =>
normalizeAddressWithOptions(literalOrName, { keyringBackend: 'test' });
normalizeAddressWithOptions(literalOrName, {
// FIXME does not observe keyring-backend option, which isn't available during arg parsing
keyringBackend: defaultKeyring,
});

/** @type {(info: unknown, indent?: unknown) => boolean } */
const show = (info, indent) =>
Expand All @@ -71,15 +81,21 @@ export const makeGovCommand = (_logger, io = {}) => {
* @param {{
* toOffer: (agoricNames: *, current: import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord | undefined) => OfferSpec,
* sendFrom?: string | undefined,
* keyringBackend: string,
* instanceName?: string,
* }} detail
* @param {Awaited<ReturnType<makeRpcUtils>>} [optUtils]
*/
const processOffer = async ({ toOffer, sendFrom }, optUtils) => {
const processOffer = async function (
{ toOffer, sendFrom, keyringBackend },
optUtils,
) {
const networkConfig = await getNetworkConfig(env);
const utils = await (optUtils || makeRpcUtils({ fetch }));
const { agoricNames, readLatestHead } = utils;

assert(keyringBackend, 'missing keyring-backend option');

let current;
if (sendFrom) {
current = await getCurrent(sendFrom, { readLatestHead });
Expand All @@ -97,7 +113,7 @@ export const makeGovCommand = (_logger, io = {}) => {
const result = await sendAction(
{ method: 'executeOffer', offer },
{
keyring: { backend: 'test' }, // XXX
keyring: { backend: keyringBackend },
from: sendFrom,
verbose: false,
...networkConfig,
Expand Down Expand Up @@ -140,21 +156,22 @@ export const makeGovCommand = (_logger, io = {}) => {
.requiredOption(
'--name <string>',
'Committee instance name',
String,
'economicCommittee',
)
.option('--voter <number>', 'Voter number', Number, 0)
.option(
'--offerId <string>',
'Offer id',
String,
`ecCommittee-${Date.now()}`,
`gov-committee-${Date.now()}`,
)
.option(
'--send-from <name-or-address>',
'Send from address',
normalizeAddress,
)
.action(async function (opts) {
.action(async function (opts, options) {
const { name: instanceName } = opts;

/** @type {Parameters<typeof processOffer>[0]['toOffer']} */
Expand All @@ -181,7 +198,8 @@ export const makeGovCommand = (_logger, io = {}) => {
await processOffer({
toOffer,
instanceName,
...opts,
sendFrom: opts.sendFrom,
keyringBackend: options.optsWithGlobals().keyringBackend,
});
});

Expand All @@ -199,7 +217,7 @@ export const makeGovCommand = (_logger, io = {}) => {
'Send from address',
normalizeAddress,
)
.action(async function (opts) {
.action(async function (opts, options) {
const { name: instanceName } = opts;

/** @type {Parameters<typeof processOffer>[0]['toOffer']} */
Expand All @@ -226,7 +244,8 @@ export const makeGovCommand = (_logger, io = {}) => {
await processOffer({
toOffer,
instanceName,
...opts,
sendFrom: opts.sendFrom,
keyringBackend: options.optsWithGlobals().keyringBackend,
});
});

Expand Down Expand Up @@ -270,7 +289,9 @@ export const makeGovCommand = (_logger, io = {}) => {
const current = await getCurrent(opts.from, { readLatestHead });

const found = findContinuingIds(current, agoricNames);
found.forEach(it => show({ ...it, address: opts.from }));
for (const it of found) {
show({ ...it, address: opts.from });
}
});

cmd
Expand Down Expand Up @@ -299,7 +320,7 @@ export const makeGovCommand = (_logger, io = {}) => {
'Send from address',
normalizeAddress,
)
.action(async function (opts) {
.action(async function (opts, options) {
const utils = await makeRpcUtils({ fetch });
const { readLatestHead } = utils;

Expand All @@ -308,8 +329,9 @@ export const makeGovCommand = (_logger, io = {}) => {
).catch(err => {
throw new CommanderError(1, 'VSTORAGE_FAILURE', err.message);
});

// XXX runtime shape-check
const questionDesc = /** @type {any} */ (info);
const questionDesc = /** @type {QuestionDetails} */ (info);

// TODO support multiple position arguments
const chosenPositions = [questionDesc.positions[opts.forPosition]];
Expand Down Expand Up @@ -343,7 +365,14 @@ export const makeGovCommand = (_logger, io = {}) => {
};
};

await processOffer({ toOffer, sendFrom: opts.sendFrom }, utils);
await processOffer(
{
toOffer,
sendFrom: opts.sendFrom,
keyringBackend: options.optsWithGlobals().keyringBackend,
},
utils,
);
});

cmd
Expand Down Expand Up @@ -376,7 +405,7 @@ export const makeGovCommand = (_logger, io = {}) => {
Number,
1,
)
.action(async function (opts) {
.action(async function (opts, options) {
const { instance: instanceName } = opts;

/** @type {Parameters<typeof processOffer>[0]['toOffer']} */
Expand Down Expand Up @@ -415,7 +444,8 @@ export const makeGovCommand = (_logger, io = {}) => {
await processOffer({
toOffer,
instanceName,
...opts,
sendFrom: opts.sendFrom,
keyringBackend: options.optsWithGlobals().keyringBackend,
});
});

Expand Down

0 comments on commit cc61e93

Please sign in to comment.