Skip to content

Commit

Permalink
feat: operator accept cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 26, 2024
1 parent 8ee1945 commit 45e5963
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
32 changes: 32 additions & 0 deletions packages/fast-usdc/src/cli/bridge-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { boardSlottingMarshaller } from '@agoric/client-utils';

/**
* @import {BridgeAction} from '@agoric/smart-wallet/src/smartWallet.js';
*/

const marshaller = boardSlottingMarshaller();

/**
* @param {BridgeAction} bridgeAction
* @param {Pick<import('stream').Writable,'write'>} stdout
*/
const outputAction = (bridgeAction, stdout) => {
const capData = marshaller.toCapData(harden(bridgeAction));
stdout.write(JSON.stringify(capData));
stdout.write('\n');
};

export const sendHint =
'Now use `agoric wallet send ...` to sign and broadcast the offer.\n';

/**
* @param {BridgeAction} bridgeAction
* @param {{
* stdout: Pick<import('stream').Writable,'write'>,
* stderr: Pick<import('stream').Writable,'write'>,
* }} io
*/
export const outputActionAndHint = (bridgeAction, { stdout, stderr }) => {
outputAction(bridgeAction, stdout);
stderr.write(sendHint);
};
50 changes: 47 additions & 3 deletions packages/fast-usdc/src/cli/operator-commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
/* eslint-env node */
/**
* @import {Command} from 'commander';
* @import {OfferSpec} from '@agoric/smart-wallet/src/offers.js';
* @import {ExecuteOfferAction} from '@agoric/smart-wallet/src/smartWallet.js';
*/

import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils';
import { INVITATION_MAKERS_DESC } from '../exos/transaction-feed.js';
import { outputActionAndHint } from './bridge-action.js';

/**
* @param {Command} program
*/
Expand All @@ -13,9 +20,46 @@ export const addOperatorCommands = program => {
operator
.command('accept')
.description('Accept invitation to be an operator')
.action(async options => {
const { requestId } = options;
console.error('TODO: Implement accept logic for request:', requestId);
.addHelpText(
'after',
'\nPipe the STDOUT to a file such as accept.json, then use the Agoric CLI to broadcast it:\n agoric wallet send --offer accept.json --from gov1 --keyring-backend="test"',
)
.option(
'--offerId <string>',
'Offer id',
String,
`operatorAccept-${Date.now()}`,
)
.action(async opts => {
const networkConfig = await fetchEnvNetworkConfig({
env: process.env,
fetch,
});
const vsk = await makeVstorageKit({ fetch }, networkConfig);
const instance = vsk.agoricNames.instance.fastUsdc;
assert(instance, 'fastUsdc instance not in agoricNames');

/** @type {OfferSpec} */
const offer = {
id: opts.offerId,
invitationSpec: {
source: 'purse',
instance,
description: INVITATION_MAKERS_DESC,
},
proposal: {},
};

/** @type {ExecuteOfferAction} */
const bridgeAction = {
method: 'executeOffer',
offer,
};

outputActionAndHint(bridgeAction, {
stderr: process.stderr,
stdout: process.stdout,
});
});

operator
Expand Down

0 comments on commit 45e5963

Please sign in to comment.