-
Notifications
You must be signed in to change notification settings - Fork 22
/
BankAPI.ts
113 lines (103 loc) 路 3.14 KB
/
BankAPI.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { BaseAPI } from './BaseAPI';
import { Coins, Coin, AccAddress } from '../../../core';
import { APIParams, Pagination, PaginationOptions } from '../APIRequester';
import { LCDClient } from '../LCDClient';
export interface SendEnabled {
denom: string;
enabled: boolean;
}
export namespace SendEnabled {
export interface Data {
denom: string;
enabled: boolean;
}
}
export interface BankParams {
send_enabled: SendEnabled[];
default_send_enabled: boolean;
}
export namespace BankParams {
export interface Data {
send_enabled: SendEnabled.Data[];
default_send_enabled: boolean;
}
}
export class BankAPI extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequesters, lcd.config);
}
/**
* Query parameters of the bank module,
* @param chainID chain id
* @returns params of the bank module
*/
public async params(
chainID: string,
params: APIParams = {}
): Promise<BankParams> {
return this.getReqFromChainID(chainID)
.get<{ params: BankParams.Data }>(`/cosmos/bank/v1beta1/params`, params)
.then(({ params: d }) => ({
send_enabled: d.send_enabled,
default_send_enabled: d.default_send_enabled,
}));
}
/**
* Look up the balance of an account by its address.
* @param address address of account to look up.
*/
public async balance(
address: AccAddress,
params: Partial<PaginationOptions & APIParams> = {}
): Promise<[Coins, Pagination]> {
return this.getReqFromAddress(address)
.get<{
balances: Coins.Data;
pagination: Pagination;
}>(`/cosmos/bank/v1beta1/balances/${address}`, params)
.then(d => [Coins.fromData(d.balances), d.pagination]);
}
/**
* Lqueries the spenable balance of all coins for a single account.
* @param address address of account to look up.
*/
public async spendableBalances(
address: AccAddress,
params: Partial<PaginationOptions & APIParams> = {}
): Promise<[Coins, Pagination]> {
return this.getReqFromAddress(address)
.get<{
balances: Coins.Data;
pagination: Pagination;
}>(`/cosmos/bank/v1beta1/spendable_balances/${address}`, params)
.then(d => [Coins.fromData(d.balances), d.pagination]);
}
/**
* Get the total supply of tokens in circulation for all denominations.
* @param chainID chain id
*/
public async total(
chainID: string,
params: Partial<PaginationOptions & APIParams> = {}
): Promise<[Coins, Pagination]> {
return this.getReqFromChainID(chainID)
.get<{ supply: Coins.Data; pagination: Pagination }>(
`/cosmos/bank/v1beta1/supply`,
params
)
.then(d => [Coins.fromData(d.supply), d.pagination]);
}
/**
* Get the total supply of tokens in circulation for all denom.
* @param chainID chain id
* @param denom denom of the coin
*/
public async supplyByDenom(chainID: string, denom: string): Promise<Coin> {
return this.getReqFromChainID(chainID)
.get<{ amount: Coin.Data }>(`/cosmos/bank/v1beta1/supply/by_denom`, {
denom: denom,
})
.then(d => Coin.fromData(d.amount));
}
// TODO: TBD: implement denoms_medata?
}