-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: exofy Orchestrator, RemoteChainFacade
- Loading branch information
Showing
6 changed files
with
255 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** @file ChainAccount exo */ | ||
import { AmountShape } from '@agoric/ertp'; | ||
import { makeTracer } from '@agoric/internal'; | ||
import { V } from '@agoric/vow/vat.js'; | ||
import { M } from '@endo/patterns'; | ||
// eslint-disable-next-line import/no-cycle -- FIXME | ||
import { makeLocalChainFacade } from '../facade.js'; | ||
|
||
/** | ||
* @import {Zone} from '@agoric/base-zone'; | ||
* @import {ChainHub} from '../utils/chainHub.js'; | ||
* @import {Connection, Port} from '@agoric/network'; | ||
* @import {AnyJson} from '@agoric/cosmic-proto'; | ||
* @import {TxBody} from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js'; | ||
* @import {LocalIbcAddress, RemoteIbcAddress} from '@agoric/vats/tools/ibc-utils.js'; | ||
* @import {AsyncFlowTools} from '@agoric/async-flow'; | ||
* @import {Vow} from '@agoric/vow'; | ||
* @import {TimerService} from '@agoric/time'; | ||
* @import {IBCConnectionID} from '@agoric/vats'; | ||
* @import {LocalChain} from '@agoric/vats/src/localchain.js'; | ||
* @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'. | ||
* @import {Remote} from '@agoric/internal'; | ||
* @import {OrchestrationService} from '../service.js'; | ||
* @import {MakeLocalChainAccountKit} from './local-chain-account-kit.js'; | ||
* @import {Chain, ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount, Orchestrator} from '../types.js'; | ||
*/ | ||
|
||
const { Fail } = assert; | ||
const trace = makeTracer('Orchestrator'); | ||
|
||
// TODO more validation | ||
export const ChainInfoShape = M.any(); | ||
export const LocalChainAccountShape = M.remotable('LocalChainAccount'); | ||
export const DenomShape = M.string(); | ||
export const BrandInfoShape = M.any(); | ||
|
||
export const DenomAmountShape = { denom: DenomShape, value: M.bigint() }; | ||
|
||
/** @see {Orchestrator} */ | ||
export const OrchestratorI = M.interface('Orchestrator', { | ||
getChain: M.callWhen(M.string()).returns(ChainInfoShape), | ||
makeLocalAccount: M.callWhen().returns(LocalChainAccountShape), | ||
getBrandInfo: M.call(DenomShape).returns(BrandInfoShape), | ||
asAmount: M.call(DenomAmountShape).returns(AmountShape), | ||
}); | ||
|
||
/** | ||
* @param {Zone} zone | ||
* @param {{ | ||
* asyncFlowTools: AsyncFlowTools; | ||
* chainHub: ChainHub; | ||
* localchain: Remote<LocalChain>; | ||
* makeLocalChainAccountKit: MakeLocalChainAccountKit; | ||
* makeRecorderKit: MakeRecorderKit; | ||
* makeRemoteChainFacade: any; | ||
* orchestrationService: Remote<OrchestrationService>; | ||
* storageNode: Remote<StorageNode>; | ||
* timerService: Remote<TimerService>; | ||
* zcf: ZCF; | ||
* }} powers | ||
*/ | ||
export const prepareOrchestrator = ( | ||
zone, | ||
{ chainHub, localchain, makeLocalChainAccountKit, makeRemoteChainFacade }, | ||
) => | ||
zone.exoClass( | ||
'Orchestrator', | ||
OrchestratorI, | ||
() => { | ||
trace('making an Orchestrator'); | ||
return {}; | ||
}, | ||
{ | ||
/** @type {Orchestrator['getChain']} */ | ||
getChain: async name => { | ||
const agoricChainInfo = await chainHub.getChainInfo('agoric'); | ||
|
||
if (name === 'agoric') { | ||
return makeLocalChainFacade( | ||
localchain, | ||
makeLocalChainAccountKit, | ||
agoricChainInfo, | ||
); | ||
} | ||
|
||
const remoteChainInfo = await chainHub.getChainInfo(name); | ||
const connectionInfo = await chainHub.getConnectionInfo( | ||
agoricChainInfo.chainId, | ||
remoteChainInfo.chainId, | ||
); | ||
|
||
return makeRemoteChainFacade(remoteChainInfo, connectionInfo); | ||
}, | ||
makeLocalAccount() { | ||
return V(localchain).makeAccount(); | ||
}, | ||
getBrandInfo: () => Fail`not yet implemented`, | ||
asAmount: () => Fail`not yet implemented`, | ||
}, | ||
); | ||
harden(prepareOrchestrator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** @file ChainAccount exo */ | ||
import { makeTracer } from '@agoric/internal'; | ||
import { V } from '@agoric/vow/vat.js'; | ||
import { M } from '@endo/patterns'; | ||
|
||
import { ChainInfoShape } from './orchestrator.js'; | ||
|
||
/** | ||
* @import {Zone} from '@agoric/base-zone'; | ||
* @import {TimerService} from '@agoric/time'; | ||
* @import {Remote} from '@agoric/internal'; | ||
* @import {OrchestrationService} from '../service.js'; | ||
* @import {prepareCosmosOrchestrationAccount} from './cosmosOrchestrationAccount.js'; | ||
* @import {ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount} from '../types.js'; | ||
*/ | ||
|
||
const { Fail } = assert; | ||
const trace = makeTracer('RemoteChainFacade'); | ||
|
||
/** @type {any} */ | ||
const anyVal = null; | ||
|
||
/** @see {Chain} */ | ||
export const RemoteChainFacadeI = M.interface('RemoteChainFacade', { | ||
getChainInfo: M.callWhen().returns(ChainInfoShape), | ||
makeAccount: M.callWhen().returns(M.remotable('OrchestrationAccount')), | ||
}); | ||
|
||
/** | ||
* @param {Zone} zone | ||
* @param {{ | ||
* makeCosmosOrchestrationAccount: ReturnType< | ||
* typeof prepareCosmosOrchestrationAccount | ||
* >; | ||
* orchestration: Remote<OrchestrationService>; | ||
* storageNode: Remote<StorageNode>; | ||
* timer: Remote<TimerService>; | ||
* }} powers | ||
*/ | ||
export const prepareRemoteChainFacade = ( | ||
zone, | ||
{ makeCosmosOrchestrationAccount, orchestration, storageNode, timer }, | ||
) => | ||
zone.exoClass( | ||
'RemoteChainFacade', | ||
RemoteChainFacadeI, | ||
/** | ||
* @param {CosmosChainInfo} remoteChainInfo | ||
* @param {IBCConnectionInfo} connectionInfo | ||
*/ | ||
(remoteChainInfo, connectionInfo) => { | ||
trace('making an RemoteChainFacade'); | ||
return { remoteChainInfo, connectionInfo }; | ||
}, | ||
{ | ||
async getChainInfo() { | ||
return this.state.remoteChainInfo; | ||
}, | ||
|
||
// FIXME parameterize on the remoteChainInfo to make() | ||
// That used to work but got lost in the migration to Exo | ||
/** @returns {Promise<OrchestrationAccount<ChainInfo>>} */ | ||
async makeAccount() { | ||
const { remoteChainInfo, connectionInfo } = this.state; | ||
|
||
const icaAccount = await V(orchestration).makeAccount( | ||
remoteChainInfo.chainId, | ||
connectionInfo.id, | ||
connectionInfo.counterparty.connection_id, | ||
); | ||
|
||
const address = await V(icaAccount).getAddress(); | ||
|
||
const [{ denom: bondDenom }] = remoteChainInfo.stakingTokens || [ | ||
{ | ||
denom: null, | ||
}, | ||
]; | ||
if (!bondDenom) { | ||
throw Fail`missing bondDenom`; | ||
} | ||
return makeCosmosOrchestrationAccount(address, bondDenom, { | ||
account: icaAccount, | ||
storageNode, | ||
icqConnection: anyVal, | ||
timer, | ||
}); | ||
}, | ||
}, | ||
); | ||
harden(prepareRemoteChainFacade); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.