Skip to content

Commit

Permalink
feat(smart-wallet): use durable zone for vows
Browse files Browse the repository at this point in the history
- refs: #9308
  • Loading branch information
0xpatrickdev committed Jul 1, 2024
1 parent 34565c4 commit 7373e55
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/smart-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"devDependencies": {
"@agoric/cosmic-proto": "^0.4.0",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/zone": "^0.2.2",
"@endo/bundle-source": "^3.2.3",
"@endo/captp": "^4.2.0",
"@endo/init": "^1.1.2",
Expand All @@ -36,6 +35,7 @@
"@agoric/vats": "^0.15.1",
"@agoric/vow": "^0.1.0",
"@agoric/zoe": "^0.26.2",
"@agoric/zone": "^0.2.2",
"@endo/eventual-send": "^1.2.2",
"@endo/far": "^1.1.2",
"@endo/marshal": "^1.5.0",
Expand Down
67 changes: 38 additions & 29 deletions packages/smart-wallet/src/offerWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import {
} from '@agoric/zoe/src/typeGuards.js';
import { AmountShape } from '@agoric/ertp/src/typeGuards.js';
import { deeplyFulfilledObject, objectMap } from '@agoric/internal';
import { heapVowTools } from '@agoric/vow/vat.js';

import { UNPUBLISHED_RESULT } from './offers.js';

const { allVows, asPromise } = heapVowTools;

/**
* @import {OfferSpec} from "./offers.js";
* @import {ContinuingOfferResult} from "./types.js";
* @import {OfferSpec} from './offers.js';
* @import {ContinuingOfferResult} from './types.js';
* @import {Passable} from '@endo/pass-style';
* @import {PromiseWatcher} from '@agoric/swingset-liveslots';
* @import {Baggage} from '@agoric/vat-data';
* @import {VowTools} from '@agoric/vow';
*/

/**
Expand All @@ -35,15 +34,18 @@ const { allVows, asPromise } = heapVowTools;
* }} OutcomeWatchers
*/

/**
* @param {OutcomeWatchers} watchers
* @param {UserSeat} seat
*/
const watchForOfferResult = ({ resultWatcher }, seat) => {
// NOTE: this enables upgrade of the contract, NOT upgrade of the smart-wallet. See #9308
const p = asPromise(E(seat).getOfferResult());
watchPromise(p, resultWatcher, seat);
return p;
/** @param {VowTools} vowTools */
const makeWatchForOfferResult = ({ asPromise }) => {
/**
* @param {OutcomeWatchers} watchers
* @param {UserSeat} seat
*/
const watchForOfferResult = ({ resultWatcher }, seat) => {
const p = asPromise(E(seat).getOfferResult());
watchPromise(p, resultWatcher, seat);
return p;
};
return watchForOfferResult;
};

/**
Expand All @@ -66,19 +68,24 @@ const watchForPayout = ({ paymentWatcher }, seat) => {
return p;
};

/**
* @param {OutcomeWatchers} watchers
* @param {UserSeat} seat
*/
export const watchOfferOutcomes = (watchers, seat) => {
// NOTE: this enables upgrade of the contract, NOT upgrade of the smart-wallet. See #9308
return asPromise(
allVows([
watchForOfferResult(watchers, seat),
watchForNumWants(watchers, seat),
watchForPayout(watchers, seat),
]),
);
/** @param {VowTools} vowTools */
export const makeWatchOfferOutcomes = vowTools => {
const watchForOfferResult = makeWatchForOfferResult(vowTools);
const { asPromise, allVows } = vowTools;
/**
* @param {OutcomeWatchers} watchers
* @param {UserSeat} seat
*/
const watchOfferOutcomes = (watchers, seat) => {
return asPromise(
allVows([
watchForOfferResult(watchers, seat),
watchForNumWants(watchers, seat),
watchForPayout(watchers, seat),
]),
);
};
return watchOfferOutcomes;
};

const offerWatcherGuard = harden({
Expand Down Expand Up @@ -111,9 +118,11 @@ const offerWatcherGuard = harden({
});

/**
* @param {import('@agoric/vat-data').Baggage} baggage
* @param {Baggage} baggage
* @param {VowTools} vowTools
*/
export const prepareOfferWatcher = baggage => {
export const prepareOfferWatcher = (baggage, vowTools) => {
const watchForOfferResult = makeWatchForOfferResult(vowTools);
return prepareExoClassKit(
baggage,
'OfferWatcher',
Expand Down
11 changes: 8 additions & 3 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ import {
AmountKeywordRecordShape,
PaymentPKeywordRecordShape,
} from '@agoric/zoe/src/typeGuards.js';
import { prepareVowTools } from '@agoric/vow';
import { makeDurableZone } from '@agoric/zone/durable.js';

import { makeInvitationsHelper } from './invitations.js';
import { shape } from './typeGuards.js';
import { objectMapStoragePath } from './utils.js';
import { prepareOfferWatcher, watchOfferOutcomes } from './offerWatcher.js';
import { prepareOfferWatcher, makeWatchOfferOutcomes } from './offerWatcher.js';

/** @import {OfferId, OfferStatus} from './offers.js'; */

Expand Down Expand Up @@ -286,7 +288,7 @@ export const prepareSmartWallet = (baggage, shared) => {
secretWalletFactoryKey: M.any(),
}),
);

const zone = makeDurableZone(baggage);
const makeRecorderKit = prepareRecorderKit(baggage, shared.publicMarshaller);

const walletPurses = provide(baggage, BRAND_TO_PURSES_KEY, () => {
Expand All @@ -298,7 +300,10 @@ export const prepareSmartWallet = (baggage, shared) => {
return store;
});

const makeOfferWatcher = prepareOfferWatcher(baggage);
const vowTools = prepareVowTools(zone.subZone('vow'));

const makeOfferWatcher = prepareOfferWatcher(baggage, vowTools);
const watchOfferOutcomes = makeWatchOfferOutcomes(vowTools);

const updateShape = {
value: AmountShape,
Expand Down
6 changes: 4 additions & 2 deletions packages/vow/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { prepareWatch } from './watch.js';
import { prepareWatchUtils } from './watch-utils.js';
import { makeAsVow } from './vow-utils.js';

/** @import {Zone} from '@agoric/base-zone' */
/** @import {IsRetryableReason, AsPromiseFunction} from './types.js' */
/**
* @import {Zone} from '@agoric/base-zone';
* @import {IsRetryableReason, AsPromiseFunction} from './types.js'
*/

/**
* @param {Zone} zone
Expand Down
11 changes: 5 additions & 6 deletions packages/vow/src/watch-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { PromiseWatcherI } from '@agoric/base-zone';
const { Fail, bare } = assert;

/**
* @import {MapStore} from '@agoric/store/src/types.js'
* @import { Zone } from '@agoric/base-zone'
* @import { Watch } from './watch.js'
* @import { When } from './when.js'
* @import {VowKit, AsPromiseFunction} from './types.js'
* @import {IsRetryableReason} from './types.js'
* @import {MapStore} from '@agoric/store/src/types.js';
* @import {Zone} from '@agoric/base-zone';
* @import {Watch} from './watch.js';
* @import {When} from './when.js';
* @import {VowKit, AsPromiseFunction, IsRetryableReason} from './types.js';
*/

const VowShape = M.tagged(
Expand Down

0 comments on commit 7373e55

Please sign in to comment.