diff --git a/packages/orchestration/src/chain-info.js b/packages/orchestration/src/chain-info.js index f387faca34e..3cbc182bb5c 100644 --- a/packages/orchestration/src/chain-info.js +++ b/packages/orchestration/src/chain-info.js @@ -1,4 +1,4 @@ -import { registerChain } from './utils/chainHub.js'; +import { registerChain } from './exos/chain-hub.js'; // Refresh with scripts/refresh-chain-info.ts import fetchedChainInfo from './fetched-chain-info.js'; diff --git a/packages/orchestration/src/examples/stakeBld.contract.js b/packages/orchestration/src/examples/stakeBld.contract.js index 009094e802e..1652ae606fd 100644 --- a/packages/orchestration/src/examples/stakeBld.contract.js +++ b/packages/orchestration/src/examples/stakeBld.contract.js @@ -11,7 +11,7 @@ import { E } from '@endo/far'; import { deeplyFulfilled } from '@endo/marshal'; import { M } from '@endo/patterns'; import { prepareLocalOrchestrationAccountKit } from '../exos/local-orchestration-account.js'; -import { makeChainHub } from '../utils/chainHub.js'; +import { makeChainHub } from '../exos/chain-hub.js'; /** * @import {NameHub} from '@agoric/vats'; diff --git a/packages/orchestration/src/utils/chainHub.js b/packages/orchestration/src/exos/chain-hub.js similarity index 86% rename from packages/orchestration/src/utils/chainHub.js rename to packages/orchestration/src/exos/chain-hub.js index 6e7a0387239..321242ff812 100644 --- a/packages/orchestration/src/utils/chainHub.js +++ b/packages/orchestration/src/exos/chain-hub.js @@ -54,7 +54,38 @@ export const connectionKey = (chainId1, chainId2) => { return [chainId1, chainId2].sort().join(CHAIN_ID_SEPARATOR); }; +const ChainIdArgShape = M.or( + M.string(), + M.splitRecord( + { + chainId: M.string(), + }, + undefined, + M.any(), + ), +); + +const ChainHubI = M.interface('ChainHub', { + registerChain: M.call(M.string(), CosmosChainInfoShape).returns(), + getChainInfo: M.callWhen(M.string()).returns(CosmosChainInfoShape), + registerConnection: M.callWhen( + M.string(), + M.string(), + IBCConnectionInfoShape, + ).returns(), + getConnectionInfo: M.callWhen(ChainIdArgShape, ChainIdArgShape).returns( + IBCConnectionInfoShape, + ), +}); + /** + * Make a new ChainHub in the zone (or in the heap if no zone is provided). + * + * The resulting object is an Exo singleton. It has no precious state. It's only + * state is a cache of queries to agoricNames and whatever info was provided in + * registration calls. When you need a newer version you can simply make a hub + * hub and repeat the registrations. + * * @param {Remote} agoricNames * @param {Zone} [zone] */ @@ -70,7 +101,7 @@ export const makeChainHub = (agoricNames, zone = makeHeapZone()) => { valueShape: IBCConnectionInfoShape, }); - const chainHub = harden({ + const chainHub = zone.exo('ChainHub', ChainHubI, { /** * Register a new chain. The name will override a name in well known chain * names. diff --git a/packages/orchestration/src/exos/local-orchestration-account.js b/packages/orchestration/src/exos/local-orchestration-account.js index 15e28d830a1..02a59a86b24 100644 --- a/packages/orchestration/src/exos/local-orchestration-account.js +++ b/packages/orchestration/src/exos/local-orchestration-account.js @@ -25,7 +25,7 @@ import { dateInSeconds, makeTimestampHelper } from '../utils/time.js'; * @import {TimerService, TimerBrand, TimestampRecord} from '@agoric/time'; * @import {PromiseVow, VowTools} from '@agoric/vow'; * @import {TypedJson} from '@agoric/cosmic-proto'; - * @import {ChainHub} from '../utils/chainHub.js'; + * @import {ChainHub} from './chain-hub.js'; */ const trace = makeTracer('LOA'); diff --git a/packages/orchestration/src/exos/orchestrator.js b/packages/orchestration/src/exos/orchestrator.js index 1ffab8c2613..02087425537 100644 --- a/packages/orchestration/src/exos/orchestrator.js +++ b/packages/orchestration/src/exos/orchestrator.js @@ -13,7 +13,7 @@ import { /** * @import {Zone} from '@agoric/base-zone'; - * @import {ChainHub} from '../utils/chainHub.js'; + * @import {ChainHub} from './chain-hub.js'; * @import {AsyncFlowTools} from '@agoric/async-flow'; * @import {Vow} from '@agoric/vow'; * @import {TimerService} from '@agoric/time'; diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 6de79caa23f..b4f6c97d81c 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -28,7 +28,7 @@ import { prepareOrchestrator } from './exos/orchestrator.js'; * storageNode: Remote; * orchestrationService: Remote; * localchain: Remote; - * chainHub: import('./utils/chainHub.js').ChainHub; + * chainHub: import('./exos/chain-hub.js').ChainHub; * makeLocalOrchestrationAccountKit: MakeLocalOrchestrationAccountKit; * makeRecorderKit: MakeRecorderKit; * makeCosmosOrchestrationAccount: any; diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index 46846cd17f6..b45ff54cff1 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -3,7 +3,7 @@ import { E, Far } from '@endo/far'; import { makeMarshal } from '@endo/marshal'; import { Fail } from '@agoric/assert'; import { registerChainNamespace } from '../chain-info.js'; -import { CHAIN_KEY, CONNECTIONS_KEY } from '../utils/chainHub.js'; +import { CHAIN_KEY, CONNECTIONS_KEY } from '../exos/chain-hub.js'; const trace = makeTracer('CoreEvalOrchestration', true); diff --git a/packages/orchestration/src/proposals/start-stakeAtom.js b/packages/orchestration/src/proposals/start-stakeAtom.js index 470236c54f8..05a6069dd9f 100644 --- a/packages/orchestration/src/proposals/start-stakeAtom.js +++ b/packages/orchestration/src/proposals/start-stakeAtom.js @@ -1,7 +1,7 @@ import { makeTracer } from '@agoric/internal'; import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js'; import { E } from '@endo/far'; -import { getChainsAndConnection, makeChainHub } from '../utils/chainHub.js'; +import { getChainsAndConnection, makeChainHub } from '../exos/chain-hub.js'; /** * @import {IBCConnectionID} from '@agoric/vats'; diff --git a/packages/orchestration/src/proposals/start-stakeOsmo.js b/packages/orchestration/src/proposals/start-stakeOsmo.js index d61b73b5ae6..c7911c5e74c 100644 --- a/packages/orchestration/src/proposals/start-stakeOsmo.js +++ b/packages/orchestration/src/proposals/start-stakeOsmo.js @@ -1,7 +1,7 @@ import { makeTracer } from '@agoric/internal'; import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js'; import { E } from '@endo/far'; -import { getChainsAndConnection, makeChainHub } from '../utils/chainHub.js'; +import { getChainsAndConnection, makeChainHub } from '../exos/chain-hub.js'; /** * @import {IBCConnectionID} from '@agoric/vats'; diff --git a/packages/orchestration/src/utils/start-helper.js b/packages/orchestration/src/utils/start-helper.js index 8ec73eb8bea..c064bca441b 100644 --- a/packages/orchestration/src/utils/start-helper.js +++ b/packages/orchestration/src/utils/start-helper.js @@ -4,7 +4,7 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/record import { makeDurableZone } from '@agoric/zone/durable.js'; import { prepareLocalOrchestrationAccountKit } from '../exos/local-orchestration-account.js'; import { makeOrchestrationFacade } from '../facade.js'; -import { makeChainHub } from './chainHub.js'; +import { makeChainHub } from '../exos/chain-hub.js'; import { prepareRemoteChainFacade } from '../exos/remote-chain-facade.js'; import { prepareCosmosOrchestrationAccount } from '../exos/cosmos-orchestration-account.js'; import { prepareLocalChainFacade } from '../exos/local-chain-facade.js'; diff --git a/packages/orchestration/test/examples/sendAnywhere.test.ts b/packages/orchestration/test/examples/sendAnywhere.test.ts index 6c5b44a23f7..d3d44833155 100644 --- a/packages/orchestration/test/examples/sendAnywhere.test.ts +++ b/packages/orchestration/test/examples/sendAnywhere.test.ts @@ -9,7 +9,7 @@ import { makeIssuerKit } from '@agoric/ertp'; import { CosmosChainInfo, IBCConnectionInfo } from '../../src/cosmos-api.js'; import { commonSetup } from '../supports.js'; import { SingleAmountRecord } from '../../src/examples/sendAnywhere.contract.js'; -import { registerChain } from '../../src/utils/chainHub.js'; +import { registerChain } from '../../src/exos/chain-hub.js'; const dirname = path.dirname(new URL(import.meta.url).pathname); diff --git a/packages/orchestration/test/utils/chainHub.test.ts b/packages/orchestration/test/exos/chain-hub.test.ts similarity index 95% rename from packages/orchestration/test/utils/chainHub.test.ts rename to packages/orchestration/test/exos/chain-hub.test.ts index 4f02ad81afa..516d07a44c6 100644 --- a/packages/orchestration/test/utils/chainHub.test.ts +++ b/packages/orchestration/test/exos/chain-hub.test.ts @@ -2,7 +2,7 @@ import test from '@endo/ses-ava/prepare-endo.js'; import { makeNameHubKit } from '@agoric/vats'; -import { makeChainHub } from '../../src/utils/chainHub.js'; +import { makeChainHub } from '../../src/exos/chain-hub.js'; const connection = { id: 'connection-1', diff --git a/packages/orchestration/test/exos/local-orchestration-account-kit.test.ts b/packages/orchestration/test/exos/local-orchestration-account-kit.test.ts index dfff8afc620..21ba90fcd68 100644 --- a/packages/orchestration/test/exos/local-orchestration-account-kit.test.ts +++ b/packages/orchestration/test/exos/local-orchestration-account-kit.test.ts @@ -7,7 +7,7 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/record import { Far } from '@endo/far'; import { prepareLocalOrchestrationAccountKit } from '../../src/exos/local-orchestration-account.js'; import { ChainAddress } from '../../src/orchestration-api.js'; -import { makeChainHub } from '../../src/utils/chainHub.js'; +import { makeChainHub } from '../../src/exos/chain-hub.js'; import { NANOSECONDS_PER_SECOND } from '../../src/utils/time.js'; import { commonSetup } from '../supports.js';