Skip to content

Commit

Permalink
refactor: back to cosmic-proto without RPC
Browse files Browse the repository at this point in the history
This reverts commit 5f19df9.
  • Loading branch information
turadg committed Apr 5, 2024
1 parent e37b916 commit 25790ee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
11 changes: 5 additions & 6 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,23 @@ export const makeWalletCommand = async command => {
)
.option('--spend', 'confirm you want to spend')
.option('--nickname <string>', 'nickname to use', 'my-wallet')
.action(async function (opts) {
.action(function (opts) {
const { account, nickname, spend } = opts;
const { home, keyringBackend: backend } = wallet.opts();
const tx = ['provision-one', nickname, account, 'SMART_WALLET'];
await null;
if (spend) {
execSwingsetTransaction(tx, {
from: account,
keyring: { home, backend },
...networkConfig,
});
} else {
const params = await fetchSwingsetParams(networkConfig);
const params = fetchSwingsetParams(networkConfig);
assert(
params.powerFlagFees.length === 1,
'multiple powerFlagFees not supported',
params.power_flag_fees.length === 1,
'multiple power_flag_fees not supported',
);
const { fee: fees } = params.powerFlagFees[0];
const { fee: fees } = params.power_flag_fees[0];
const nf = new Intl.NumberFormat('en-US');
const costs = fees
.map(f => `${nf.format(Number(f.amount))} ${f.denom}`)
Expand Down
24 changes: 14 additions & 10 deletions packages/agoric-cli/src/lib/chain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
/* global process */
import { agoric } from '@agoric/cosmic-proto';
import { normalizeBech32 } from '@cosmjs/encoding';
import { execFileSync as execFileSyncAmbient } from 'child_process';

Expand Down Expand Up @@ -96,16 +95,21 @@ harden(execSwingsetTransaction);
/**
*
* @param {import('./rpc.js').MinimalNetworkConfig} net
* @returns {Promise<import('@agoric/cosmic-proto/swingset/swingset.js').Params>}
*/
export const fetchSwingsetParams = async net => {
const { rpcAddrs } = net;
const rpcEndpoint = rpcAddrs[0];
const client = await agoric.ClientFactory.createRPCQueryClient({
rpcEndpoint,
});
const { params } = await client.agoric.swingset.params();
return params;
// TODO fetch by HTTP instead of shelling out https://github.com/Agoric/agoric-sdk/issues/9200
export const fetchSwingsetParams = net => {
const { chainName, rpcAddrs } = net;
const cmd = [
`--node=${rpcAddrs[0]}`,
`--chain-id=${chainName}`,
'query',
'swingset',
'params',
'--output',
'--json',
];
const buffer = execFileSyncAmbient(agdBinary, cmd);
return JSON.parse(buffer.toString());
};
harden(fetchSwingsetParams);

Expand Down
14 changes: 11 additions & 3 deletions packages/agoric-cli/src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
makeLeaderFromRpcAddresses,
makeCastingSpec,
} from '@agoric/casting';
import { getSigningAgoricClientOptions } from '@agoric/cosmic-proto';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { DirectSecp256k1HdWallet, Registry } from '@cosmjs/proto-signing';
import { defaultRegistryTypes } from '@cosmjs/stargate';
import { stringToPath } from '@cosmjs/crypto';
import { Decimal } from '@cosmjs/math';
import { fromBech32 } from '@cosmjs/encoding';

import { MsgInstallBundle } from '@agoric/cosmic-proto/swingset/msgs.js';

// https://github.com/Agoric/agoric-sdk/blob/master/golang/cosmos/daemon/main.go
const Agoric = {
Bech32MainPrefix: 'agoric',
Expand All @@ -36,6 +38,12 @@ const Agoric = {
const hdPath = (coinType = 118, account = 0) =>
stringToPath(`m/44'/${coinType}'/${account}'/0/0`);

// @ts-expect-error difference in private property _push
const registry = new Registry([
...defaultRegistryTypes,
[Agoric.proto.swingset.InstallBundle.typeUrl, MsgInstallBundle],
]);

/**
* @typedef {object} JsonHttpRequest
* @property {string} hostname
Expand Down Expand Up @@ -281,8 +289,8 @@ export const makeCosmosBundlePublisher = ({

// AWAIT
const stargateClient = await connectWithSigner(endpoint, wallet, {
...getSigningAgoricClientOptions(),
gasPrice: Agoric.gasPrice,
registry,
});

// AWAIT
Expand Down
21 changes: 13 additions & 8 deletions packages/casting/test/test-interpose-net-access.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// @ts-check
/* global globalThis */
import { QueryClient, setupBankExtension } from '@cosmjs/stargate';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import anyTest from 'ava';
import {
createProtobufRpcClient,
QueryClient,
setupBankExtension,
} from '@cosmjs/stargate';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
// import { QueryClientImpl } from '@agoric/cosmic-proto/vstorage/query.js';

import { agoric } from '@agoric/cosmic-proto';
import { makeHttpClient } from '../src/makeHttpClient.js';
import { captureIO, replayIO, web1, web2 } from './net-access-fixture.js';

Expand Down Expand Up @@ -69,21 +73,22 @@ const scenario2 = {
],
};

test(`vstorage query: Children (RECORDING: ${RECORDING})`, async t => {
test.failing(`vstorage query: Children (RECORDING: ${RECORDING})`, async t => {
const { context: io } = t;

const { fetch: fetchMock, web } = io.recording
? captureIO(io.fetch)
: { fetch: replayIO(web2), web: new Map() };
const rpcClient = makeHttpClient(scenario2.endpoint, fetchMock);

t.is(agoric.vstorage.Children.typeUrl, '/agoric.vstorage.Children');

const tmClient = await Tendermint34Client.create(rpcClient);
const qClient = new QueryClient(tmClient);
const queryService = agoric.vstorage.createRpcQueryExtension(qClient);
const rpc = createProtobufRpcClient(qClient);
// @ts-expect-error -- XXX
// eslint-disable-next-line no-undef -- XXX
const queryService = new QueryClientImpl(rpc);

const children = await queryService.children({ path: '' });
const children = await queryService.Children({ path: '' });
if (io.recording) {
t.snapshot(web);
}
Expand Down

0 comments on commit 25790ee

Please sign in to comment.