-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathconsensus_accounts.ts
63 lines (52 loc) · 1.78 KB
/
consensus_accounts.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
import * as event from './event';
import * as transaction from './transaction';
import * as types from './types';
import * as wrapper from './wrapper';
/**
* Unique module name.
*/
export const MODULE_NAME = 'consensus_accounts';
export const ERR_INVALID_ARGUMENT_CODE = 1;
export const ERR_INVALID_DENOMINATION_CODE = 2;
export const ERR_INSUFFICIENT_WITHDRAW_BALANCE_CODE = 3;
// Callable methods.
export const METHOD_DEPOSIT = 'consensus.Deposit';
export const METHOD_WITHDRAW = 'consensus.Withdraw';
// Queries.
export const METHOD_BALANCE = 'consensus.Balance';
export const METHOD_ACCOUNT = 'consensus.Account';
// Events.
export const EVENT_DEPOSIT_CODE = 1;
export const EVENT_WITHDRAW_CODE = 2;
export class Wrapper extends wrapper.Base {
constructor(runtimeID: Uint8Array) {
super(runtimeID);
}
callDeposit() {
return this.call<types.ConsensusDeposit, void>(METHOD_DEPOSIT);
}
callWithdraw() {
return this.call<types.ConsensusWithdraw, void>(METHOD_WITHDRAW);
}
queryBalance() {
return this.query<types.ConsensusBalanceQuery, types.ConsensusAccountBalance>(
METHOD_BALANCE,
);
}
queryAccount() {
return this.query<types.ConsensusAccountQuery, Uint8Array>(METHOD_ACCOUNT);
}
}
export function moduleEventHandler(codes: {
[EVENT_DEPOSIT_CODE]?: event.Handler<types.ConsensusAccountsDepositEvent>;
[EVENT_WITHDRAW_CODE]?: event.Handler<types.ConsensusAccountsWithdrawEvent>;
}) {
return [MODULE_NAME, codes] as event.ModuleHandler;
}
/**
* Use this as a part of a {@link transaction.CallHandlers}.
*/
export type TransactionCallHandlers = {
[METHOD_DEPOSIT]?: transaction.CallHandler<types.ConsensusDeposit>;
[METHOD_WITHDRAW]?: transaction.CallHandler<types.ConsensusWithdraw>;
};