Skip to content

Commit

Permalink
feat: zoeTools uses asVow
Browse files Browse the repository at this point in the history
- `retriable` does not seem to be a good fit for these functions as they are not idempotent
  • Loading branch information
0xpatrickdev committed Sep 19, 2024
1 parent 8159c66 commit 2cad888
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
4 changes: 1 addition & 3 deletions packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const provideOrchestration = (
orchestration: zone.subZone('orchestration'),
/** system names for vows */
vows: zone.subZone('vows'),
/** system names for zoe */
zoe: zone.subZone('zoe'),
/** contract-provided names, and subzones */
contract: zone.subZone('contract'),
};
Expand All @@ -76,7 +74,7 @@ export const provideOrchestration = (

const chainHub = makeChainHub(agoricNames, vowTools);

const zoeTools = makeZoeTools(zones.zoe, { zcf, vowTools });
const zoeTools = makeZoeTools(zcf, vowTools);

const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller);
const makeLocalOrchestrationAccountKit = prepareLocalOrchestrationAccountKit(
Expand Down
53 changes: 29 additions & 24 deletions packages/orchestration/src/utils/zoe-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { E } from '@endo/far';
const { assign, keys, values } = Object;

/**
* @import {HostOf, GuestInterface} from '@agoric/async-flow';
* @import {InvitationMakers} from '@agoric/smart-wallet/src/types.js';
* @import {ResolvedPublicTopic} from '@agoric/zoe/src/contractSupport/topics.js';
* @import {VowTools} from '@agoric/vow';
* @import {Zone} from '@agoric/zone';
* @import {LocalAccountMethods} from '../types.js';
*/

Expand Down Expand Up @@ -38,25 +38,26 @@ const { assign, keys, values } = Object;
*/

/**
* @param {Zone} zone
* @param {{ zcf: ZCF; vowTools: VowTools }} io
* @param {ZCF} zcf
* @param {VowTools} vowTools
*/
export const makeZoeTools = (
zone,
{ zcf, vowTools: { retriable, when, allVows, allSettled } },
) => {
export const makeZoeTools = (zcf, vowTools) => {
const { when, allVows, allSettled, asVow } = vowTools;
/**
* Transfer the `amounts` from `srcSeat` to `localAccount`. If any of the
* deposits fail, everything will be rolled back to the `srcSeat`. Supports
* multiple items in the `amounts` {@link AmountKeywordRecord}.
*
* @type {HostOf<LocalTransfer>}
*/
const localTransfer = retriable(
zone,
'localTransfer',
const localTransfer = (srcSeat, localAccount, amounts) =>
/**
* @type {LocalTransfer}
* There are no interchain actions - everything happens on the local chain -
* so we can expect this to settle promptly. As such, it's safe to use
* `asVow` instead of `watch`. In the future, when async-flow supports E and
* promises, we might consider making this an async-flow function.
*/
async (srcSeat, localAccount, amounts) => {
asVow(async () => {
!srcSeat.hasExited() || Fail`The seat cannot have exited.`;
const { zcfSeat: tempSeat, userSeat: userSeatP } = zcf.makeEmptySeatKit();
const userSeat = await userSeatP;
Expand Down Expand Up @@ -114,21 +115,24 @@ export const makeZoeTools = (
throw makeError(`One or more deposits failed ${q(errors)}`);
}
// TODO #9541 remove userSeat from baggage
},
);
});

/**
* Transfer the `amounts` from a `localAccount` to the `recipientSeat`. If any
* of the withdrawals fail, everything will be rolled back to the
* `srcLocalAccount`. Supports multiple items in the `amounts`
* {@link PaymentKeywordRecord}.
* {@link PaymentKeywordRecord}
*
* @type {HostOf<WithdrawToSeat>}
*/
const withdrawToSeat = retriable(
zone,
'withdrawToSeat',
/** @type {WithdrawToSeat} */
async (localAccount, destSeat, amounts) => {
await null;
const withdrawToSeat = (localAccount, destSeat, amounts) =>
/*
* There are no interchain actions - everything happens on the local chain -
* so we can expect this to settle promptly. As such, it's safe to use
* `asVow` instead of `watch`. In the future, when async-flow supports E and
* promises, we might consider making this an async-flow function.
*/
asVow(async () => {
!destSeat.hasExited() || Fail`The seat cannot have exited.`;

const settledWithdrawals = await when(
Expand Down Expand Up @@ -167,12 +171,13 @@ export const makeZoeTools = (
paymentKwr,
);
console.debug(depositResponse);
},
);
});

return harden({
localTransfer,
withdrawToSeat,
});
};
/** @typedef {ReturnType<typeof makeZoeTools>} ZoeTools */

/** @typedef {ReturnType<typeof makeZoeTools>} ZoeToolsHost */
/** @typedef {GuestInterface<ZoeToolsHost>} ZoeTools */
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ Generated by [AVA](https://avajs.dev).
VowInternalsKit_kindHandle: 'Alleged: kind',
WatchUtils_kindHandle: 'Alleged: kind',
},
zoe: {},
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,4 @@ Generated by [AVA](https://avajs.dev).
VowInternalsKit_kindHandle: 'Alleged: kind',
WatchUtils_kindHandle: 'Alleged: kind',
},
zoe: {},
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ Generated by [AVA](https://avajs.dev).
VowInternalsKit_kindHandle: 'Alleged: kind',
WatchUtils_kindHandle: 'Alleged: kind',
},
zoe: {},
}
Binary file not shown.

0 comments on commit 2cad888

Please sign in to comment.