Skip to content

Commit

Permalink
feat: ocap makeStargateClient
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 6, 2024
1 parent 129516a commit c8f7407
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/client-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
"ts-blank-space": "^0.4.1"
},
"dependencies": {
"@agoric/casting": "^0.4.2",
"@agoric/ertp": "^0.16.2",
"@agoric/internal": "^0.3.2",
"@agoric/smart-wallet": "^0.5.3",
"@agoric/vats": "^0.15.1",
"@cosmjs/stargate": "^0.32.3",
"@cosmjs/tendermint-rpc": "^0.32.3",
"@endo/common": "^1.2.7",
"@endo/errors": "^1.2.7",
"@endo/marshal": "^1.6.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/client-utils/src/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
*/

import { StargateClient } from '@cosmjs/stargate';
import { pickEndpoint } from './rpc.js';
import { makeTendermint34Client, pickEndpoint } from './rpc.js';

/**
* @param {MinimalNetworkConfig} config
* @param {{ fetch: typeof window.fetch }} io
* @returns {Promise<StargateClient>}
*/
export const makeStargateClient = config =>
StargateClient.connect(pickEndpoint(config));
export const makeStargateClient = async (config, { fetch }) => {
const url = pickEndpoint(config);
const tm = await makeTendermint34Client(url, { fetch });
return StargateClient.create(tm);
};

/**
* @param {{
Expand Down
12 changes: 12 additions & 0 deletions packages/client-utils/src/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
boardSlottingMarshaller,
makeBoardRemote,
} from '@agoric/vats/tools/board-utils.js';
import { makeTendermintRpcClient } from '@agoric/casting';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';

export { boardSlottingMarshaller };

Expand Down Expand Up @@ -246,3 +248,13 @@ export const makeRpcUtils = async ({ fetch }, config) => {
}
};
/** @typedef {Awaited<ReturnType<typeof makeRpcUtils>>} RpcUtils */

/**
* @param {string} endpoint
* @param {{ fetch: typeof window.fetch }} io
* @returns {Promise<Tendermint34Client>}
*/
export const makeTendermint34Client = (endpoint, { fetch }) => {
const rpcClient = makeTendermintRpcClient(endpoint, fetch);
return Tendermint34Client.create(rpcClient);
};
2 changes: 1 addition & 1 deletion packages/client-utils/src/wallet-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const makeWalletUtils = async ({ fetch, delay }, networkConfig) => {
await makeRpcUtils({ fetch }, networkConfig);
const m = boardSlottingMarshaller(fromBoard.convertSlotToVal);

const client = await makeStargateClient(networkConfig);
const client = await makeStargateClient(networkConfig, { fetch });

/**
* @param {string} from
Expand Down

0 comments on commit c8f7407

Please sign in to comment.