Skip to content

Commit

Permalink
feat(orchestrator): return unwrapped vows
Browse files Browse the repository at this point in the history
- returning unwrapped vows to ensure tests are passing and functionality is preserved
  • Loading branch information
0xpatrickdev committed Jun 19, 2024
1 parent 8e63778 commit ae9ecf5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
87 changes: 63 additions & 24 deletions packages/orchestration/src/exos/orchestrator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file ChainAccount exo */
import { AmountShape } from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { V } from '@agoric/vow/vat.js';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import {
ChainInfoShape,
Expand All @@ -10,6 +10,7 @@ import {
BrandInfoShape,
DenomAmountShape,
} from '../typeGuards.js';
import { getChainsAndConnection } from '../utils/chainHub.js';

/**
* @import {Zone} from '@agoric/base-zone';
Expand Down Expand Up @@ -61,40 +62,78 @@ export const prepareOrchestrator = (
localchain,
makeLocalChainFacade,
makeRemoteChainFacade,
vowTools: _vowTools,
vowTools: { watch, when },
},
) =>
zone.exoClass(
zone.exoClassKit(
'Orchestrator',
OrchestratorI,
{
orchestrator: OrchestratorI,
makeLocalChainFacadeWatcher: M.interface('makeLocalChainFacadeWatcher', {
onFulfilled: M.call(M.record())
.optional(M.arrayOf(M.undefined()))
.returns(M.any()), // FIXME narrow
}),
makeRemoteChainFacadeWatcher: M.interface(
'makeRemoteChainFacadeWatcher',
{
onFulfilled: M.call(M.arrayOf(M.record()))
.optional(M.arrayOf(M.undefined()))
.returns(M.any()), // FIXME narrow
},
),
},
() => {
trace('making an Orchestrator');
return {};
},
{
/** @type {Orchestrator['getChain']} */
getChain: async name => {
const agoricChainInfo = await chainHub.getChainInfo('agoric');

if (name === 'agoric') {
// @ts-expect-error XXX chainInfo generic
/** Waits for `chainInfo` and returns a LocalChainFacade */
makeLocalChainFacadeWatcher: {
/** @param {ChainInfo} agoricChainInfo */
onFulfilled(agoricChainInfo) {
return makeLocalChainFacade(agoricChainInfo);
}

const remoteChainInfo = await chainHub.getChainInfo(name);
const connectionInfo = await chainHub.getConnectionInfo(
agoricChainInfo.chainId,
remoteChainInfo.chainId,
);

// @ts-expect-error XXX chainInfo generic
return makeRemoteChainFacade(remoteChainInfo, connectionInfo);
},
},
/**
* Waits for `chainInfo` for `agoric` and a remote chain and returns a
* RemoteChainFacade
*/
makeRemoteChainFacadeWatcher: {
/**
* Waits for `chainInfo` for `agoric` and a remote chain and returns a
* RemoteChainFacade
*
* @param {[ChainInfo, ChainInfo, IBCConnectionInfo]} chainsAndConnection
*/
onFulfilled([_agoricChainInfo, remoteChainInfo, connectionInfo]) {
return makeRemoteChainFacade(remoteChainInfo, connectionInfo);
},
},
makeLocalAccount() {
return V(localchain).makeAccount();
orchestrator: {
/** @type {Orchestrator['getChain']} */
getChain(name) {
if (name === 'agoric') {
return when(
watch(
chainHub.getChainInfo('agoric'),
this.facets.makeLocalChainFacadeWatcher,
),
);
}
return when(
watch(
getChainsAndConnection(chainHub, 'agoric', name),
this.facets.makeRemoteChainFacadeWatcher,
),
);
},
makeLocalAccount() {
return when(watch(E(localchain).makeAccount()));
},
getBrandInfo: () => Fail`not yet implemented`,
asAmount: () => Fail`not yet implemented`,
},
getBrandInfo: () => Fail`not yet implemented`,
asAmount: () => Fail`not yet implemented`,
},
);
harden(prepareOrchestrator);
2 changes: 1 addition & 1 deletion packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const makeOrchestrationFacade = ({
* @returns {(...args: Args) => Promise<unknown>}
*/
orchestrate(durableName, ctx, fn) {
const orc = makeOrchestrator();
const orc = makeOrchestrator().orchestrator;

return async (...args) => fn(orc, ctx, ...args);
},
Expand Down
6 changes: 5 additions & 1 deletion packages/orchestration/src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { TimeMath } from '@agoric/time';
export const SECONDS_PER_MINUTE = 60n;
export const NANOSECONDS_PER_SECOND = 1_000_000_000n;

/** @param {Remote<TimerService>} timer */
/**
* XXX should this be durable? resumable?
*
* @param {Remote<TimerService>} timer
*/
export function makeTimestampHelper(timer) {
/** @type {TimerBrand | undefined} */
let brandCache;
Expand Down

0 comments on commit ae9ecf5

Please sign in to comment.