Skip to content

Commit

Permalink
feat: add contact address property and register depositFacet name
Browse files Browse the repository at this point in the history
This makes it possible for Pegasus to find the wallet's
depositFacet via
E(home.namesByAddress).lookup(address, 'depositFacet')
  • Loading branch information
michaelfig committed Apr 11, 2021
1 parent a799be9 commit feae632
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
10 changes: 9 additions & 1 deletion packages/dapp-svelte-wallet/api/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ export default async function deployWallet(
const home = await homePromise;
// console.log('have home', home);
const {
agoric: { agoricNames, namesByAddress, board, faucet, zoe },
agoric: {
agoricNames,
namesByAddress,
myAddressNameAdmin,
board,
faucet,
zoe,
},
local: { http, spawner, wallet: oldWallet },
} = home;

Expand All @@ -27,6 +34,7 @@ export default async function deployWallet(
const walletVat = await E(walletInstall).spawn({
agoricNames,
namesByAddress,
myAddressNameAdmin,
zoe,
board,
faucet,
Expand Down
34 changes: 21 additions & 13 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const cmp = (a, b) => {
* @property {Board} board
* @property {NameHub} [agoricNames]
* @property {NameHub} [namesByAddress]
* @property {MyAddressNameAdmin} myAddressNameAdmin
* @property {(state: any) => void} [pursesStateChangeHandler=noActionStateChangeHandler]
* @property {(state: any) => void} [inboxStateChangeHandler=noActionStateChangeHandler]
* @param {MakeWalletParams} param0
Expand All @@ -64,6 +65,7 @@ export function makeWallet({
board,
agoricNames,
namesByAddress,
myAddressNameAdmin,
pursesStateChangeHandler = noActionStateChangeHandler,
inboxStateChangeHandler = noActionStateChangeHandler,
}) {
Expand Down Expand Up @@ -586,7 +588,7 @@ export function makeWallet({
[],
));

const addContact = async (petname, actions) => {
const addContact = async (petname, actions, address = undefined) => {
const already = await E(board).has(actions);
let depositFacet;
if (already) {
Expand All @@ -612,6 +614,7 @@ export function makeWallet({

const contact = harden({
actions,
address,
depositBoardId,
});

Expand Down Expand Up @@ -1156,18 +1159,10 @@ export function makeWallet({
await paymentRecord.actions.deposit(depositTo);
};

// Allow people to send us payments.
const selfContact = addContact(
'Self',
Far('contact', {
receive(payment) {
return addPayment(payment);
},
}),
);
let selfContactP;
async function getDepositFacetId(_brandBoardId) {
// Always return the generic deposit facet.
return E.get(selfContact).depositBoardId;
return E.get(selfContactP).depositBoardId;
}

async function disableAutoDeposit(pursePetname) {
Expand Down Expand Up @@ -1205,7 +1200,7 @@ export function makeWallet({
return pendingP;
}

const boardIdP = E.get(selfContact).depositBoardId;
const boardIdP = E.get(selfContactP).depositBoardId;
pendingEnableAutoDeposits.init(brand, boardIdP);
const boardId = await boardIdP;
brandToDepositFacetId.init(brand, boardId);
Expand Down Expand Up @@ -1302,7 +1297,7 @@ export function makeWallet({
}

function getSelfContact() {
return selfContact;
return selfContactP;
}

const makeManager = (petnameMapping, managerType) => {
Expand Down Expand Up @@ -1496,6 +1491,19 @@ export function makeWallet({
});

const initialize = async () => {
// Allow people to send us payments.
const selfDepositFacet = Far('contact', {
receive(payment) {
return addPayment(payment);
},
});
const [address] = await Promise.all([
E(myAddressNameAdmin).getMyAddress(),
E(myAddressNameAdmin).update('depositFacet', selfDepositFacet),
]);
// We need to do this before we can enable auto deposit.
selfContactP = addContact('Self', selfDepositFacet, address);

// Make Zoe invite purse
const ZOE_INVITE_PURSE_PETNAME = 'Default Zoe invite purse';
const inviteIssuerP = E(zoe).getInvitationIssuer();
Expand Down
11 changes: 10 additions & 1 deletion packages/dapp-svelte-wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,25 @@ export function buildRootObject(_vatPowers) {
},
});

async function startup({ zoe, board, agoricNames, namesByAddress }) {
async function startup({
zoe,
board,
agoricNames,
namesByAddress,
myAddressNameAdmin,
}) {
const w = makeWallet({
agoricNames,
namesByAddress,
myAddressNameAdmin,
zoe,
board,
pursesStateChangeHandler: pursesPublish,
inboxStateChangeHandler: inboxPublish,
});
console.error('waiting for wallet to initialize');
await w.initialized;
console.error('wallet initialized');
walletAdmin = w.admin;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ import { makeZoe } from '@agoric/zoe';
import fakeVatAdmin from '@agoric/zoe/src/contractFacet/fakeVatAdmin';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeBoard } from '@agoric/cosmic-swingset/lib/ag-solo/vats/lib-board';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeNameHubKit } from '@agoric/cosmic-swingset/lib/ag-solo/vats/nameHub';
import { makeWallet } from '../src/lib-wallet';

import '../src/types';

function makeFakeMyAddressNameAdmin() {
const { nameAdmin: rawMyAddressNameAdmin } = makeNameHubKit();
return {
...rawMyAddressNameAdmin,
getMyAddress() {
return 'agoric1test1';
},
};
}

const setup = async () => {
const zoe = makeZoe(fakeVatAdmin);
const board = makeBoard();
Expand All @@ -20,6 +32,7 @@ const setup = async () => {
const { admin: wallet, initialized } = makeWallet({
zoe,
board,
myAddressNameAdmin: makeFakeMyAddressNameAdmin(),
pursesStateChangeHandler,
inboxStateChangeHandler,
});
Expand Down
15 changes: 15 additions & 0 deletions packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ import { assert } from '@agoric/assert';
import { E } from '@agoric/eventual-send';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeBoard } from '@agoric/cosmic-swingset/lib/ag-solo/vats/lib-board';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeNameHubKit } from '@agoric/cosmic-swingset/lib/ag-solo/vats/nameHub';
import { makeWallet } from '../src/lib-wallet';

import '../src/types';

const ZOE_INVITE_PURSE_PETNAME = 'Default Zoe invite purse';

function makeFakeMyAddressNameAdmin() {
const { nameAdmin: rawMyAddressNameAdmin } = makeNameHubKit();
return {
...rawMyAddressNameAdmin,
getMyAddress() {
return 'agoric1test1';
},
};
}

async function setupTest() {
const pursesStateChangeLog = [];
const inboxStateChangeLog = [];
Expand Down Expand Up @@ -74,6 +86,7 @@ async function setupTest() {
const { admin: wallet, initialized } = makeWallet({
zoe,
board,
myAddressNameAdmin: makeFakeMyAddressNameAdmin(),
pursesStateChangeHandler,
inboxStateChangeHandler,
});
Expand Down Expand Up @@ -1197,6 +1210,7 @@ test('addOffer makeContinuingInvitation', async t => {
const { admin: wallet, initialized } = makeWallet({
zoe,
board,
myAddressNameAdmin: makeFakeMyAddressNameAdmin(),
pursesStateChangeHandler,
inboxStateChangeHandler,
});
Expand Down Expand Up @@ -1261,6 +1275,7 @@ test('getZoe, getBoard', async t => {
const { admin: wallet, initialized } = makeWallet({
zoe,
board,
myAddressNameAdmin: makeFakeMyAddressNameAdmin(),
pursesStateChangeHandler,
inboxStateChangeHandler,
});
Expand Down

0 comments on commit feae632

Please sign in to comment.