-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Dean Tribble <[email protected]>
- Loading branch information
Showing
4 changed files
with
88 additions
and
69 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
Binary file modified
BIN
+3 Bytes
(100%)
packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.snap
Binary file not shown.