Skip to content

Commit

Permalink
feat(smart-wallet): accept Vow for offerResult
Browse files Browse the repository at this point in the history
* Make smart wallet use `when` to accept a Vow for the result of an offer

NOTE: this enables upgrade of the contract, NOT upgrade of the smart-wallet

refs: #9308

Co-authored-by: Dean Tribble <[email protected]>
  • Loading branch information
0xpatrickdev and dtribble committed Jun 28, 2024
1 parent 59c3d2b commit cc8c08e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/boot/test/bootstrapTests/lca.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ test.serial('stakeBld', async t => {
},
},
}),
// TODO should receive "simulated packet timeout" error
// TODO propagate error message through bridge
// FIXME should receive "simulated packet timeout" error
// { message: 'simulated packet timeout' },
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ test('makeStakeBldInvitation', async t => {
);
const delegateOffer = await E(zoe).offer(delegateInv);
await t.throwsAsync(E(delegateOffer).getOfferResult(), {
message: 'simualted packet timeout',
message: 'simulated packet timeout',
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/smart-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@agoric/store": "^0.9.2",
"@agoric/vat-data": "^0.5.2",
"@agoric/vats": "^0.15.1",
"@agoric/vow": "^0.1.0",
"@agoric/zoe": "^0.26.2",
"@endo/eventual-send": "^1.2.2",
"@endo/far": "^1.1.2",
Expand Down
19 changes: 13 additions & 6 deletions packages/smart-wallet/src/offerWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ 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 { when, allVows } = heapVowTools;

/**
* @import {OfferSpec} from "./offers.js";
* @import {ContinuingOfferResult} from "./types.js";
Expand All @@ -37,7 +40,8 @@ import { UNPUBLISHED_RESULT } from './offers.js';
* @param {UserSeat} seat
*/
const watchForOfferResult = ({ resultWatcher }, seat) => {
const p = E(seat).getOfferResult();
// NOTE: this enables upgrade of the contract, NOT upgrade of the smart-wallet. See #9308
const p = when(E(seat).getOfferResult());
watchPromise(p, resultWatcher, seat);
return p;
};
Expand Down Expand Up @@ -67,11 +71,14 @@ const watchForPayout = ({ paymentWatcher }, seat) => {
* @param {UserSeat} seat
*/
export const watchOfferOutcomes = (watchers, seat) => {
return Promise.all([
watchForOfferResult(watchers, seat),
watchForNumWants(watchers, seat),
watchForPayout(watchers, seat),
]);
// NOTE: this enables upgrade of the contract, NOT upgrade of the smart-wallet. See #9308
return when(
allVows([
watchForOfferResult(watchers, seat),
watchForNumWants(watchers, seat),
watchForPayout(watchers, seat),
]),
);
};

const offerWatcherGuard = harden({
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/tools/fake-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const makeFakeLocalchainBridge = (zone, onToBridge = () => {}) => {
}
case '/cosmos.staking.v1beta1.MsgDelegate': {
if (message.amount.amount === '504') {
throw Error('simualted packet timeout');
throw Error('simulated packet timeout');
}
return /** @type {JsonSafe<MsgDelegateResponse>} */ ({});
}
Expand Down

0 comments on commit cc8c08e

Please sign in to comment.