Use CometClient
This commit is contained in:
@@ -60,7 +60,7 @@ describe("CosmWasmClient", () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = await CosmWasmClient.connect(wasmd.endpoint);
|
||||
const openedClient = client as unknown as PrivateCosmWasmClient;
|
||||
const getCodeSpy = spyOn(openedClient.tmClient!, "status").and.callThrough();
|
||||
const getCodeSpy = spyOn(openedClient.cometClient!, "status").and.callThrough();
|
||||
|
||||
expect(await client.getChainId()).toEqual(wasmd.chainId); // from network
|
||||
expect(await client.getChainId()).toEqual(wasmd.chainId); // from cache
|
||||
|
||||
@@ -21,13 +21,7 @@ import {
|
||||
TimeoutError,
|
||||
TxExtension,
|
||||
} from "@cosmjs/stargate";
|
||||
import {
|
||||
HttpEndpoint,
|
||||
Tendermint34Client,
|
||||
Tendermint37Client,
|
||||
TendermintClient,
|
||||
toRfc3339WithNanoseconds,
|
||||
} from "@cosmjs/tendermint-rpc";
|
||||
import { CometClient, connectComet, HttpEndpoint, toRfc3339WithNanoseconds } from "@cosmjs/tendermint-rpc";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import { TxMsgData } from "cosmjs-types/cosmos/base/abci/v1beta1/abci";
|
||||
import {
|
||||
@@ -81,14 +75,14 @@ export interface ContractCodeHistoryEntry {
|
||||
|
||||
/** Use for testing only */
|
||||
export interface PrivateCosmWasmClient {
|
||||
readonly tmClient: TendermintClient | undefined;
|
||||
readonly cometClient: CometClient | undefined;
|
||||
readonly queryClient:
|
||||
| (QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension)
|
||||
| undefined;
|
||||
}
|
||||
|
||||
export class CosmWasmClient {
|
||||
private readonly tmClient: TendermintClient | undefined;
|
||||
private readonly cometClient: CometClient | undefined;
|
||||
private readonly queryClient:
|
||||
| (QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension)
|
||||
| undefined;
|
||||
@@ -102,34 +96,23 @@ export class CosmWasmClient {
|
||||
* To set the Tendermint client explicitly, use `create`.
|
||||
*/
|
||||
public static async connect(endpoint: string | HttpEndpoint): Promise<CosmWasmClient> {
|
||||
// Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉
|
||||
// Using 0.34 as the fallback.
|
||||
let tmClient: TendermintClient;
|
||||
const tm37Client = await Tendermint37Client.connect(endpoint);
|
||||
const version = (await tm37Client.status()).nodeInfo.version;
|
||||
if (version.startsWith("0.37.")) {
|
||||
tmClient = tm37Client;
|
||||
} else {
|
||||
tm37Client.disconnect();
|
||||
tmClient = await Tendermint34Client.connect(endpoint);
|
||||
}
|
||||
|
||||
return CosmWasmClient.create(tmClient);
|
||||
const cometClient = await connectComet(endpoint);
|
||||
return CosmWasmClient.create(cometClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance from a manually created Tendermint client.
|
||||
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
||||
*/
|
||||
public static async create(tmClient: TendermintClient): Promise<CosmWasmClient> {
|
||||
return new CosmWasmClient(tmClient);
|
||||
public static async create(cometClient: CometClient): Promise<CosmWasmClient> {
|
||||
return new CosmWasmClient(cometClient);
|
||||
}
|
||||
|
||||
protected constructor(tmClient: TendermintClient | undefined) {
|
||||
if (tmClient) {
|
||||
this.tmClient = tmClient;
|
||||
protected constructor(cometClient: CometClient | undefined) {
|
||||
if (cometClient) {
|
||||
this.cometClient = cometClient;
|
||||
this.queryClient = QueryClient.withExtensions(
|
||||
tmClient,
|
||||
cometClient,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupWasmExtension,
|
||||
@@ -138,17 +121,15 @@ export class CosmWasmClient {
|
||||
}
|
||||
}
|
||||
|
||||
protected getTmClient(): TendermintClient | undefined {
|
||||
return this.tmClient;
|
||||
protected getTmClient(): CometClient | undefined {
|
||||
return this.cometClient;
|
||||
}
|
||||
|
||||
protected forceGetTmClient(): TendermintClient {
|
||||
if (!this.tmClient) {
|
||||
throw new Error(
|
||||
"Tendermint client not available. You cannot use online functionality in offline mode.",
|
||||
);
|
||||
protected forceGetTmClient(): CometClient {
|
||||
if (!this.cometClient) {
|
||||
throw new Error("Comet client not available. You cannot use online functionality in offline mode.");
|
||||
}
|
||||
return this.tmClient;
|
||||
return this.cometClient;
|
||||
}
|
||||
|
||||
protected getQueryClient():
|
||||
@@ -244,7 +225,7 @@ export class CosmWasmClient {
|
||||
}
|
||||
|
||||
public disconnect(): void {
|
||||
if (this.tmClient) this.tmClient.disconnect();
|
||||
if (this.cometClient) this.cometClient.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,12 +31,7 @@ import {
|
||||
SignerData,
|
||||
StdFee,
|
||||
} from "@cosmjs/stargate";
|
||||
import {
|
||||
HttpEndpoint,
|
||||
Tendermint34Client,
|
||||
Tendermint37Client,
|
||||
TendermintClient,
|
||||
} from "@cosmjs/tendermint-rpc";
|
||||
import { CometClient, connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc";
|
||||
import { assert, assertDefined } from "@cosmjs/utils";
|
||||
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
@@ -196,19 +191,8 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
signer: OfflineSigner,
|
||||
options: SigningCosmWasmClientOptions = {},
|
||||
): Promise<SigningCosmWasmClient> {
|
||||
// Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉
|
||||
// Using 0.34 as the fallback.
|
||||
let tmClient: TendermintClient;
|
||||
const tm37Client = await Tendermint37Client.connect(endpoint);
|
||||
const version = (await tm37Client.status()).nodeInfo.version;
|
||||
if (version.startsWith("0.37.")) {
|
||||
tmClient = tm37Client;
|
||||
} else {
|
||||
tm37Client.disconnect();
|
||||
tmClient = await Tendermint34Client.connect(endpoint);
|
||||
}
|
||||
|
||||
return SigningCosmWasmClient.createWithSigner(tmClient, signer, options);
|
||||
const cometClient = await connectComet(endpoint);
|
||||
return SigningCosmWasmClient.createWithSigner(cometClient, signer, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,11 +200,11 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
||||
*/
|
||||
public static async createWithSigner(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
signer: OfflineSigner,
|
||||
options: SigningCosmWasmClientOptions = {},
|
||||
): Promise<SigningCosmWasmClient> {
|
||||
return new SigningCosmWasmClient(tmClient, signer, options);
|
||||
return new SigningCosmWasmClient(cometClient, signer, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,11 +224,11 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}
|
||||
|
||||
protected constructor(
|
||||
tmClient: TendermintClient | undefined,
|
||||
cometClient: CometClient | undefined,
|
||||
signer: OfflineSigner,
|
||||
options: SigningCosmWasmClientOptions,
|
||||
) {
|
||||
super(tmClient);
|
||||
super(cometClient);
|
||||
const {
|
||||
registry = new Registry([...defaultStargateTypes, ...wasmTypes]),
|
||||
aminoTypes = new AminoTypes({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { iavlSpec, ics23, tendermintSpec, verifyExistence, verifyNonExistence } from "@confio/ics23";
|
||||
import { toAscii, toHex } from "@cosmjs/encoding";
|
||||
import { firstEvent } from "@cosmjs/stream";
|
||||
import { tendermint34, TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
import { CometClient, tendermint34 } from "@cosmjs/tendermint-rpc";
|
||||
import { arrayContentEquals, assert, assertDefined, isNonNullObject, sleep } from "@cosmjs/utils";
|
||||
import { ProofOps } from "cosmjs-types/tendermint/crypto/proof";
|
||||
import { Stream } from "xstream";
|
||||
@@ -45,24 +45,24 @@ export interface QueryAbciResponse {
|
||||
|
||||
export class QueryClient {
|
||||
/** Constructs a QueryClient with 0 extensions */
|
||||
public static withExtensions(tmClient: TendermintClient): QueryClient;
|
||||
public static withExtensions(cometClient: CometClient): QueryClient;
|
||||
|
||||
/** Constructs a QueryClient with 1 extension */
|
||||
public static withExtensions<A extends object>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
): QueryClient & A;
|
||||
|
||||
/** Constructs a QueryClient with 2 extensions */
|
||||
public static withExtensions<A extends object, B extends object>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
): QueryClient & A & B;
|
||||
|
||||
/** Constructs a QueryClient with 3 extensions */
|
||||
public static withExtensions<A extends object, B extends object, C extends object>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -70,7 +70,7 @@ export class QueryClient {
|
||||
|
||||
/** Constructs a QueryClient with 4 extensions */
|
||||
public static withExtensions<A extends object, B extends object, C extends object, D extends object>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -85,7 +85,7 @@ export class QueryClient {
|
||||
D extends object,
|
||||
E extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -102,7 +102,7 @@ export class QueryClient {
|
||||
E extends object,
|
||||
F extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -121,7 +121,7 @@ export class QueryClient {
|
||||
F extends object,
|
||||
G extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -142,7 +142,7 @@ export class QueryClient {
|
||||
G extends object,
|
||||
H extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -165,7 +165,7 @@ export class QueryClient {
|
||||
H extends object,
|
||||
I extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -190,7 +190,7 @@ export class QueryClient {
|
||||
I extends object,
|
||||
J extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -217,7 +217,7 @@ export class QueryClient {
|
||||
J extends object,
|
||||
K extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -246,7 +246,7 @@ export class QueryClient {
|
||||
K extends object,
|
||||
L extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -277,7 +277,7 @@ export class QueryClient {
|
||||
L extends object,
|
||||
M extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -310,7 +310,7 @@ export class QueryClient {
|
||||
M extends object,
|
||||
N extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -345,7 +345,7 @@ export class QueryClient {
|
||||
N extends object,
|
||||
O extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -382,7 +382,7 @@ export class QueryClient {
|
||||
O extends object,
|
||||
P extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -421,7 +421,7 @@ export class QueryClient {
|
||||
P extends object,
|
||||
Q extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -462,7 +462,7 @@ export class QueryClient {
|
||||
Q extends object,
|
||||
R extends object,
|
||||
>(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
setupExtensionA: QueryExtensionSetup<A>,
|
||||
setupExtensionB: QueryExtensionSetup<B>,
|
||||
setupExtensionC: QueryExtensionSetup<C>,
|
||||
@@ -484,10 +484,10 @@ export class QueryClient {
|
||||
): QueryClient & A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q & R;
|
||||
|
||||
public static withExtensions(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
...extensionSetups: Array<QueryExtensionSetup<object>>
|
||||
): any {
|
||||
const client = new QueryClient(tmClient);
|
||||
const client = new QueryClient(cometClient);
|
||||
const extensions = extensionSetups.map((setupExtension) => setupExtension(client));
|
||||
for (const extension of extensions) {
|
||||
assert(isNonNullObject(extension), `Extension must be a non-null object`);
|
||||
@@ -506,10 +506,10 @@ export class QueryClient {
|
||||
return client;
|
||||
}
|
||||
|
||||
private readonly tmClient: TendermintClient;
|
||||
private readonly cometClient: CometClient;
|
||||
|
||||
public constructor(tmClient: TendermintClient) {
|
||||
this.tmClient = tmClient;
|
||||
public constructor(cometClient: CometClient) {
|
||||
this.cometClient = cometClient;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -557,7 +557,7 @@ export class QueryClient {
|
||||
queryKey: Uint8Array,
|
||||
desiredHeight?: number,
|
||||
): Promise<ProvenQuery> {
|
||||
const { key, value, height, proof, code, log } = await this.tmClient.abciQuery({
|
||||
const { key, value, height, proof, code, log } = await this.cometClient.abciQuery({
|
||||
// we need the StoreKey for the module, not the module name
|
||||
// https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L12
|
||||
path: `/store/${store}/key`,
|
||||
@@ -608,7 +608,7 @@ export class QueryClient {
|
||||
request: Uint8Array,
|
||||
desiredHeight?: number,
|
||||
): Promise<QueryAbciResponse> {
|
||||
const response = await this.tmClient.abciQuery({
|
||||
const response = await this.cometClient.abciQuery({
|
||||
path: path,
|
||||
data: request,
|
||||
prove: false,
|
||||
@@ -641,7 +641,7 @@ export class QueryClient {
|
||||
let nextHeader: tendermint34.Header | undefined;
|
||||
let headersSubscription: Stream<tendermint34.NewBlockHeaderEvent> | undefined;
|
||||
try {
|
||||
headersSubscription = this.tmClient.subscribeNewBlockHeader();
|
||||
headersSubscription = this.cometClient.subscribeNewBlockHeader();
|
||||
} catch {
|
||||
// Ignore exception caused by non-WebSocket Tendermint clients
|
||||
}
|
||||
@@ -656,7 +656,7 @@ export class QueryClient {
|
||||
|
||||
while (!nextHeader) {
|
||||
// start from current height to avoid backend error for minHeight in the future
|
||||
const correctHeader = (await this.tmClient.blockchain(height, searchHeight)).blockMetas
|
||||
const correctHeader = (await this.cometClient.blockchain(height, searchHeight)).blockMetas
|
||||
.map((meta) => meta.header)
|
||||
.find((h) => h.height === searchHeight);
|
||||
if (correctHeader) {
|
||||
|
||||
@@ -98,7 +98,7 @@ describe("StargateClient", () => {
|
||||
pendingWithoutSimapp();
|
||||
const client = await StargateClient.connect(simapp.tendermintUrl);
|
||||
const openedClient = client as unknown as PrivateStargateClient;
|
||||
const getCodeSpy = spyOn(openedClient.tmClient!, "status").and.callThrough();
|
||||
const getCodeSpy = spyOn(openedClient.cometClient!, "status").and.callThrough();
|
||||
|
||||
expect(await client.getChainId()).toEqual(simapp.chainId); // from network
|
||||
expect(await client.getChainId()).toEqual(simapp.chainId); // from cache
|
||||
|
||||
@@ -2,13 +2,7 @@
|
||||
import { addCoins } from "@cosmjs/amino";
|
||||
import { toHex } from "@cosmjs/encoding";
|
||||
import { Uint53 } from "@cosmjs/math";
|
||||
import {
|
||||
HttpEndpoint,
|
||||
Tendermint34Client,
|
||||
Tendermint37Client,
|
||||
TendermintClient,
|
||||
toRfc3339WithNanoseconds,
|
||||
} from "@cosmjs/tendermint-rpc";
|
||||
import { CometClient, connectComet, HttpEndpoint, toRfc3339WithNanoseconds } from "@cosmjs/tendermint-rpc";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import { MsgData, TxMsgData } from "cosmjs-types/cosmos/base/abci/v1beta1/abci";
|
||||
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
||||
@@ -188,7 +182,7 @@ export class BroadcastTxError extends Error {
|
||||
|
||||
/** Use for testing only */
|
||||
export interface PrivateStargateClient {
|
||||
readonly tmClient: TendermintClient | undefined;
|
||||
readonly cometClient: CometClient | undefined;
|
||||
}
|
||||
|
||||
export interface StargateClientOptions {
|
||||
@@ -196,7 +190,7 @@ export interface StargateClientOptions {
|
||||
}
|
||||
|
||||
export class StargateClient {
|
||||
private readonly tmClient: TendermintClient | undefined;
|
||||
private readonly cometClient: CometClient | undefined;
|
||||
private readonly queryClient:
|
||||
| (QueryClient & AuthExtension & BankExtension & StakingExtension & TxExtension)
|
||||
| undefined;
|
||||
@@ -213,19 +207,8 @@ export class StargateClient {
|
||||
endpoint: string | HttpEndpoint,
|
||||
options: StargateClientOptions = {},
|
||||
): Promise<StargateClient> {
|
||||
// Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉
|
||||
// Using 0.34 as the fallback.
|
||||
let tmClient: TendermintClient;
|
||||
const tm37Client = await Tendermint37Client.connect(endpoint);
|
||||
const version = (await tm37Client.status()).nodeInfo.version;
|
||||
if (version.startsWith("0.37.")) {
|
||||
tmClient = tm37Client;
|
||||
} else {
|
||||
tm37Client.disconnect();
|
||||
tmClient = await Tendermint34Client.connect(endpoint);
|
||||
}
|
||||
|
||||
return StargateClient.create(tmClient, options);
|
||||
const cometClient = await connectComet(endpoint);
|
||||
return StargateClient.create(cometClient, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,17 +216,17 @@ export class StargateClient {
|
||||
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
||||
*/
|
||||
public static async create(
|
||||
tmClient: TendermintClient,
|
||||
cometClient: CometClient,
|
||||
options: StargateClientOptions = {},
|
||||
): Promise<StargateClient> {
|
||||
return new StargateClient(tmClient, options);
|
||||
return new StargateClient(cometClient, options);
|
||||
}
|
||||
|
||||
protected constructor(tmClient: TendermintClient | undefined, options: StargateClientOptions) {
|
||||
if (tmClient) {
|
||||
this.tmClient = tmClient;
|
||||
protected constructor(cometClient: CometClient | undefined, options: StargateClientOptions) {
|
||||
if (cometClient) {
|
||||
this.cometClient = cometClient;
|
||||
this.queryClient = QueryClient.withExtensions(
|
||||
tmClient,
|
||||
cometClient,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupStakingExtension,
|
||||
@@ -254,17 +237,15 @@ export class StargateClient {
|
||||
this.accountParser = accountParser;
|
||||
}
|
||||
|
||||
protected getTmClient(): TendermintClient | undefined {
|
||||
return this.tmClient;
|
||||
protected getTmClient(): CometClient | undefined {
|
||||
return this.cometClient;
|
||||
}
|
||||
|
||||
protected forceGetTmClient(): TendermintClient {
|
||||
if (!this.tmClient) {
|
||||
throw new Error(
|
||||
"Tendermint client not available. You cannot use online functionality in offline mode.",
|
||||
);
|
||||
protected forceGetTmClient(): CometClient {
|
||||
if (!this.cometClient) {
|
||||
throw new Error("Comet client not available. You cannot use online functionality in offline mode.");
|
||||
}
|
||||
return this.tmClient;
|
||||
return this.cometClient;
|
||||
}
|
||||
|
||||
protected getQueryClient():
|
||||
@@ -414,7 +395,7 @@ export class StargateClient {
|
||||
}
|
||||
|
||||
public disconnect(): void {
|
||||
if (this.tmClient) this.tmClient.disconnect();
|
||||
if (this.cometClient) this.cometClient.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user