Skip to content

Commit

Permalink
feat: getCurrentWalletRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 8, 2024
1 parent 924fd06 commit f57d920
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
13 changes: 3 additions & 10 deletions a3p-integration/proposals/z:acceptance/governance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,15 @@ test.serial(
'economic committee can make governance proposal and vote on it',
async t => {
const { waitUntil } = makeTimerUtils({ setTimeout });
const { readLatestHead, getLastUpdate } = await makeWalletUtils(
{ delay, fetch },
networkConfig,
);
const { readLatestHead, getLastUpdate, getCurrentWalletRecord } =
await makeWalletUtils({ delay, fetch }, networkConfig);
const governanceDriver = await makeGovernanceDriver(fetch, networkConfig);

/** @type {any} */
const instance = await readLatestHead(`published.agoricNames.instance`);
const instances = Object.fromEntries(instance);

const wallet =
/** @type {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} */ (
await readLatestHead(
`published.wallet.${governanceAddresses[0]}.current`,
)
);
const wallet = await getCurrentWalletRecord(governanceAddresses[0]);
const usedInvitations = wallet.offerToUsedInvitation;

const charterInvitation = usedInvitations.find(
Expand Down
9 changes: 3 additions & 6 deletions a3p-integration/proposals/z:acceptance/test-lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env node */
import { makeVstorageKit, makeStargateClient } from '@agoric/client-utils';
import { makeStargateClient, makeVstorageKit } from '@agoric/client-utils';
import { readFile, writeFile } from 'node:fs/promises';
import { networkConfig } from './rpc.js';

Expand Down Expand Up @@ -56,11 +56,8 @@ export const getBalances = async (addresses, targetDenom = undefined) => {
* @param {WalletUtils} walletUtils
* @returns {Promise<string[]>}
*/
export const listVaults = async (addr, { readLatestHead }) => {
// TODO parameterize readLatestHead to match these string types
const current = /** @type {CurrentWalletRecord} */ (
await readLatestHead(`published.wallet.${addr}.current`)
);
export const listVaults = async (addr, { getCurrentWalletRecord }) => {
const current = await getCurrentWalletRecord(addr);
const vaultStoragePaths = current.offerToPublicSubscriberPaths.map(
([_offerId, pathmap]) => pathmap.vault,
);
Expand Down
19 changes: 16 additions & 3 deletions packages/client-utils/src/wallet-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { boardSlottingMarshaller, makeVstorageKit } from './vstorage-kit.js';

/**
* @import {Amount, Brand} from '@agoric/ertp/src/types.js'
* @import {CurrentWalletRecord, UpdateRecord} from '@agoric/smart-wallet/src/smartWallet.js';
* @import {MinimalNetworkConfig} from './rpc.js';
*/

Expand Down Expand Up @@ -82,11 +83,22 @@ export const makeWalletUtils = async ({ fetch, delay }, networkConfig) => {

/**
* @param {string} addr
* @returns {Promise<import('@agoric/smart-wallet/src/smartWallet.js').UpdateRecord>}
* @returns {Promise<UpdateRecord>}
*/
const getLastUpdate = addr => {
// @ts-expect-error cast
return readLatestHead(`published.wallet.${addr}`);
return /** @type {Promise<UpdateRecord>} */ (
readLatestHead(`published.wallet.${addr}`)
);
};

/**
* @param {string} addr
* @returns {Promise<CurrentWalletRecord>}
*/
const getCurrentWalletRecord = addr => {
return /** @type {Promise<CurrentWalletRecord>} */ (
readLatestHead(`published.wallet.${addr}.current`)
);
};

return {
Expand All @@ -96,6 +108,7 @@ export const makeWalletUtils = async ({ fetch, delay }, networkConfig) => {
marshaller,
vstorage,
getLastUpdate,
getCurrentWalletRecord,
readLatestHead,
storedWalletState,
pollOffer,
Expand Down

0 comments on commit f57d920

Please sign in to comment.