Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

walletFactory misc #6178

Merged
merged 3 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// @ts-check
import { AmountMath, AmountShape, PaymentShape } from '@agoric/ertp';
import {
AmountMath,
AmountShape,
BrandShape,
PaymentShape,
} from '@agoric/ertp';
import { isNat } from '@agoric/nat';
import {
makeStoredPublishKit,
observeIteration,
observeNotifier,
} from '@agoric/notifier';
import { M, makeScalarMapStore } from '@agoric/store';
import { fit, M, makeScalarMapStore } from '@agoric/store';
import {
defineVirtualFarClassKit,
defineDurableFarClassKit,
makeKindHandle,
makeScalarBigMapStore,
pickFacet,
} from '@agoric/vat-data';
Expand Down Expand Up @@ -105,13 +111,26 @@ const { details: X, quote: q } = assert;
* }} shared
*/
export const initState = (unique, shared) => {
// TODO move to guard
// assert.typeof(address, 'string', 'invalid address');
// assert(bank, 'missing bank');
// assert(invitationIssuer, 'missing invitationIssuer');
// assert(invitationBrand, 'missing invitationBrand');
// assert(invitationPurse, 'missing invitationPurse');
// assert(storageNode, 'missing storageNode');
// Some validation of inputs. "any" erefs because this synchronous call can't check more than that.
fit(
unique,
harden({
address: M.string(),
bank: M.eref(M.any()),
invitationPurse: M.eref(M.any()),
}),
);
fit(
shared,
harden({
agoricNames: M.eref(M.any()),
invitationIssuer: M.eref(M.any()),
invitationBrand: BrandShape,
publicMarshaller: M.any(),
storageNode: M.eref(M.any()),
zoe: M.eref(M.any()),
}),
);

// NB: state size must not grow monotonically
// This is the node that UIs subscribe to for everything they need.
Expand All @@ -132,15 +151,15 @@ export const initState = (unique, shared) => {
offerToInvitationMakers: makeScalarBigMapStore('invitation makers', {
durable: true,
}),
// What purses have reported on construction and by getCurrentAmountNotifier updates.
purseBalances: makeScalarMapStore(),
};

const nonpreciousState = {
brandDescriptors: makeScalarMapStore(),
// To ensure every offer ID is unique we require that each is a number greater
// than has ever been used. This high water mark is sufficient to track that.
lastOfferId: 0,
// What purses have reported on construction and by getCurrentAmountNotifier updates.
purseBalances: makeScalarMapStore(),
updatePublishKit: harden(
makeStoredPublishKit(myWalletStorageNode, shared.publicMarshaller),
),
Expand Down Expand Up @@ -276,7 +295,6 @@ const behavior = {
/**
* Similar to {DepositFacet} but async because it has to look up the purse.
*/
// TODO(PS0) decide whether to match canonical `DepositFacet'. it would have to take a local Payment
deposit: {
/**
* Put the assets from the payment into the appropriate purse.
Expand Down Expand Up @@ -439,8 +457,8 @@ const finish = ({ state, facets }) => {
});
};

const SmartWalletKit = defineVirtualFarClassKit(
'SmartWallet',
const SmartWalletKit = defineDurableFarClassKit(
makeKindHandle('SmartWallet'),
behaviorGuards,
initState,
behavior,
Expand Down
4 changes: 3 additions & 1 deletion packages/smart-wallet/src/walletFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const start = async (zcf, privateArgs) => {
const { storageNode, bridgeManager } = privateArgs;

/** @type {MapStore<string, import('./smartWallet').SmartWallet>} */
const walletsByAddress = makeScalarBigMapStore('walletsByAddress');
const walletsByAddress = makeScalarBigMapStore('walletsByAddress', {
durable: true,
});
const provider = makeAtomicProvider(walletsByAddress);

const handleWalletAction = makeHeapFarInstance(
Expand Down