Skip to content

Commit

Permalink
feat(smart-wallet): publishAgoricBrandsDisplayInfo to vstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Aug 5, 2023
1 parent d28354b commit 3c13938
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// @ts-check
import { E } from '@endo/far';
import { makeMarshal } from '@endo/marshal';

const { fromEntries, keys, values } = Object;
const { Fail } = assert;

// vstorage paths under published.*
const WALLET_STORAGE_PATH_SEGMENT = 'wallet';
const BOARD_AUX = 'boardAux';

const { fromEntries, keys, values } = Object;
const marshalData = makeMarshal(_val => Fail`data only`);

// borrow zip, allValues from @agoric/interal
// but don't bring in all of @endo/marshal etc.
Expand Down Expand Up @@ -74,6 +80,33 @@ export const upgradeWalletFactory = async (
};
harden(upgradeWalletFactory);

/**
* @param { BootstrapPowers } powers
*/
export const publishAgoricBrandsDisplayInfo = async ({
consume: { agoricNames, board, chainStorage },
}) => {
// @ts-expect-error chainStorage is only falsy in testing
const boardAux = E(chainStorage).makeChildNode(BOARD_AUX);
const publishBrandInfo = async brand => {
const [id, displayInfo, allegedName] = await Promise.all([
E(board).getId(brand),
E(brand).getDisplayInfo(),
E(brand).getAllegedName(),
]);
const node = E(boardAux).makeChildNode(id);
const aux = marshalData.toCapData(harden({ allegedName, displayInfo }));
await E(node).setValue(JSON.stringify(aux));
};

/** @type {ERef<NameHub>} */
const brandHub = E(agoricNames).lookup('brand');
const brands = await E(brandHub).values();
// tolerate failure; in particular, for the timer brand
await Promise.allSettled(brands.map(publishBrandInfo));
};
harden(publishAgoricBrandsDisplayInfo);

/** @type { import("@agoric/vats/src/core/lib-boot").BootstrapManifest } */
const manifest = {
[upgradeWalletFactory.name]: {
Expand All @@ -90,6 +123,9 @@ const manifest = {
consume: { walletFactory: true, provisionPool: true },
},
},
[publishAgoricBrandsDisplayInfo.name]: {
consume: { agoricNames: true, board: true, chainStorage: true },
},
};
harden(manifest);

Expand Down

0 comments on commit 3c13938

Please sign in to comment.