-
Notifications
You must be signed in to change notification settings - Fork 1
/
consensusInfoClient.js
55 lines (47 loc) · 1.26 KB
/
consensusInfoClient.js
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
import {
AccountBalanceQuery,
AccountId,
AccountInfoQuery,
Client,
TokenInfoQuery,
} from "@hashgraph/sdk";
class ConsensusInfoClient {
constructor() {
if (
process.env.NODE_IP &&
process.env.NODE_ACCOUNT_ID &&
process.env.MIRROR_NETWORK
) {
const node = {
[process.env.NODE_IP]: AccountId.fromString(
process.env.NODE_ACCOUNT_ID,
),
};
this.sdkClient = Client.forNetwork(node);
} else {
this.sdkClient = Client.forTestnet();
}
this.sdkClient.setOperator(
process.env.OPERATOR_ACCOUNT_ID,
process.env.OPERATOR_ACCOUNT_PRIVATE_KEY,
);
}
async getBalance(accountId) {
return this.executeAccountMethod(accountId, new AccountBalanceQuery());
}
async getAccountInfo(accountId) {
return this.executeAccountMethod(accountId, new AccountInfoQuery());
}
async getTokenInfo(tokenId) {
return this.executeTokenMethod(tokenId, new TokenInfoQuery());
}
async executeAccountMethod(accountId, method) {
method.setAccountId(accountId);
return method.execute(this.sdkClient);
}
async executeTokenMethod(tokenId, method) {
method.setTokenId(tokenId);
return method.execute(this.sdkClient);
}
}
export default new ConsensusInfoClient();