-
Notifications
You must be signed in to change notification settings - Fork 22
/
AuthAPI.ts
105 lines (98 loc) 路 3.17 KB
/
AuthAPI.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
import {
AccAddress,
Account,
LazyGradedVestingAccount,
DelayedVestingAccount,
PeriodicVestingAccount,
ContinuousVestingAccount,
BaseAccount,
ModuleAccount,
} from '../../../core';
import { BaseAPI } from './BaseAPI';
import { APIParams } from '../APIRequester';
import { LCDClient } from '../LCDClient';
export interface AuthParams {
max_memo_characters: number;
tx_sig_limit: number;
tx_size_cost_per_byte: number;
sig_verify_cost_ed25519: number;
sig_verify_cost_secp256k1: number;
}
export namespace AuthParams {
export interface Data {
max_memo_characters: string;
tx_sig_limit: string;
tx_size_cost_per_byte: string;
sig_verify_cost_ed25519: string;
sig_verify_cost_secp256k1: string;
}
}
export class AuthAPI extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequesters, lcd.config);
}
/**
* Query the modules acccounts information
*
* @param address address of account to look up
*/
public async moduleAccountsInfo(
chainID: string,
params: APIParams = {}
): Promise<Array<ModuleAccount>> {
const { accounts } = await this.getReqFromChainID(chainID).get<{
accounts: Array<ModuleAccount.Data>;
}>(`/cosmos/auth/v1beta1/module_accounts`, params);
return accounts.map((account: any) => ModuleAccount.fromData(account));
}
/**
* Query a specific module acccount information
*
* @param address address of account to look up
*/
public async moduleAccountInfo(
chainID: string,
moduleName: string,
params: APIParams = {}
): Promise<ModuleAccount> {
const { account } = await this.getReqFromChainID(chainID).get<{
account: ModuleAccount.Data;
}>(`/cosmos/auth/v1beta1/module_accounts/${moduleName}`, params);
return ModuleAccount.fromData(account);
}
/**
* Looks up the account information using its Terra account address. If the account has
* vesting, it will be one of [LazyGradedVestingAccount, DelayedVestingAccount, PeriodicVestingAccount, ContinuousVestingAccount]
*
* @param address address of account to look up
*/
public async accountInfo(
address: AccAddress,
params: APIParams = {}
): Promise<Account> {
const { account } = await this.getReqFromAddress(address).get<{
account:
| BaseAccount.Data
| LazyGradedVestingAccount.Data
| DelayedVestingAccount.Data
| PeriodicVestingAccount.Data
| ContinuousVestingAccount.Data
| BaseAccount.Data;
}>(`/cosmos/auth/v1beta1/accounts/${address}`, params);
return Account.fromData(account);
}
public async parameters(
chainID: string,
params: APIParams = {}
): Promise<AuthParams> {
return this.getReqFromChainID(chainID)
.get<{ params: AuthParams.Data }>(`/cosmos/auth/v1beta1/params`, params)
.then(({ params: d }) => ({
max_memo_characters: Number.parseInt(d.max_memo_characters),
tx_sig_limit: Number.parseInt(d.tx_sig_limit),
tx_size_cost_per_byte: Number.parseInt(d.tx_size_cost_per_byte),
sig_verify_cost_ed25519: Number.parseInt(d.sig_verify_cost_ed25519),
sig_verify_cost_secp256k1: Number.parseInt(d.sig_verify_cost_secp256k1),
}));
}
}