mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Allow creating higher level clients with a given Tendermint client
This commit is contained in:
parent
dd35029813
commit
7f8934cbe5
@ -39,6 +39,12 @@ and this project adheres to
|
|||||||
`Tendermint34Client` or `Tendermint37Client` and
|
`Tendermint34Client` or `Tendermint37Client` and
|
||||||
`isTendermint34Client`/`isTendermint37Client` to get the specific type
|
`isTendermint34Client`/`isTendermint37Client` to get the specific type
|
||||||
([#1376]).
|
([#1376]).
|
||||||
|
- @cosmjs/stargate: Add constructors `StargateClient.create` and
|
||||||
|
`SigningStargateClient.createWithSigner` to construct with a given Tendermint
|
||||||
|
client ([#1376]).
|
||||||
|
- @cosmjs/cosmwasm-stargate: Add constructors `CosmWasmClient.create` and
|
||||||
|
`SigningCosmWasmClient.createWithSigner` to construct with a given Tendermint
|
||||||
|
client ([#1376]).
|
||||||
|
|
||||||
[#1308]: https://github.com/cosmos/cosmjs/pull/1308
|
[#1308]: https://github.com/cosmos/cosmjs/pull/1308
|
||||||
[#1376]: https://github.com/cosmos/cosmjs/pull/1376
|
[#1376]: https://github.com/cosmos/cosmjs/pull/1376
|
||||||
|
@ -96,8 +96,22 @@ export class CosmWasmClient {
|
|||||||
private readonly codesCache = new Map<number, CodeDetails>();
|
private readonly codesCache = new Map<number, CodeDetails>();
|
||||||
private chainId: string | undefined;
|
private chainId: string | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance by connecting to the given Tendermint RPC endpoint.
|
||||||
|
*
|
||||||
|
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
|
||||||
|
* support, see `create`.
|
||||||
|
*/
|
||||||
public static async connect(endpoint: string | HttpEndpoint): Promise<CosmWasmClient> {
|
public static async connect(endpoint: string | HttpEndpoint): Promise<CosmWasmClient> {
|
||||||
const tmClient = await Tendermint34Client.connect(endpoint);
|
const tmClient = await Tendermint34Client.connect(endpoint);
|
||||||
|
return CosmWasmClient.create(tmClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
return new CosmWasmClient(tmClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,12 +183,30 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
|||||||
private readonly aminoTypes: AminoTypes;
|
private readonly aminoTypes: AminoTypes;
|
||||||
private readonly gasPrice: GasPrice | undefined;
|
private readonly gasPrice: GasPrice | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance by connecting to the given Tendermint RPC endpoint.
|
||||||
|
*
|
||||||
|
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
|
||||||
|
* support, see `createWithSigner`.
|
||||||
|
*/
|
||||||
public static async connectWithSigner(
|
public static async connectWithSigner(
|
||||||
endpoint: string | HttpEndpoint,
|
endpoint: string | HttpEndpoint,
|
||||||
signer: OfflineSigner,
|
signer: OfflineSigner,
|
||||||
options: SigningCosmWasmClientOptions = {},
|
options: SigningCosmWasmClientOptions = {},
|
||||||
): Promise<SigningCosmWasmClient> {
|
): Promise<SigningCosmWasmClient> {
|
||||||
const tmClient = await Tendermint34Client.connect(endpoint);
|
const tmClient = await Tendermint34Client.connect(endpoint);
|
||||||
|
return SigningCosmWasmClient.createWithSigner(tmClient, signer, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance from a manually created Tendermint client.
|
||||||
|
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
||||||
|
*/
|
||||||
|
public static async createWithSigner(
|
||||||
|
tmClient: TendermintClient,
|
||||||
|
signer: OfflineSigner,
|
||||||
|
options: SigningCosmWasmClientOptions = {},
|
||||||
|
): Promise<SigningCosmWasmClient> {
|
||||||
return new SigningCosmWasmClient(tmClient, signer, options);
|
return new SigningCosmWasmClient(tmClient, signer, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +114,30 @@ export class SigningStargateClient extends StargateClient {
|
|||||||
private readonly aminoTypes: AminoTypes;
|
private readonly aminoTypes: AminoTypes;
|
||||||
private readonly gasPrice: GasPrice | undefined;
|
private readonly gasPrice: GasPrice | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance by connecting to the given Tendermint RPC endpoint.
|
||||||
|
*
|
||||||
|
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
|
||||||
|
* support, see `createWithSigner`.
|
||||||
|
*/
|
||||||
public static async connectWithSigner(
|
public static async connectWithSigner(
|
||||||
endpoint: string | HttpEndpoint,
|
endpoint: string | HttpEndpoint,
|
||||||
signer: OfflineSigner,
|
signer: OfflineSigner,
|
||||||
options: SigningStargateClientOptions = {},
|
options: SigningStargateClientOptions = {},
|
||||||
): Promise<SigningStargateClient> {
|
): Promise<SigningStargateClient> {
|
||||||
const tmClient = await Tendermint34Client.connect(endpoint);
|
const tmClient = await Tendermint34Client.connect(endpoint);
|
||||||
|
return SigningStargateClient.createWithSigner(tmClient, signer, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance from a manually created Tendermint client.
|
||||||
|
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
||||||
|
*/
|
||||||
|
public static async createWithSigner(
|
||||||
|
tmClient: TendermintClient,
|
||||||
|
signer: OfflineSigner,
|
||||||
|
options: SigningStargateClientOptions = {},
|
||||||
|
): Promise<SigningStargateClient> {
|
||||||
return new SigningStargateClient(tmClient, signer, options);
|
return new SigningStargateClient(tmClient, signer, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,11 +191,28 @@ export class StargateClient {
|
|||||||
private chainId: string | undefined;
|
private chainId: string | undefined;
|
||||||
private readonly accountParser: AccountParser;
|
private readonly accountParser: AccountParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance by connecting to the given Tendermint RPC endpoint.
|
||||||
|
*
|
||||||
|
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
|
||||||
|
* support, see `create`.
|
||||||
|
*/
|
||||||
public static async connect(
|
public static async connect(
|
||||||
endpoint: string | HttpEndpoint,
|
endpoint: string | HttpEndpoint,
|
||||||
options: StargateClientOptions = {},
|
options: StargateClientOptions = {},
|
||||||
): Promise<StargateClient> {
|
): Promise<StargateClient> {
|
||||||
const tmClient = await Tendermint34Client.connect(endpoint);
|
const tmClient = await Tendermint34Client.connect(endpoint);
|
||||||
|
return StargateClient.create(tmClient, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance from a manually created Tendermint client.
|
||||||
|
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
||||||
|
*/
|
||||||
|
public static async create(
|
||||||
|
tmClient: TendermintClient,
|
||||||
|
options: StargateClientOptions = {},
|
||||||
|
): Promise<StargateClient> {
|
||||||
return new StargateClient(tmClient, options);
|
return new StargateClient(tmClient, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user