Skip to content

Commit 860354f

Browse files
author
Fabrice Bascoulergue
committed
Add missing common calls implementation
1 parent a5941e2 commit 860354f

File tree

2 files changed

+109
-11
lines changed

2 files changed

+109
-11
lines changed

docs/lib/classes/lumclient.md

+64-7
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
- [disconnect](lumclient.md#disconnect)
1919
- [getAccount](lumclient.md#getaccount)
2020
- [getAccountUnverified](lumclient.md#getaccountunverified)
21+
- [getAllBalancesUnverified](lumclient.md#getallbalancesunverified)
22+
- [getAllSupplies](lumclient.md#getallsupplies)
2123
- [getBalance](lumclient.md#getbalance)
22-
- [getBalancesUnverified](lumclient.md#getbalancesunverified)
24+
- [getBalanceUnverified](lumclient.md#getbalanceunverified)
2325
- [getBlock](lumclient.md#getblock)
2426
- [getBlockHeight](lumclient.md#getblockheight)
2527
- [getChainId](lumclient.md#getchainid)
28+
- [getSupply](lumclient.md#getsupply)
2629
- [getTx](lumclient.md#gettx)
2730
- [getValidators](lumclient.md#getvalidators)
2831
- [searchTx](lumclient.md#searchtx)
2932
- [signAndBroadcastTx](lumclient.md#signandbroadcasttx)
3033
- [signTx](lumclient.md#signtx)
34+
- [status](lumclient.md#status)
3135
- [txsQuery](lumclient.md#txsquery)
3236
- [connect](lumclient.md#connect)
3337

@@ -57,7 +61,7 @@ ___
5761

5862
### queryClient
5963

60-
`Readonly` **queryClient**: *QueryClient* & AuthExtension & BankExtension
64+
`Readonly` **queryClient**: *QueryClient* & AuthExtension & BankExtension & DistributionExtension & StakingExtension
6165

6266
___
6367

@@ -126,6 +130,32 @@ Name | Type | Description |
126130

127131
___
128132

133+
### getAllBalancesUnverified
134+
135+
**getAllBalancesUnverified**(`address`: *string*): *Promise*<[*Coin*](../interfaces/lumtypes.coin.md)[]\>
136+
137+
Get all account balances without verifying their existence
138+
139+
#### Parameters:
140+
141+
Name | Type | Description |
142+
:------ | :------ | :------ |
143+
`address` | *string* | wallet address |
144+
145+
**Returns:** *Promise*<[*Coin*](../interfaces/lumtypes.coin.md)[]\>
146+
147+
___
148+
149+
### getAllSupplies
150+
151+
**getAllSupplies**(): *Promise*<[*Coin*](../interfaces/lumtypes.coin.md)[]\>
152+
153+
Get all coins supplies
154+
155+
**Returns:** *Promise*<[*Coin*](../interfaces/lumtypes.coin.md)[]\>
156+
157+
___
158+
129159
### getBalance
130160

131161
**getBalance**(`address`: *string*, `searchDenom`: *string*): *Promise*<*null* \| [*Coin*](../interfaces/lumtypes.coin.md)\>
@@ -143,19 +173,20 @@ Name | Type | Description |
143173

144174
___
145175

146-
### getBalancesUnverified
176+
### getBalanceUnverified
147177

148-
**getBalancesUnverified**(`address`: *string*): *Promise*<[*Coin*](../interfaces/lumtypes.coin.md)[]\>
178+
**getBalanceUnverified**(`address`: *string*, `searchDenom`: *string*): *Promise*<*null* \| [*Coin*](../interfaces/lumtypes.coin.md)\>
149179

150-
Get all account balances without verifying their existence
180+
Get an account balance without verifying their existence
151181

152182
#### Parameters:
153183

154184
Name | Type | Description |
155185
:------ | :------ | :------ |
156-
`address` | *string* | wallet address |
186+
`address` | *string* | wallet address |
187+
`searchDenom` | *string* | Coin denomination (ex: lum) |
157188

158-
**Returns:** *Promise*<[*Coin*](../interfaces/lumtypes.coin.md)[]\>
189+
**Returns:** *Promise*<*null* \| [*Coin*](../interfaces/lumtypes.coin.md)\>
159190

160191
___
161192

@@ -195,6 +226,22 @@ Get the chain id
195226

196227
___
197228

229+
### getSupply
230+
231+
**getSupply**(`searchDenom`: *string*): *Promise*<*null* \| [*Coin*](../interfaces/lumtypes.coin.md)\>
232+
233+
Get coin supply
234+
235+
#### Parameters:
236+
237+
Name | Type | Description |
238+
:------ | :------ | :------ |
239+
`searchDenom` | *string* | Coin denomination (ex: lum) |
240+
241+
**Returns:** *Promise*<*null* \| [*Coin*](../interfaces/lumtypes.coin.md)\>
242+
243+
___
244+
198245
### getTx
199246

200247
**getTx**(`hash`: *Uint8Array*, `includeProof?`: *boolean*): *Promise*<*null* \| TxResponse\>
@@ -292,6 +339,16 @@ Name | Type | Description |
292339

293340
___
294341

342+
### status
343+
344+
**status**(): *Promise*<StatusResponse\>
345+
346+
Get the connected node status information
347+
348+
**Returns:** *Promise*<StatusResponse\>
349+
350+
___
351+
295352
### txsQuery
296353

297354
`Private`**txsQuery**(`params`: TxSearchParams): *Promise*<TxResponse[]\>

src/client/LumClient.ts

+45-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Uint64 } from '@cosmjs/math';
2-
import { Client as TendermintClient, adaptor34 as TendermintAdaptor } from '@cosmjs/tendermint-rpc';
2+
import { Client as TendermintClient, adaptor34 as TendermintAdaptor, StatusResponse } from '@cosmjs/tendermint-rpc';
33
import {
44
QueryClient as StargateQueryClient,
55
setupAuthExtension as StargateSetupAuthExtension,
66
setupBankExtension as StargateSetupBankExtension,
7+
setupDistributionExtension as StargateDistributionExtension,
8+
setupStakingExtension as StargateStakingExtension,
79
coinFromProto,
810
AuthExtension,
911
BankExtension,
12+
StakingExtension,
13+
DistributionExtension,
1014
} from '@cosmjs/stargate';
1115

1216
import { LumWallet } from '../wallet';
@@ -16,7 +20,7 @@ import { BroadcastTxCommitResponse, ValidatorsResponse, TxResponse, TxSearchPara
1620

1721
export class LumClient {
1822
readonly tmClient: TendermintClient;
19-
readonly queryClient: StargateQueryClient & AuthExtension & BankExtension;
23+
readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & DistributionExtension & StakingExtension;
2024
private chainId?: string;
2125

2226
/**
@@ -26,7 +30,7 @@ export class LumClient {
2630
*/
2731
constructor(tmClient: TendermintClient) {
2832
this.tmClient = tmClient;
29-
this.queryClient = StargateQueryClient.withExtensions(tmClient, StargateSetupAuthExtension, StargateSetupBankExtension);
33+
this.queryClient = StargateQueryClient.withExtensions(tmClient, StargateSetupAuthExtension, StargateSetupBankExtension, StargateDistributionExtension, StargateStakingExtension);
3034
}
3135

3236
/**
@@ -47,6 +51,14 @@ export class LumClient {
4751
this.tmClient.disconnect();
4852
}
4953

54+
/**
55+
* Get the connected node status information
56+
*/
57+
status = async (): Promise<StatusResponse> => {
58+
const status = await this.tmClient.status();
59+
return status;
60+
};
61+
5062
/**
5163
* Get the chain id
5264
*/
@@ -125,16 +137,45 @@ export class LumClient {
125137
return balance ? coinFromProto(balance) : null;
126138
};
127139

140+
/**
141+
* Get an account balance without verifying their existence
142+
*
143+
* @param address wallet address
144+
* @param searchDenom Coin denomination (ex: lum)
145+
*/
146+
getBalanceUnverified = async (address: string, searchDenom: string): Promise<Coin | null> => {
147+
const balance = await this.queryClient.bank.unverified.balance(address, searchDenom);
148+
return balance ? coinFromProto(balance) : null;
149+
};
150+
128151
/**
129152
* Get all account balances without verifying their existence
130153
*
131154
* @param address wallet address
132155
*/
133-
getBalancesUnverified = async (address: string): Promise<Coin[]> => {
156+
getAllBalancesUnverified = async (address: string): Promise<Coin[]> => {
134157
const balances = await this.queryClient.bank.unverified.allBalances(address);
135158
return balances.map(coinFromProto);
136159
};
137160

161+
/**
162+
* Get coin supply
163+
*
164+
* @param searchDenom Coin denomination (ex: lum)
165+
*/
166+
getSupply = async (searchDenom: string): Promise<Coin | null> => {
167+
const supply = await this.queryClient.bank.unverified.supplyOf(searchDenom);
168+
return supply ? coinFromProto(supply) : null;
169+
};
170+
171+
/**
172+
* Get all coins supplies
173+
*/
174+
getAllSupplies = async (): Promise<Coin[]> => {
175+
const supplies = await this.queryClient.bank.unverified.totalSupply();
176+
return supplies.map(coinFromProto);
177+
};
178+
138179
/**
139180
* Get all validators
140181
* Validators are sorted first by voting power (descending), then by address (ascending)

0 commit comments

Comments
 (0)