Skip to content

Commit

Permalink
WIP(sendAnywhere): use registerChain
Browse files Browse the repository at this point in the history
Error: Unknown chain "may24"

because transfer() depends on a global mapping
  • Loading branch information
dckc committed Jun 5, 2024
1 parent 1c34cf6 commit 610a0fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/orchestration/src/examples/sendAnywhere.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { Fail } = assert;
* @import {ERef} from '@endo/far'
* @import {OrchestrationService} from '../service.js';
* @import {NameHub, Board} from '@agoric/vats';
* @import { Remote } from '@agoric/vow';
* @import {Remote} from '@agoric/vow';
*/

/**
Expand Down Expand Up @@ -52,8 +52,6 @@ const SingleAmountRecord = M.recordOf(M.string(), AmountShape, {
*/
export const start = async (zcf, privateArgs, baggage) => {
const zone = makeDurableZone(baggage);
/** @type {MapStore<number, CosmosChainInfo>} */
const chains = zone.mapStore('chains');

const { makeRecorderKit } = prepareRecorderKitMakers(
baggage,
Expand All @@ -68,7 +66,7 @@ export const start = async (zcf, privateArgs, baggage) => {
privateArgs.agoricChainInfo,
);

const { orchestrate } = makeOrchestrationFacade({
const { orchestrate, registerChain } = makeOrchestrationFacade({
zcf,
zone,
...privateArgs,
Expand Down Expand Up @@ -111,7 +109,8 @@ export const start = async (zcf, privateArgs, baggage) => {
entries(give).length > 0 || Fail`empty give`;
const [[kw, amt]] = entries(give);
const { [kw]: pmtP } = await withdrawFromSeat(zcf, seat, give);
const { chainId } = chains.get(chainKey);
const info = await orch.getChain(chainKey).then(c => c.getChainInfo());
const { chainId } = info;
await E(contractAccount).deposit(await pmtP, amt);
const { denom } = await findBrandInVBank(amt.brand);
const { value } = amt;
Expand Down Expand Up @@ -145,6 +144,7 @@ export const start = async (zcf, privateArgs, baggage) => {
},
);

let nonce = 0n;
const creatorFacet = zone.exo(
'Send CF',
M.interface('Send CF', {
Expand All @@ -153,8 +153,8 @@ export const start = async (zcf, privateArgs, baggage) => {
{
/** @param {CosmosChainInfo} chainInfo */
addChain(chainInfo) {
const chainKey = chains.getSize();
chains.init(chainKey, chainInfo);
const chainKey = `chain${(nonce += 1n)}`;
registerChain(chainKey, chainInfo);
return chainKey;
},
},
Expand Down
10 changes: 5 additions & 5 deletions packages/orchestration/test/examples/sendAnywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ test('send using arbitrary chain info', async t => {
},
);

const chainInfo = {
const chainInfo = harden({
...chainRegistryInfo.celestia,
chainId: 'may24',
ibcConnectionInfo: agoricPeerInfo[0],
connections: zone.mapStore('may24 connections'),
connections: {},
stakingTokens: [{ denom: 'umay' }],
...chainInfoDefaults,
} as CosmosChainInfo;
}) as CosmosChainInfo;
t.log('add chain using creatorFacet', chainInfo);
await E(creatorFacet).addChain(chainInfo);
const chainKey = await E(creatorFacet).addChain(chainInfo);

t.log('do offer');
const publicFacet = await E(zoe).getPublicFacet(instance);
Expand All @@ -166,7 +166,7 @@ test('send using arbitrary chain info', async t => {

const anAmt = ist.make(20n);
const Send = ist.mint.mintPayment(anAmt);
const dest = { destAddr: 'agoric1valopsfufu', chainKey: 0 };
const dest = { destAddr: 'agoric1valopsfufu', chainKey };
const userSeat = await E(zoe).offer(
inv,
{ give: { Send: anAmt } },
Expand Down

0 comments on commit 610a0fd

Please sign in to comment.