Skip to content

Commit

Permalink
feat(dapp-svelte-wallet): add getAgoricNames and getNamesByAddress
Browse files Browse the repository at this point in the history
Both these methods are exposed on the wallet bridge, and return
the corresponding on-chain naming hubs.  Optional variadic
arguments specify a path to look up.
  • Loading branch information
michaelfig committed Mar 26, 2021
1 parent 04c5bdd commit 7c8f4d5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 3 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,7 @@ export default async function deployWallet(
const home = await homePromise;
// console.log('have home', home);
const {
agoric: { board, faucet, zoe },
agoric: { agoricNames, namesByAddress, board, faucet, zoe },
local: { http, spawner, wallet: oldWallet },
} = home;

Expand All @@ -25,6 +25,8 @@ export default async function deployWallet(

// Wallet for both end-user client and dapp dev client
const walletVat = await E(walletInstall).spawn({
agoricNames,
namesByAddress,
zoe,
board,
faucet,
Expand Down
10 changes: 10 additions & 0 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ const cmp = (a, b) => {
* @typedef {Object} MakeWalletParams
* @property {ZoeService} zoe
* @property {Board} board
* @property {NameHub} agoricNames
* @property {NameHub} namesByAddress
* @property {(state: any) => void} [pursesStateChangeHandler=noActionStateChangeHandler]
* @property {(state: any) => void} [inboxStateChangeHandler=noActionStateChangeHandler]
* @param {MakeWalletParams} param0
*/
export function makeWallet({
zoe,
board,
agoricNames,
namesByAddress,
pursesStateChangeHandler = noActionStateChangeHandler,
inboxStateChangeHandler = noActionStateChangeHandler,
}) {
Expand Down Expand Up @@ -1472,6 +1476,12 @@ export function makeWallet({
getBoard() {
return board;
},
getAgoricNames(...path) {
return E(agoricNames).lookup(...path);
},
getNamesByAddress(...path) {
return E(namesByAddress).lookup(...path);
},
});

const initialize = async () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/dapp-svelte-wallet/api/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @typedef {import('@agoric/cosmic-swingset/lib/ag-solo/vats/lib-board').Board} Board
*/

/**
* @typedef {import('@agoric/cosmic-swingset/lib/ag-solo/vats/types').NameHub} NameHub
*/

/**
* @typedef {string | string[]} Petname A petname can either be a plain string
* or a path for which the first element is a petname for the origin, and the
Expand Down Expand Up @@ -83,6 +87,10 @@
* Get the Zoe Service
* @property {() => Promise<Board>} getBoard
* Get the Board
* @property {(...path: Array<unknown>) => Promise<unknown>} getAgoricNames
* Get the curated Agoric public naming hub
* @property {(...path: Array<unknown>) => Promise<unknown>} getNamesByAddress
* Get the Agoric address mapped to its public naming hub
* @property {(brands: Array<Brand>) => Promise<Array<Petname>>}
* getBrandPetnames
* Get the petnames for the brands that are passed in
Expand Down
18 changes: 17 additions & 1 deletion packages/dapp-svelte-wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ export function buildRootObject(_vatPowers) {
},
});

async function startup({ zoe, board }) {
async function startup({ zoe, board, agoricNames, namesByAddress }) {
const w = makeWallet({
agoricNames,
namesByAddress,
zoe,
board,
pursesStateChangeHandler: pursesPublish,
Expand Down Expand Up @@ -178,6 +180,14 @@ export function buildRootObject(_vatPowers) {
await approve();
return walletAdmin.getBoard();
},
async getAgoricNames(...path) {
await approve();
return walletAdmin.getAgoricNames(...path);
},
async getNamesByAddress(...path) {
await approve();
return walletAdmin.getNamesByAddress(...path);
},
async getBrandPetnames(brands) {
await approve();
return walletAdmin.getBrandPetnames(brands);
Expand Down Expand Up @@ -227,6 +237,12 @@ export function buildRootObject(_vatPowers) {
async getBoard() {
return walletAdmin.getBoard();
},
async getAgoricNames(...path) {
return walletAdmin.getAgoricNames(...path);
},
async getNamesByAddress(...path) {
return walletAdmin.getNamesByAddress(...path);
},
async getBrandPetnames(brands) {
return walletAdmin.getBrandPetnames(brands);
},
Expand Down

0 comments on commit 7c8f4d5

Please sign in to comment.