Skip to content

Commit

Permalink
refactor(orchestration): simplify example guest code (#9586)
Browse files Browse the repository at this point in the history
closes: #XXXX
refs: https://github.com/Agoric/agoric-sdk/pull/9566/files#r1653602477

## Description

At https://github.com/Agoric/agoric-sdk/pull/9566/files#r1653602477 @dckc commented on a cleanup that I thought I did and marked as done, but was not done. 

Before #9566, the code that would be guest code had several workarounds marked `// XXX when() until membrane` that correctly indicated that they should be cleaned up as of #9566, which introduces exactly that membrane.

In addition, guest code has no need for `heapVowE` since it doesn't see vows. It should just use the normal `E`. To keep this distinct, I stopped renaming `hostVowE` where host code needs it in the same file.

### Security Considerations
none
### Scaling Considerations
none
### Documentation Considerations
examples are now more like what we want to teach
### Testing Considerations
I believe this PR is a pure refactor that should not have any observable effects. Thus, it should not affect any tests. We'll see soon.
### Upgrade Considerations
none
  • Loading branch information
erights authored Jun 28, 2024
1 parent 5b2d338 commit f0f1a3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
17 changes: 8 additions & 9 deletions packages/orchestration/src/examples/sendAnywhere.contract.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { M, mustMatch } from '@endo/patterns';
import { heapVowE as E } from '@agoric/vow/vat.js';
import { E } from '@endo/far';
import { heapVowE } from '@agoric/vow/vat.js';
import { makeStateRecord } from '@agoric/async-flow';
import { AmountShape } from '@agoric/ertp';
import { CosmosChainInfoShape } from '../typeGuards.js';
Expand Down Expand Up @@ -53,20 +54,16 @@ const sendItFn = async (
const { chainName, destAddr } = offerArgs;
const { give } = seat.getProposal();
const [[kw, amt]] = entries(give);
// XXX when() until membrane
const { denom } = await E.when(agoricNamesTools.findBrandInVBank(amt.brand));
const { denom } = await agoricNamesTools.findBrandInVBank(amt.brand);
const chain = await orch.getChain(chainName);

// FIXME ok to use a heap var crossing the membrane scope this way?
if (!contractState.account) {
const agoricChain = await orch.getChain('agoric');
// XXX when() until membrane
contractState.account = await E.when(agoricChain.makeAccount());
contractState.account = await agoricChain.makeAccount();
console.log('contractState.account', contractState.account);
}

// XXX when() until membrane
const info = await E.when(chain.getChainInfo());
const info = await chain.getChainInfo();
console.log('info', info);
const { chainId } = info;
assert(typeof chainId === 'string', 'bad chainId');
Expand Down Expand Up @@ -156,7 +153,9 @@ export const start = async (zcf, privateArgs, baggage) => {
const chainKey = `${chainInfo.chainId}-${(nonce += 1n)}`;
// when() because chainHub methods return vows. If this were inside
// orchestrate() the membrane would wrap/unwrap automatically.
const agoricChainInfo = await E.when(chainHub.getChainInfo('agoric'));
const agoricChainInfo = await heapVowE.when(
chainHub.getChainInfo('agoric'),
);
chainHub.registerChain(chainKey, chainInfo);
chainHub.registerConnection(
agoricChainInfo.chainId,
Expand Down
7 changes: 2 additions & 5 deletions packages/orchestration/src/examples/swapExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js'
import { Far } from '@endo/far';
import { deeplyFulfilled } from '@endo/marshal';
import { M, objectMap } from '@endo/patterns';
import { heapVowTools } from '@agoric/vow/vat.js';
import { orcUtils } from '../utils/orc.js';
import { provideOrchestration } from '../utils/start-helper.js';

Expand Down Expand Up @@ -34,10 +33,8 @@ const stackAndSwapFn = async (orch, { zcf }, seat, offerArgs) => {
const agoric = await orch.getChain('agoric');

const [omniAccount, localAccount] = await Promise.all([
// XXX when() until membrane
heapVowTools.when(omni.makeAccount()),
// XXX when() until membrane
heapVowTools.when(agoric.makeAccount()),
omni.makeAccount(),
agoric.makeAccount(),
]);

const omniAddress = omniAccount.getAddress();
Expand Down

0 comments on commit f0f1a3e

Please sign in to comment.