Skip to content

Commit

Permalink
feat: getConnectionInfo by obj or string
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 12, 2024
1 parent 521dfd0 commit 13e02f0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/orchestration/src/exos/local-chain-account-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export const prepareLocalChainAccountKit = (

const agoricChainInfo = await chainHub.getChainInfo('agoric');
const { transferChannel } = await chainHub.getConnectionInfo(
agoricChainInfo.chainId,
destination.chainId,
agoricChainInfo,
destination,
);

await null;
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ export const makeOrchestrationFacade = ({

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

return makeRemoteChainFacade(remoteChainInfo, connectionInfo, {
Expand Down
5 changes: 1 addition & 4 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ export const startStakeAtom = async ({

const agoric = await chainHub.getChainInfo('agoric');
const cosmoshub = await chainHub.getChainInfo('cosmoshub');
const connectionInfo = await chainHub.getConnectionInfo(
agoric.chainId,
cosmoshub.chainId,
);
const connectionInfo = await chainHub.getConnectionInfo(agoric, cosmoshub);

/** @type {StartUpgradableOpts<StakeAtomSF>} */
const startOpts = {
Expand Down
8 changes: 5 additions & 3 deletions packages/orchestration/src/utils/chainHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ export const makeChainHub = (agoricNames, zone = makeHeapZone()) => {
},

/**
* @param {string} chainId1
* @param {string} chainId2
* @param {string | { chainId: string }} chain1
* @param {string | { chainId: string }} chain2
* @returns {Promise<IBCConnectionInfo>}
*/
async getConnectionInfo(chainId1, chainId2) {
async getConnectionInfo(chain1, chain2) {
const chainId1 = typeof chain1 === 'string' ? chain1 : chain1.chainId;
const chainId2 = typeof chain2 === 'string' ? chain2 : chain2.chainId;
const key = connectionKey(chainId1, chainId2);
if (connectionInfos.has(key)) {
return connectionInfos.get(key);
Expand Down
44 changes: 44 additions & 0 deletions packages/orchestration/test/utils/chainHub.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable @jessie.js/safe-await-separator -- XXX irrelevant for tests */
import test from '@endo/ses-ava/prepare-endo.js';

import { makeNameHubKit } from '@agoric/vats';
import { makeChainHub } from '../../src/utils/chainHub.js';

const connection = {
id: 'connection-1',
client_id: '07-tendermint-3',
counterparty: {
client_id: '07-tendermint-2',
connection_id: 'connection-1',
prefix: {
key_prefix: '',
},
},
state: 3 /* IBCConnectionState.STATE_OPEN */,
transferChannel: {
portId: 'transfer',
channelId: 'channel-1',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 1 /* Order.ORDER_UNORDERED */,
state: 3 /* IBCConnectionState.STATE_OPEN */,
version: 'ics20-1',
},
};

test('getConnectionInfo', async t => {
const { nameHub } = makeNameHubKit();
const chainHub = makeChainHub(nameHub);

const aChain = { chainId: 'a-1' };
const bChain = { chainId: 'b-2' };

chainHub.registerConnection(aChain.chainId, bChain.chainId, connection);

// Look up by string or info object
t.deepEqual(
await chainHub.getConnectionInfo(aChain.chainId, bChain.chainId),
connection,
);
t.deepEqual(await chainHub.getConnectionInfo(aChain, bChain), connection);
});

0 comments on commit 13e02f0

Please sign in to comment.