Skip to content

Commit

Permalink
feat: VstorageKit
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 8, 2024
1 parent 5896d07 commit 71486d7
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 286 deletions.
4 changes: 2 additions & 2 deletions a3p-integration/proposals/s:stake-bld/test-lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const makeAgoricNames = async (ctx, vstorage) => {
* @param {{ fetch: typeof window.fetch }} io
* @param {MinimalNetworkConfig} config
*/
export const makeRpcUtils = async ({ fetch }, config = networkConfig) => {
export const makeVstorageKit = async ({ fetch }, config = networkConfig) => {
await null;
try {
const vstorage = makeVStorage({ fetch }, config);
Expand Down Expand Up @@ -263,4 +263,4 @@ export const makeRpcUtils = async ({ fetch }, config = networkConfig) => {
throw Error(`RPC failure (${config.rpcAddrs}): ${err.message}`);
}
};
/** @typedef {Awaited<ReturnType<typeof makeRpcUtils>>} RpcUtils */
/** @typedef {Awaited<ReturnType<typeof makeVstorageKit>>} RpcUtils */
4 changes: 2 additions & 2 deletions a3p-integration/proposals/s:stake-bld/test-lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { inspect } from 'util';
import { execSwingsetTransaction, pollTx } from './chain.js';
import { makeRpcUtils } from './rpc.js';
import { makeVstorageKit } from './rpc.js';

/**
* Sign and broadcast a wallet-action.
Expand Down Expand Up @@ -61,7 +61,7 @@ export const makeWalletUtils = async (
networkConfig,
) => {
const { agoricNames, fromBoard, marshaller, readLatestHead, vstorage } =
await makeRpcUtils({ fetch }, networkConfig);
await makeVstorageKit({ fetch }, networkConfig);

/**
*
Expand Down
4 changes: 2 additions & 2 deletions a3p-integration/proposals/z:acceptance/test-lib/governance.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { agops, agoric, executeOffer } from '@agoric/synthetic-chain';
import { makeRpcUtils } from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';

/**
* @param {typeof window.fetch} fetch
* @param {import('@agoric/client-utils').MinimalNetworkConfig} networkConfig
*/
export const makeGovernanceDriver = async (fetch, networkConfig) => {
const { readLatestHead, marshaller } = await makeRpcUtils(
const { readLatestHead, marshaller } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down
4 changes: 2 additions & 2 deletions a3p-integration/proposals/z:acceptance/test-lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const makeAgoricNames = async (ctx, vstorage) => {
* @param {{ fetch: typeof window.fetch }} io
* @param {MinimalNetworkConfig} config
*/
export const makeRpcUtils = async ({ fetch }, config = networkConfig) => {
export const makeVstorageKit = async ({ fetch }, config = networkConfig) => {
await null;
try {
const vstorage = makeVStorage({ fetch }, config);
Expand Down Expand Up @@ -263,4 +263,4 @@ export const makeRpcUtils = async ({ fetch }, config = networkConfig) => {
throw Error(`RPC failure (${config.rpcAddrs}): ${err.message}`);
}
};
/** @typedef {Awaited<ReturnType<typeof makeRpcUtils>>} RpcUtils */
/** @typedef {Awaited<ReturnType<typeof makeVstorageKit>>} RpcUtils */
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-env node */
import { InvalidArgumentError } from 'commander';
import { Fail } from '@endo/errors';
import { makeRpcUtils } from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';
import { outputActionAndHint } from '../lib/wallet.js';
import { getNetworkConfig } from '../lib/network-config.js';

Expand Down Expand Up @@ -89,7 +89,7 @@ export const makeAuctionCommand = (
* }} opts
*/
async opts => {
const { agoricNames, readLatestHead } = await makeRpcUtils(
const { agoricNames, readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down
12 changes: 6 additions & 6 deletions packages/agoric-cli/src/commands/gov.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeRpcUtils } from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';
import { execFileSync as execFileSyncAmbient } from 'child_process';
import { Command, CommanderError } from 'commander';
import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js';
Expand Down Expand Up @@ -91,13 +91,13 @@ export const makeGovCommand = (_logger, io = {}) => {
* keyringBackend: string,
* instanceName?: string,
* }} detail
* @param {Awaited<ReturnType<makeRpcUtils>>} [optUtils]
* @param {Awaited<ReturnType<makeVstorageKit>>} [optUtils]
*/
const processOffer = async function (
{ toOffer, sendFrom, keyringBackend },
optUtils,
) {
const utils = await (optUtils || makeRpcUtils({ fetch }, networkConfig));
const utils = await (optUtils || makeVstorageKit({ fetch }, networkConfig));
const { agoricNames, readLatestHead } = utils;

assert(keyringBackend, 'missing keyring-backend option');
Expand Down Expand Up @@ -265,7 +265,7 @@ export const makeGovCommand = (_logger, io = {}) => {
)
.requiredOption('--for <string>', 'description of the invitation')
.action(async opts => {
const { agoricNames, readLatestHead } = await makeRpcUtils(
const { agoricNames, readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down Expand Up @@ -294,7 +294,7 @@ export const makeGovCommand = (_logger, io = {}) => {
normalizeAddress,
)
.action(async opts => {
const { agoricNames, readLatestHead } = await makeRpcUtils(
const { agoricNames, readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down Expand Up @@ -333,7 +333,7 @@ export const makeGovCommand = (_logger, io = {}) => {
normalizeAddress,
)
.action(async function (opts, options) {
const utils = await makeRpcUtils({ fetch }, networkConfig);
const utils = await makeVstorageKit({ fetch }, networkConfig);
const { readLatestHead } = utils;

const info = await readLatestHead(
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 @@ -2,7 +2,7 @@
/* eslint-disable func-names */
/* eslint-env node */
import {
makeRpcUtils,
makeVstorageKit,
makeWalletUtils,
storageHelper,
} from '@agoric/client-utils';
Expand Down Expand Up @@ -87,7 +87,7 @@ export const makeOracleCommand = (logger, io = {}) => {
const rpcTools = async () => {
// XXX pass fetch to getNetworkConfig() explicitly
const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const utils = await makeRpcUtils({ fetch }, networkConfig);
const utils = await makeVstorageKit({ fetch }, networkConfig);

const lookupPriceAggregatorInstance = ([brandIn, brandOut]) => {
const name = oracleBrandFeedName(brandIn, brandOut);
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeRpcUtils, storageHelper } from '@agoric/client-utils';
import { makeVstorageKit, storageHelper } from '@agoric/client-utils';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { Command } from 'commander';
import { getNetworkConfig } from '../lib/network-config.js';
Expand Down Expand Up @@ -63,7 +63,7 @@ export const makePsmCommand = logger => {
);

const rpcTools = async () => {
const utils = await makeRpcUtils({ fetch }, networkConfig);
const utils = await makeVstorageKit({ fetch }, networkConfig);

const lookupPsmInstance = ([minted, anchor]) => {
const name = `psm-${minted}-${anchor}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/agoric-cli/src/commands/reserve.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeRpcUtils } from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { Command } from 'commander';
import { getNetworkConfig } from '../lib/network-config.js';
Expand Down Expand Up @@ -32,7 +32,7 @@ export const makeReserveCommand = (_logger, io = {}) => {
* }} opts
*/
async ({ collateralBrand, ...opts }) => {
const { agoricNames } = await makeRpcUtils({ fetch }, networkConfig);
const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig);

const offer = Offers.reserve.AddCollateral(agoricNames, {
collateralBrandKey: collateralBrand,
Expand Down Expand Up @@ -66,7 +66,7 @@ export const makeReserveCommand = (_logger, io = {}) => {
1,
)
.action(async function (opts) {
const { agoricNames } = await makeRpcUtils({ fetch }, networkConfig);
const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig);

const reserveInstance = agoricNames.instance.reserve;
assert(reserveInstance, 'missing reserve in names');
Expand Down
13 changes: 8 additions & 5 deletions packages/agoric-cli/src/commands/vaults.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeRpcUtils } from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';
import {
lookupOfferIdForVault,
Offers,
Expand Down Expand Up @@ -39,7 +39,10 @@ export const makeVaultsCommand = logger => {
normalizeAddress,
)
.action(async function (opts) {
const { readLatestHead } = await makeRpcUtils({ fetch }, networkConfig);
const { readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);

const current = await getCurrent(opts.from, {
readLatestHead,
Expand All @@ -64,7 +67,7 @@ export const makeVaultsCommand = logger => {
.option('--collateralBrand <string>', 'Collateral brand key', 'ATOM')
.action(async function (opts) {
logger.warn('running with options', opts);
const { agoricNames } = await makeRpcUtils({ fetch }, networkConfig);
const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig);

const offer = Offers.vaults.OpenVault(agoricNames, {
giveCollateral: opts.giveCollateral,
Expand Down Expand Up @@ -99,7 +102,7 @@ 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 makeRpcUtils(
const { agoricNames, readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down Expand Up @@ -143,7 +146,7 @@ export const makeVaultsCommand = logger => {
)
.action(async function (opts) {
logger.warn('running with options', opts);
const { agoricNames, readLatestHead } = await makeRpcUtils(
const { agoricNames, readLatestHead } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down
21 changes: 11 additions & 10 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
makeLeader,
makeLeaderFromRpcAddresses,
} from '@agoric/casting';
import { makeRpcUtils } from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';
import { execFileSync } from 'child_process';
import fs from 'fs';
import util from 'util';
Expand Down Expand Up @@ -105,7 +105,7 @@ export const makeWalletCommand = async command => {
.action(async function (opts) {
const offerStr = fs.readFileSync(opts.file).toString();

const { unserializer } = await makeRpcUtils({ fetch }, networkConfig);
const { unserializer } = await makeVstorageKit({ fetch }, networkConfig);

const offerObj = unserializer.fromCapData(JSON.parse(offerStr));
console.log(offerObj);
Expand All @@ -120,7 +120,7 @@ export const makeWalletCommand = async command => {
.action(async function (opts) {
const offerStr = fs.readFileSync(opts.offer).toString();

const { unserializer } = await makeRpcUtils({ fetch }, networkConfig);
const { unserializer } = await makeVstorageKit({ fetch }, networkConfig);

const offerObj = unserializer.fromCapData(JSON.parse(offerStr));
console.log(offerObj.offer.id);
Expand Down Expand Up @@ -158,7 +158,7 @@ export const makeWalletCommand = async command => {
.command('list')
.description('list all wallets in vstorage')
.action(async function () {
const { vstorage } = await makeRpcUtils({ fetch }, networkConfig);
const { vstorage } = await makeVstorageKit({ fetch }, networkConfig);
const wallets = await vstorage.keys('published.wallet');
process.stdout.write(wallets.join('\n'));
});
Expand All @@ -172,12 +172,13 @@ export const makeWalletCommand = async command => {
normalizeAddress,
)
.action(async function (opts) {
const { agoricNames, unserializer, readLatestHead } = await makeRpcUtils(
{
fetch,
},
networkConfig,
);
const { agoricNames, unserializer, readLatestHead } =
await makeVstorageKit(
{
fetch,
},
networkConfig,
);

const leader = makeLeader(networkConfig.rpcAddrs[0]);
const follower = await makeFollower(
Expand Down
1 change: 1 addition & 0 deletions packages/client-utils/src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './rpc.js';
export * from './sync-tools.js';
export * from './vstorage-kit.js';
export * from './wallet-utils.js';
Loading

0 comments on commit 71486d7

Please sign in to comment.