Skip to content

Commit

Permalink
feat(examples): logging progress
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 17, 2024
1 parent 146884b commit dd61e16
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
11 changes: 10 additions & 1 deletion packages/orchestration/src/examples/send-anywhere.contract.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { makeSharedStateRecord } from '@agoric/async-flow';

import { AmountShape } from '@agoric/ertp';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { M } from '@endo/patterns';
import { E } from '@endo/far';
import { withOrchestration } from '../utils/start-helper.js';
import * as flows from './send-anywhere.flows.js';
import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js';

/**
* @import {Vow} from '@agoric/vow';
* @import {Zone} from '@agoric/zone';
* @import {OrchestrationPowers, OrchestrationTools} from '../utils/start-helper.js';
*/
Expand All @@ -33,7 +36,7 @@ const contract = async (
zcf,
privateArgs,
zone,
{ chainHub, orchestrateAll, zoeTools },
{ chainHub, orchestrateAll, vowTools, zoeTools },
) => {
const contractState = makeSharedStateRecord(
/** @type {{ account: OrchestrationAccount<any> | undefined }} */ {
Expand All @@ -43,10 +46,16 @@ const contract = async (

const creatorFacet = prepareChainHubAdmin(zone, chainHub);

// UNTIL https://github.com/Agoric/agoric-sdk/issues/9066
const logNode = E(privateArgs.storageNode).makeChildNode('log');
/** @type {(msg: string) => Vow<void>} */
const log = msg => vowTools.watch(E(logNode).setValue(msg));

// orchestrate uses the names on orchestrationFns to do a "prepare" of the associated behavior
const orchFns = orchestrateAll(flows, {
zcf,
contractState,
log,
localTransfer: zoeTools.localTransfer,
});

Expand Down
10 changes: 7 additions & 3 deletions packages/orchestration/src/examples/send-anywhere.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { M, mustMatch } from '@endo/patterns';

/**
* @import {GuestOf} from '@agoric/async-flow';
* @import {Vow} from '@agoric/vow';
* @import {ZoeTools} from '../utils/zoe-tools.js';
* @import {Orchestrator, LocalAccountMethods, OrchestrationAccountI, OrchestrationFlow} from '../types.js';
*/
Expand All @@ -18,12 +19,13 @@ const { entries } = Object;
* @param {object} ctx
* @param {{ localAccount?: OrchestrationAccountI & LocalAccountMethods }} ctx.contractState
* @param {GuestOf<ZoeTools['localTransfer']>} ctx.localTransfer
* @param {GuestOf<(msg: string) => Vow<void>>} ctx.log
* @param {ZCFSeat} seat
* @param {{ chainName: string; destAddr: string }} offerArgs
*/
export const sendIt = async (
orch,
{ contractState, localTransfer },
{ contractState, localTransfer, log },
seat,
offerArgs,
) => {
Expand All @@ -32,17 +34,18 @@ export const sendIt = async (
// NOTE the proposal shape ensures that the `give` is a single asset
const { give } = seat.getProposal();
const [[_kw, amt]] = entries(give);
void log(`sending {${amt.value}} from ${chainName} to ${destAddr}`);
const agoric = await orch.getChain('agoric');
const assets = await agoric.getVBankAssetInfo();
void log(`got info for denoms: ${assets.map(a => a.denom).join(', ')}`);
const { denom } = NonNullish(
assets.find(a => a.brand === amt.brand),
`${amt.brand} not registered in vbank`,
);
const chain = await orch.getChain(chainName);

if (!contractState.localAccount) {
const agoricChain = await orch.getChain('agoric');
contractState.localAccount = await agoricChain.makeAccount();
contractState.localAccount = await agoric.makeAccount();
}

const info = await chain.getChainInfo();
Expand All @@ -65,5 +68,6 @@ export const sendIt = async (
},
);
seat.exit();
void log(`transfer complete, seat exited`);
};
harden(sendIt);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Snapshot report for `test/examples/sendAnywhere.test.ts`
# Snapshot report for `test/examples/send-anywhere.test.ts`

The actual snapshot is saved in `sendAnywhere.test.ts.snap`.
The actual snapshot is saved in `send-anywhere.test.ts.snap`.

Generated by [AVA](https://avajs.dev).

Expand All @@ -27,8 +27,10 @@ Generated by [AVA](https://avajs.dev).
chainHub: {
ChainHub_kindHandle: 'Alleged: kind',
ChainHub_singleton: 'Alleged: ChainHub',
brandDenom: {},
chainInfos: {},
connectionInfos: {},
denom: {},
lookupChainInfo_kindHandle: 'Alleged: kind',
lookupChainsAndConnection_kindHandle: 'Alleged: kind',
lookupConnectionInfo_kindHandle: 'Alleged: kind',
Expand All @@ -38,26 +40,36 @@ Generated by [AVA](https://avajs.dev).
'ChainHub Admin_singleton': 'Alleged: ChainHub Admin',
'Send PF_kindHandle': 'Alleged: kind',
'Send PF_singleton': 'Alleged: Send PF',
findBrandInVBank_kindHandle: 'Alleged: kind',
orchestration: {
sendIt: {
asyncFlow_kindHandle: 'Alleged: kind',
endowments: {
0: {
contractState_kindHandle: 'Alleged: kind',
contractState_singleton: 'Alleged: contractState',
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
log_kindHandle: 'Alleged: kind',
log_singleton: 'Alleged: log',
},
},
},
},
},
orchestration: {
'Cosmos Orchestration Account Holder_kindHandle': 'Alleged: kind',
'Local Orchestration Account Kit_kindHandle': 'Alleged: kind',
LocalChainFacade_kindHandle: 'Alleged: kind',
Orchestrator_kindHandle: 'Alleged: kind',
RemoteChainFacade_kindHandle: 'Alleged: kind',
sendIt: {
asyncFlow_kindHandle: 'Alleged: kind',
endowments: {
1: {
contractState_kindHandle: 'Alleged: kind',
contractState_singleton: 'Alleged: contractState',
findBrandInVBank_kindHandle: 'Alleged: kind',
findBrandInVBank_singleton: 'Alleged: findBrandInVBank',
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
},
},
chainName: {},
ibcTools: {
IBCTransferSenderKit_kindHandle: 'Alleged: kind',
ibcResultWatcher_kindHandle: 'Alleged: kind',
ibcResultWatcher_singleton: 'Alleged: ibcResultWatcher',
},
packetTools: {
PacketToolsKit_kindHandle: 'Alleged: kind',
},
},
vows: {
Expand Down
Binary file not shown.

0 comments on commit dd61e16

Please sign in to comment.