Skip to content

Commit

Permalink
refactor: wallet spawn takes publicFacetName
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 1, 2022
1 parent ad13c34 commit fd1b8c0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export const makeAddressNameHubs = async ({
});
// reserve space for deposit facet
myAddressNameAdmin.reserve('depositFacet');
myAddressNameAdmin.reserve('smartWallet');
// Register it with the namesByAddress hub.
namesByAddressAdmin.update(address, myAddressNameHub, myAddressNameAdmin);
return { agoricNames, namesByAddress, myAddressNameAdmin };
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const cmp = (a, b) => {
* @property {(state: any) => void} [pursesStateChangeHandler=noActionStateChangeHandler]
* @property {(state: any) => void} [inboxStateChangeHandler=noActionStateChangeHandler]
* @property {() => number} [dateNow]
* @property {string} [publicFacetName]
* @param {MakeWalletParams} param0
*/
export function makeWallet({
Expand All @@ -73,6 +74,7 @@ export function makeWallet({
pursesStateChangeHandler = noActionStateChangeHandler,
inboxStateChangeHandler = noActionStateChangeHandler,
dateNow = undefined,
publicFacetName = 'depositFacet',
}) {
let lastId = 0;

Expand Down Expand Up @@ -1875,7 +1877,7 @@ export function makeWallet({
.then(addInviteDepositFacet);
zoeInvitePurse = wallet.getPurse(ZOE_INVITE_PURSE_PETNAME);

await E(myAddressNameAdmin).update('depositFacet', selfDepositFacet);
await E(myAddressNameAdmin).update(publicFacetName, selfDepositFacet);
};

// Importing assets as virtual purses from the bank is a highly-trusted path.
Expand Down
29 changes: 27 additions & 2 deletions packages/wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ import { makeTimerDeviceDateNow, makeTimerServiceDateNow } from './date-now.js';

import './internal-types.js';

/**
* @typedef {{
* agoricNames: NameHub,
* board: Board,
* localTimerPollInterval?: bigint,
* localTimerService: unknown,
* myAddressNameAdmin: MyAddressNameAdmin,
* namesByAddress: NameHub,
* publicFacetName: string,
* timerDevice?: unknown,
* timerDeviceScale?: number,
* zoe: ERef<ZoeService>,
* }} WalletStartupTerms
*/

export function buildRootObject(vatPowers) {
// See if we have the device vat power.
const { D } = vatPowers || {};
Expand Down Expand Up @@ -81,6 +96,10 @@ export function buildRootObject(vatPowers) {
},
});

/**
*
* @param {WalletStartupTerms} terms
*/
async function startup({
zoe,
board,
Expand All @@ -91,6 +110,7 @@ export function buildRootObject(vatPowers) {
timerDeviceScale,
localTimerService,
localTimerPollInterval,
publicFacetName,
}) {
/** @type {ERef<() => number> | undefined} */
let dateNowP;
Expand All @@ -114,6 +134,7 @@ export function buildRootObject(vatPowers) {
pursesStateChangeHandler: pursesPublish,
inboxStateChangeHandler: inboxPublish,
dateNow,
publicFacetName,
});
console.error('waiting for wallet to initialize');
await w.initialized;
Expand Down Expand Up @@ -641,8 +662,12 @@ export function buildRootObject(vatPowers) {
});
}

// Adapter for spawner.
export default function spawn(terms, _inviteMaker) {
/**
* Adapter for spawner.
*
* @param {WalletStartupTerms} terms
*/
export default function spawn(terms) {
const walletVat = buildRootObject();
return walletVat.startup(terms).then(_ => walletVat);
}
14 changes: 12 additions & 2 deletions packages/wallet/contract/src/smart-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ import '@agoric/wallet-backend/src/types.js'; // TODO avoid ambient types

const { assign, entries, keys, fromEntries } = Object;

/**
* @typedef {{
* agoricNames: NameHub,
* bank: import('@agoric/vats/src/vat-bank').Bank,
* board: Board,
* myAddressNameAdmin: MyAddressNameAdmin,
* namesByAddress: NameHub,
* }} SmartWalletContractTerms
*/

/**
*
* TODO: multi-tennant wallet
*
* @param {ZCF} zcf
* @param {ZCF<SmartWalletContractTerms>} zcf
* @param {{
* storageNode?: ERef<StorageNode>,
* marshaller?: ERef<Marshaller>,
Expand All @@ -39,10 +49,10 @@ export const start = async (zcf, privateArgs) => {
zoe,
board,
localTimerService: undefined,
publicFacetName: 'smartWallet',
});

const wallet = await E(walletVat).getWallet(bank);
// @ts-expect-error TODO: type for getMyAddress
const address = await E(myAddressNameAdmin).getMyAddress();
const { storageNode, marshaller } = privateArgs;

Expand Down
1 change: 1 addition & 0 deletions packages/wallet/contract/test/test-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const makeTestContext = async t => {
});
// reserve space for deposit facet
myAddressNameAdmin.reserve('depositFacet');
myAddressNameAdmin.reserve('smartWallet');
// Register it with the namesByAddress hub.
return E(consume.namesByAddressAdmin).update(
address,
Expand Down

0 comments on commit fd1b8c0

Please sign in to comment.