Skip to content

Commit 7b0f4d0

Browse files
committed
refactor: separate flows module
1 parent 39e1adf commit 7b0f4d0

File tree

2 files changed

+135
-129
lines changed

2 files changed

+135
-129
lines changed

contract/src/orca.contract.js

Lines changed: 11 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
66
import { Fail } from '@endo/errors';
77
import { E } from '@endo/far';
88
import { M } from '@endo/patterns';
9+
import * as flows from './orca.flows.js';
910

1011
import '@agoric/zoe/src/zoeService/types-ambient.js';
1112

@@ -21,7 +22,6 @@ import '@agoric/zoe/src/zoeService/types-ambient.js';
2122
*/
2223

2324
const trace = makeTracer('OrchDev1');
24-
const { entries } = Object;
2525

2626
const SingleAmountRecord = M.and(
2727
M.recordOf(M.string(), AmountShape, {
@@ -30,39 +30,6 @@ const SingleAmountRecord = M.and(
3030
M.not(harden({})),
3131
);
3232

33-
/**
34-
* Create an account on a Cosmos chain and return a continuing offer with
35-
* invitations makers for Delegate, WithdrawRewards, Transfer, etc.
36-
*
37-
* @param {Orchestrator} orch
38-
* @param {undefined} _ctx
39-
* @param {ZCFSeat} seat
40-
* @param {{ chainName: string }} offerArgs
41-
*/
42-
const createAccountsFn = async (orch, _ctx, seat, { chainName }) => {
43-
const { give } = seat.getProposal();
44-
trace('version 0.1.36');
45-
trace('give');
46-
trace(give);
47-
trace('inside createAccounts');
48-
trace('orch');
49-
trace(orch);
50-
trace('seat');
51-
trace(seat);
52-
trace(chainName);
53-
seat.exit();
54-
const chain = await orch.getChain(chainName);
55-
trace('chain object');
56-
trace(chain);
57-
const info = await chain.getChainInfo();
58-
trace('chain info', info);
59-
const chainAccount = await chain.makeAccount();
60-
console.log('chainAccount');
61-
console.log(chainAccount);
62-
63-
return chainAccount.asContinuingOffer();
64-
};
65-
6633
/**
6734
* @typedef {(
6835
* srcSeat: ZCFSeat,
@@ -75,82 +42,6 @@ const createAccountsFn = async (orch, _ctx, seat, { chainName }) => {
7542
* ) => Promise<void>} Transfer
7643
*/
7744

78-
/**
79-
* Create an account on a Cosmos chain and return a continuing offer with
80-
* invitations makers for Delegate, WithdrawRewards, Transfer, etc.
81-
*
82-
* @param {Orchestrator} orch
83-
* @param {object} ctx
84-
* @param {Transfer} ctx.transfer
85-
* @param {StorageNode['setValue']} ctx.setValue
86-
* @param {ZCFSeat} seat
87-
* @param {{ chainName: string }} offerArgs
88-
*/
89-
const createAndFundFn = async (
90-
orch,
91-
{
92-
transfer,
93-
// write,
94-
// makeChildNode,
95-
setValue,
96-
},
97-
seat,
98-
{ chainName },
99-
) => {
100-
const { give } = seat.getProposal();
101-
const [[_kw, amt]] = entries(give);
102-
trace('orch', orch);
103-
trace('_kw', _kw);
104-
trace('amt', amt);
105-
trace('give:', give);
106-
// trace("write:", write);
107-
// trace("makeChildNode:", makeChildNode);
108-
trace('setValue:', setValue);
109-
110-
const [agoric, chain] = await Promise.all([
111-
orch.getChain('agoric'),
112-
orch.getChain(chainName),
113-
]);
114-
115-
const info = await chain.getChainInfo();
116-
trace('chain info', info);
117-
118-
const assets = await agoric.getVBankAssetInfo();
119-
trace('fetched assets:', assets);
120-
121-
const localAccount = await agoric.makeAccount();
122-
trace('localAccount', localAccount);
123-
124-
const remoteAccount = await chain.makeAccount();
125-
trace('remoteAccount', remoteAccount);
126-
const [localAddress, remoteAddress] = await Promise.all([
127-
localAccount.getAddress(),
128-
remoteAccount.getAddress(),
129-
]);
130-
131-
// vstorage tests
132-
trace('writing');
133-
// setValue(`status x`)
134-
// const node1 = await makeChildNode(`orca-createAndFund-${localAddress.value}-${localAddress.value}`);
135-
136-
trace('localAddress', localAddress);
137-
trace('remoteAddress', remoteAddress);
138-
trace('fund new orch account');
139-
trace('seat', seat);
140-
trace('transfer', transfer);
141-
await transfer(
142-
seat,
143-
localAccount,
144-
remoteAccount,
145-
give,
146-
amt,
147-
localAddress,
148-
remoteAddress,
149-
);
150-
seat.exit();
151-
return remoteAccount.asContinuingOffer();
152-
};
153-
15445
/**
15546
* @param {ZCF} zcf
15647
* @param {OrchestrationPowers & {
@@ -163,7 +54,7 @@ const contract = async (
16354
zcf,
16455
privateArgs,
16556
zone,
166-
{ orchestrate, vowTools, zoeTools },
57+
{ orchestrateAll, vowTools, zoeTools },
16758
) => {
16859
trace('inside start function: v1.1.95');
16960
trace('privateArgs', privateArgs);
@@ -263,24 +154,15 @@ const contract = async (
263154
const wrap = wrapper();
264155
trace('wrapper.transfer', wrapper);
265156

266-
/** @type {OfferHandler} */
267-
// @ts-expect-error ZCFSeat not Passable
268-
const makeAccount = orchestrate('makeAccount', undefined, createAccountsFn);
269-
270-
/** @type {OfferHandler} */
271-
const makeCreateAndFund = orchestrate(
272-
'makeCreateAndFund',
273-
{
274-
localTransfer: zoeTools.localTransfer,
275-
transfer: wrap.transfer,
276-
// write: E(storageNode).write),
277-
// makeChildNode: E(storageNode).makeChildNode,
278-
// setValue: E(storageNode).setValue,
279-
setValue: privateArgs.storageNode.setValue,
280-
},
281-
// @ts-expect-error ZCFSeat not Passable
282-
createAndFundFn,
283-
);
157+
// @ts-expect-error XXX ZCFSeat not Passable
158+
const { makeAccount, makeCreateAndFund } = orchestrateAll(flows, {
159+
localTransfer: zoeTools.localTransfer,
160+
transfer: wrap.transfer,
161+
// write: E(storageNode).write),
162+
// makeChildNode: E(storageNode).makeChildNode,
163+
// setValue: E(storageNode).setValue,
164+
setValue: privateArgs.storageNode.setValue,
165+
});
284166

285167
const publicFacet = zone.exo(
286168
'Orca Public Facet',

contract/src/orca.flows.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* @import {GuestOf} from '@agoric/async-flow';
3+
* @import {Amount} from '@agoric/ertp/src/types.js';
4+
* @import {Marshaller, StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
5+
* @import {ChainAddress, Orchestrator} from '@agoric/orchestration';
6+
* @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js';
7+
* @import {ZoeTools} from '@agoric/orchestration/src/utils/zoe-tools.js';
8+
* @import {Transfer} from './orca.contract.js';
9+
*/
10+
11+
import { makeTracer } from './debug.js';
12+
13+
const trace = makeTracer('OrchFlows');
14+
15+
/**
16+
* Create an account on a Cosmos chain and return a continuing offer with
17+
* invitations makers for Delegate, WithdrawRewards, Transfer, etc.
18+
*
19+
* @param {Orchestrator} orch
20+
* @param {unknown} _ctx
21+
* @param {ZCFSeat} seat
22+
* @param {{ chainName: string }} offerArgs
23+
*/
24+
export const makeAccount = async (orch, _ctx, seat, { chainName }) => {
25+
const { give } = seat.getProposal();
26+
trace('version 0.1.36');
27+
trace('give');
28+
trace(give);
29+
trace('inside createAccounts');
30+
trace('orch');
31+
trace(orch);
32+
trace('seat');
33+
trace(seat);
34+
trace(chainName);
35+
seat.exit();
36+
const chain = await orch.getChain(chainName);
37+
trace('chain object');
38+
trace(chain);
39+
const info = await chain.getChainInfo();
40+
trace('chain info', info);
41+
const chainAccount = await chain.makeAccount();
42+
console.log('chainAccount');
43+
console.log(chainAccount);
44+
45+
return chainAccount.asContinuingOffer();
46+
};
47+
harden(makeAccount);
48+
49+
/**
50+
* Create an account on a Cosmos chain and return a continuing offer with
51+
* invitations makers for Delegate, WithdrawRewards, Transfer, etc.
52+
*
53+
* @param {Orchestrator} orch
54+
* @param {object} ctx
55+
* @param {Transfer} ctx.transfer
56+
* @param {StorageNode['setValue']} ctx.setValue
57+
* @param {ZCFSeat} seat
58+
* @param {{ chainName: string }} offerArgs
59+
*/
60+
export const makeCreateAndFund = async (
61+
orch,
62+
{
63+
transfer,
64+
// write,
65+
// makeChildNode,
66+
setValue,
67+
},
68+
seat,
69+
{ chainName },
70+
) => {
71+
const { give } = seat.getProposal();
72+
const [[_kw, amt]] = Object.entries(give);
73+
trace('orch', orch);
74+
trace('_kw', _kw);
75+
trace('amt', amt);
76+
trace('give:', give);
77+
// trace("write:", write);
78+
// trace("makeChildNode:", makeChildNode);
79+
trace('setValue:', setValue);
80+
81+
const [agoric, chain] = await Promise.all([
82+
orch.getChain('agoric'),
83+
orch.getChain(chainName),
84+
]);
85+
86+
const info = await chain.getChainInfo();
87+
trace('chain info', info);
88+
89+
const assets = await agoric.getVBankAssetInfo();
90+
trace('fetched assets:', assets);
91+
92+
const localAccount = await agoric.makeAccount();
93+
trace('localAccount', localAccount);
94+
95+
const remoteAccount = await chain.makeAccount();
96+
trace('remoteAccount', remoteAccount);
97+
const [localAddress, remoteAddress] = await Promise.all([
98+
localAccount.getAddress(),
99+
remoteAccount.getAddress(),
100+
]);
101+
102+
// vstorage tests
103+
trace('writing');
104+
// setValue(`status x`)
105+
// const node1 = await makeChildNode(`orca-createAndFund-${localAddress.value}-${localAddress.value}`);
106+
107+
trace('localAddress', localAddress);
108+
trace('remoteAddress', remoteAddress);
109+
trace('fund new orch account');
110+
trace('seat', seat);
111+
trace('transfer', transfer);
112+
await transfer(
113+
seat,
114+
localAccount,
115+
remoteAccount,
116+
give,
117+
amt,
118+
localAddress,
119+
remoteAddress,
120+
);
121+
seat.exit();
122+
return remoteAccount.asContinuingOffer();
123+
};
124+
harden(makeCreateAndFund);

0 commit comments

Comments
 (0)