forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc Orch factoring improvements (Agoric#9676)
refs: Agoric#9449 ## Description Adapted from Agoric#9657 . The `retriable` helper and `withOrchestration` refactor landed already. This has the rest: - orchestrateAll helper - separate module for flows - ZoeTools endowment (for `withdrawFromSeat` à la Agoric#9449 ) - makeOrchestrator abstraction ### Security Considerations `orchestrateAll` grants the same context to each orchFn. If they have to be different, the author can make multiple calls grouping what is the same. Improves POLA of some Orchestration services by passing a `makeOrchestrator`. ### Scaling Considerations none ### Documentation Considerations none yet ### Testing Considerations CI ### Upgrade Considerations not yet deployed
- Loading branch information
Showing
12 changed files
with
289 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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, | ||
}, | ||
); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.