-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
misc Orch factoring improvements #9676
Changes from all commits
800009c
ff94d3c
9e61ddd
e9988c9
5c77188
ecb67b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { M, mustMatch } from '@endo/patterns'; | ||
|
||
/** | ||
* @import {Orchestrator, OrchestrationAccount} from '../types.js'; | ||
*/ | ||
|
||
const { entries } = Object; | ||
|
||
// in guest file (the orchestration functions) | ||
// the second argument is all the endowments provided | ||
|
||
export const orchestrationFns = harden({ | ||
/** | ||
* @param {Orchestrator} orch | ||
* @param {object} ctx | ||
* @param {{ account: OrchestrationAccount<any> }} ctx.contractState | ||
* @param {any} ctx.localTransfer | ||
* @param {any} ctx.findBrandInVBank | ||
* @param {ZCFSeat} seat | ||
* @param {{ chainName: string; destAddr: string }} offerArgs | ||
*/ | ||
async sendIt( | ||
orch, | ||
{ contractState, localTransfer, findBrandInVBank }, | ||
seat, | ||
Comment on lines
+13
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything we can do to reduce boilerplate around this? ( Maybe curry orch and ctx so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because sendIt is a flow (guest fn) and not a regular function I think that's asking for trouble |
||
offerArgs, | ||
) { | ||
mustMatch( | ||
offerArgs, | ||
harden({ chainName: M.scalar(), destAddr: M.string() }), | ||
); | ||
const { chainName, destAddr } = offerArgs; | ||
// NOTE the proposal shape ensures that the `give` is a single asset | ||
const { give } = seat.getProposal(); | ||
const [[_kw, amt]] = entries(give); | ||
const { denom } = await findBrandInVBank(amt.brand); | ||
const chain = await orch.getChain(chainName); | ||
|
||
if (!contractState.account) { | ||
const agoricChain = await orch.getChain('agoric'); | ||
contractState.account = await agoricChain.makeAccount(); | ||
} | ||
|
||
const info = await chain.getChainInfo(); | ||
const { chainId } = info; | ||
assert(typeof chainId === 'string', 'bad chainId'); | ||
|
||
await localTransfer(seat, contractState.account, give); | ||
|
||
await contractState.account.transfer( | ||
{ denom, value: amt.value }, | ||
{ | ||
value: destAddr, | ||
encoding: 'bech32', | ||
chainId, | ||
}, | ||
); | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not crazy about moving this to a separate file. Did we feel
sendAnywhere.contract.js
got too big, or was there a different motivation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation is that it's a different runtime environment than the contract. Keeping the flows in a separate file will help prevent trying to access host values directly. Also it will let us improve linting. E.g. the "no async" lint rules need only apply to these files, not the contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but putting them at the top of the file also achieves the same
Think you meant to say no
E
, but I see your point. Noting this can be achieved intra-file with something likeProperty[key.name=/OfferHandler$/]
orProperty[key.name=/Handler$/]
if we enforce the convention (sendIt -> sendItHandler)