Skip to content

Commit

Permalink
use readPublished for types in agoric-cli (#10450)
Browse files Browse the repository at this point in the history
follow-up

## Description
Pulled out of #10422 while debugging an intermittent Docker integration failure.

### Security Considerations
none
### Scaling Considerations
none

### Documentation Considerations
none

### Testing Considerations
CI

### Upgrade Considerations
none
  • Loading branch information
mergify[bot] authored Nov 12, 2024
2 parents a82d636 + c890f53 commit 3b799b8
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 76.19
"atLeast": 76.24
}
}
2 changes: 1 addition & 1 deletion packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@
"workerThreads": false
},
"typeCoverage": {
"atLeast": 77.45
"atLeast": 77.54
}
}
8 changes: 2 additions & 6 deletions packages/agoric-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,12 @@ export const makeAuctionCommand = (
* }} opts
*/
async opts => {
const { agoricNames, readLatestHead } = await makeVstorageKit(
const { agoricNames, readPublished } = await makeVstorageKit(
{ fetch },
networkConfig,
);

/** @type {{ current: AuctionParamRecord }} */
// @ts-expect-error XXX should runtime check?
const { current } = await readLatestHead(
`published.auction.governance`,
);
const { current } = await readPublished(`auction.governance`);

const {
AuctionStartDelay: {
Expand Down
27 changes: 12 additions & 15 deletions packages/agoric-cli/src/commands/gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ export const makeGovCommand = (_logger, io = {}) => {
optUtils,
) {
const utils = await (optUtils || makeVstorageKit({ fetch }, networkConfig));
const { agoricNames, readLatestHead } = utils;
const { agoricNames, readPublished } = utils;

assert(keyringBackend, 'missing keyring-backend option');

let current;
if (sendFrom) {
current = await getCurrent(sendFrom, { readLatestHead });
current = await getCurrent(sendFrom, { readPublished });
}

const offer = toOffer(agoricNames, current);
Expand Down Expand Up @@ -134,9 +134,9 @@ export const makeGovCommand = (_logger, io = {}) => {
show({ timestamp, height, offerId: offer.id, txhash });
const checkInWallet = async blockInfo => {
const [state, update] = await Promise.all([
getCurrent(sendFrom, { readLatestHead }),
getLastUpdate(sendFrom, { readLatestHead }),
readLatestHead(`published.wallet.${sendFrom}`),
getCurrent(sendFrom, { readPublished }),
getLastUpdate(sendFrom, { readPublished }),
readPublished(`wallet.${sendFrom}`),
]);
if (update.updated === 'offerStatus' && update.status.id === offer.id) {
return blockInfo;
Expand Down Expand Up @@ -265,11 +265,11 @@ export const makeGovCommand = (_logger, io = {}) => {
)
.requiredOption('--for <string>', 'description of the invitation')
.action(async opts => {
const { agoricNames, readLatestHead } = await makeVstorageKit(
const { agoricNames, readPublished } = await makeVstorageKit(
{ fetch },
networkConfig,
);
const current = await getCurrent(opts.from, { readLatestHead });
const current = await getCurrent(opts.from, { readPublished });

const known = findContinuingIds(current, agoricNames);
if (!known) {
Expand All @@ -294,11 +294,11 @@ export const makeGovCommand = (_logger, io = {}) => {
normalizeAddress,
)
.action(async opts => {
const { agoricNames, readLatestHead } = await makeVstorageKit(
const { agoricNames, readPublished } = await makeVstorageKit(
{ fetch },
networkConfig,
);
const current = await getCurrent(opts.from, { readLatestHead });
const current = await getCurrent(opts.from, { readPublished });

const found = findContinuingIds(current, agoricNames);
for (const it of found) {
Expand Down Expand Up @@ -334,19 +334,16 @@ export const makeGovCommand = (_logger, io = {}) => {
)
.action(async function (opts, options) {
const utils = await makeVstorageKit({ fetch }, networkConfig);
const { readLatestHead } = utils;
const { readPublished } = utils;

const info = await readLatestHead(
`published.committees.${opts.pathname}.latestQuestion`,
const questionDesc = await readPublished(
`committees.${opts.pathname}.latestQuestion`,
).catch(err => {
// CommanderError is a class constructor, and so
// must be invoked with `new`.
throw new CommanderError(1, 'VSTORAGE_FAILURE', err.message);
});

// XXX runtime shape-check
const questionDesc = /** @type {QuestionDetails} */ (info);

// TODO support multiple position arguments
const chosenPositions = [questionDesc.positions[opts.forPosition]];
assert(chosenPositions, `undefined position index ${opts.forPosition}`);
Expand Down
20 changes: 9 additions & 11 deletions packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,12 @@ inter auction status
* }}
*/ opts,
) => {
const { agoricNames, readLatestHead } = await tryMakeUtils();
const { agoricNames, readPublished } = await tryMakeUtils();

/** @type { [ScheduleNotification, BookDataNotification, *] } */
// @ts-expect-error dynamic cast
const [schedule, book, { current: params }] = await Promise.all([
readLatestHead(`published.auction.schedule`),
readLatestHead(`published.auction.book${opts.book}`),
readLatestHead(`published.auction.governance`),
readPublished('auction.schedule'),
readPublished(`auction.book${opts.book}`),
readPublished('auction.governance'),
]);

const fmt = makeFormatters(Object.values(agoricNames.vbankAsset));
Expand Down Expand Up @@ -493,9 +491,9 @@ inter auction status
return;
}

const { networkConfig, readLatestHead } = await tryMakeUtils();
const { networkConfig, readPublished } = await tryMakeUtils();

const current = await getCurrent(from, { readLatestHead });
const current = await getCurrent(from, { readPublished });
const liveIds = current.liveOffers.map(([i, _s]) => i);
if (!liveIds.includes(id)) {
// InvalidArgumentError is a class constructor, and so
Expand All @@ -520,7 +518,7 @@ inter auction status
show({ timestamp, height, offerId: id, txhash });

const checkGone = async blockInfo => {
const pollResult = await getCurrent(from, { readLatestHead });
const pollResult = await getCurrent(from, { readPublished });
const found = pollResult.liveOffers.find(([i, _]) => i === id);
if (found) throw Error('retry');
return blockInfo;
Expand Down Expand Up @@ -562,11 +560,11 @@ $ inter bid list --from my-acct
* }} opts
*/
async opts => {
const { agoricNames, readLatestHead, storedWalletState } =
const { agoricNames, readPublished, storedWalletState } =
await tryMakeUtils();

const [current, state] = await Promise.all([
getCurrent(opts.from, { readLatestHead }),
getCurrent(opts.from, { readPublished }),
storedWalletState(opts.from),
]);
const entries = opts.all
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export const makeOracleCommand = (logger, io = {}) => {
console.warn(sendHint);
});

const findOracleCap = async (instance, from, readLatestHead) => {
const current = await getCurrent(from, { readLatestHead });
const findOracleCap = async (instance, from, readPublished) => {
const current = await getCurrent(from, { readPublished });

const { offerToUsedInvitation: entries } = /** @type {any} */ (current);
Array.isArray(entries) || Fail`entries must be an array: ${entries}`;
Expand Down
15 changes: 6 additions & 9 deletions packages/agoric-cli/src/commands/vaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ export const makeVaultsCommand = logger => {
normalizeAddress,
)
.action(async function (opts) {
const { readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);
const { readPublished } = await makeVstorageKit({ fetch }, networkConfig);

const current = await getCurrent(opts.from, {
readLatestHead,
readPublished,
});

const vaultStoragePaths = current.offerToPublicSubscriberPaths.map(
Expand Down Expand Up @@ -102,14 +99,14 @@ export const makeVaultsCommand = logger => {
.requiredOption('--vaultId <string>', 'Key of vault (e.g. vault1)')
.action(async function (opts) {
logger.warn('running with options', opts);
const { agoricNames, readLatestHead } = await makeVstorageKit(
const { agoricNames, readPublished } = await makeVstorageKit(
{ fetch },
networkConfig,
);

const previousOfferId = await lookupOfferIdForVault(
opts.vaultId,
getCurrent(opts.from, { readLatestHead }),
getCurrent(opts.from, { readPublished }),
);

const offer = Offers.vaults.AdjustBalances(
Expand Down Expand Up @@ -146,14 +143,14 @@ export const makeVaultsCommand = logger => {
)
.action(async function (opts) {
logger.warn('running with options', opts);
const { agoricNames, readLatestHead } = await makeVstorageKit(
const { agoricNames, readPublished } = await makeVstorageKit(
{ fetch },
networkConfig,
);

const previousOfferId = await lookupOfferIdForVault(
opts.vaultId,
getCurrent(opts.from, { readLatestHead }),
getCurrent(opts.from, { readPublished }),
);

const offer = Offers.vaults.CloseVault(
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const makeWalletCommand = async command => {
normalizeAddress,
)
.action(async function (opts) {
const { agoricNames, unserializer, readLatestHead } =
const { agoricNames, unserializer, readPublished } =
await makeVstorageKit(
{
fetch,
Expand All @@ -191,7 +191,7 @@ export const makeWalletCommand = async command => {

const coalesced = await coalesceWalletState(follower);

const current = await getCurrent(opts.from, { readLatestHead });
const current = await getCurrent(opts.from, { readPublished });

console.warn(
'got coalesced',
Expand Down
15 changes: 7 additions & 8 deletions packages/agoric-cli/src/lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { execSwingsetTransaction, pollTx } from './chain.js';
/**
* @import {CurrentWalletRecord} from '@agoric/smart-wallet/src/smartWallet.js';
* @import {AgoricNamesRemotes} from '@agoric/vats/tools/board-utils.js';
* @import {MinimalNetworkConfig, WalletUtils} from '@agoric/client-utils';
* @import {MinimalNetworkConfig, VstorageKit} from '@agoric/client-utils';
*/

const marshaller = boardSlottingMarshaller();
Expand All @@ -25,15 +25,15 @@ const emptyCurrentRecord = {

/**
* @param {string} addr
* @param {Pick<WalletUtils, 'readLatestHead'>} io
* @param {Pick<VstorageKit, 'readPublished'>} io
* @returns {Promise<import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord>}
*/
export const getCurrent = async (addr, { readLatestHead }) => {
export const getCurrent = async (addr, { readPublished }) => {
// Partial because older writes may not have had all properties
// NB: assumes changes are only additions
let current =
/** @type {Partial<import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord> | undefined} */ (
await readLatestHead(`published.wallet.${addr}.current`)
await readPublished(`wallet.${addr}.current`)
);
if (current === undefined) {
throw Error(`undefined current node for ${addr}`);
Expand All @@ -60,12 +60,11 @@ export const getCurrent = async (addr, { readLatestHead }) => {

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

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@
"workerThreads": false
},
"typeCoverage": {
"atLeast": 90.58
"atLeast": 91.11
}
}
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
"timeout": "20m"
},
"typeCoverage": {
"atLeast": 80.52
"atLeast": 82.83
}
}
2 changes: 1 addition & 1 deletion packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 93.22
"atLeast": 93.14
}
}
2 changes: 1 addition & 1 deletion packages/vats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
"workerThreads": false
},
"typeCoverage": {
"atLeast": 91.52
"atLeast": 91.39
}
}

0 comments on commit 3b799b8

Please sign in to comment.