Skip to content

Commit

Permalink
refactor: provideAsyncFlowTools to facade
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 18, 2024
1 parent 562579d commit f096604
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/orchestration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
"dependencies": {
"@agoric/async-flow": "^0.1.0",
"@agoric/assert": "^0.6.0",
"@agoric/cosmic-proto": "^0.4.0",
"@agoric/ertp": "^0.16.2",
Expand Down
22 changes: 15 additions & 7 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/** @file Orchestration service */

import { V as E } from '@agoric/vow/vat.js';
import { Fail } from '@agoric/assert';
import { prepareCosmosOrchestrationAccount } from './exos/cosmosOrchestrationAccount.js';

/**
* @import {AsyncFlowTools} from '@agoric/async-flow';
* @import {Zone} from '@agoric/zone';
* @import {TimerService} from '@agoric/time';
* @import {IBCConnectionID} from '@agoric/vats';
Expand Down Expand Up @@ -156,6 +158,7 @@ const makeRemoteChainFacade = (
* typeof import('./exos/local-chain-account-kit.js').prepareLocalChainAccountKit
* >;
* makeRecorderKit: MakeRecorderKit;
* asyncFlowTools: AsyncFlowTools;
* }} powers
*/
export const makeOrchestrationFacade = ({
Expand All @@ -168,14 +171,19 @@ export const makeOrchestrationFacade = ({
chainHub,
makeLocalChainAccountKit,
makeRecorderKit,
asyncFlowTools,
}) => {
console.log('makeOrchestrationFacade got', {
zone,
timerService,
zcf,
storageNode,
orchestrationService,
});
(zone &&
timerService &&
zcf &&
storageNode &&
orchestrationService &&
// @ts-expect-error type says defined but double check
makeLocalChainAccountKit &&
// @ts-expect-error type says defined but double check
makeRecorderKit &&
asyncFlowTools) ||
Fail`params missing`;

return {
/**
Expand Down
6 changes: 6 additions & 0 deletions packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ export const provideOrchestration = (
chainHub,
);

const vowTools = prepareVowTools(zone.subZone('vows'));
const asyncFlowTools = prepareAsyncFlowTools(zone.subZone('asyncFlow'), {
vowTools,
});

const facade = makeOrchestrationFacade({
zcf,
zone,
chainHub,
makeLocalChainAccountKit,
makeRecorderKit,
asyncFlowTools,
...remotePowers,
});
return { ...facade, chainHub, zone };
Expand Down
8 changes: 7 additions & 1 deletion packages/orchestration/test/facade.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { prepareAsyncFlowTools } from '@agoric/async-flow';
import { setupZCFTest } from '@agoric/zoe/test/unitTests/zcf/setupZcfTest.js';
import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
import { prepareVowTools } from '@agoric/vow';
import type { CosmosChainInfo, IBCConnectionInfo } from '../src/cosmos-api.js';
import { makeOrchestrationFacade } from '../src/facade.js';
import type { Chain } from '../src/orchestration-api.js';
Expand Down Expand Up @@ -46,13 +48,16 @@ test('chain info', async t => {
const { bootstrap, facadeServices } = await commonSetup(t);

const zone = bootstrap.rootZone;

const { zcf } = await setupZCFTest();
const chainHub = makeChainHub(facadeServices.agoricNames);
const { makeRecorderKit } = prepareRecorderKitMakers(
zone.mapStore('recorder'),
bootstrap.marshaller,
);
const vowTools = prepareVowTools(zone.subZone('vows'));
const asyncFlowTools = prepareAsyncFlowTools(zone.subZone('asyncFlow'), {
vowTools,
});

const { orchestrate } = makeOrchestrationFacade({
...facadeServices,
Expand All @@ -62,6 +67,7 @@ test('chain info', async t => {
chainHub,
makeLocalChainAccountKit,
makeRecorderKit,
asyncFlowTools,
});

chainHub.registerChain('mock', mockChainInfo);
Expand Down
3 changes: 2 additions & 1 deletion packages/orchestration/test/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export const commonSetup = async t => {
localchain,
marshaller,
orchestration,
rootZone,
// TODO remove; bootstrap doesn't have a zone
rootZone: rootZone.subZone('contract'),
storage,
},
brands: {
Expand Down

0 comments on commit f096604

Please sign in to comment.