-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWallet.js
94 lines (73 loc) · 1.99 KB
/
Wallet.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
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
const { URL } = require('url');
const endpoints = require('./endpoints');
class WalletService {
constructor(client) {
this._client = client;
}
async getCoins() {
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.COINS;
const r = await c.get(u);
return r.data.result;
}
async getBalances() {
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.BALANCES;
const r = await c.get(u);
return r.data.result;
}
async getDepositAddress(coinId) {
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.DEPOSIT_ADDRESS + `/${coinId}`;
const r = await c.get(u);
return r.data.result;
}
async getDepositHistory() {
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.DEPOSITS;
const r = await c.get(u);
return r.data.result;
}
async getWithdrawlHistory() {
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.WITHDRAWALS;
const r = await c.get(u);
return r.data.result;
}
async requestWithdrawl(coin, size, address, opts={ tag: null, password: null, code: null }) {
const { tag, password, code } = opts;
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.WITHDRAWALS;
const r = await c.post(u, {
coin,
size,
address,
tag,
password,
code
});
return r.data.result;
}
async requestWithdrawal(coin, size, address, opts={ tag: null, password: null, code: null }) {
const { tag, password, code } = opts;
const c = this._client;
const u = new URL(c.baseURL.href);
u.pathname = endpoints.WALLET.WITHDRAWALS;
const r = await c.post(u, {
coin,
size,
address,
tag,
password,
code
});
return r.data.result;
}
}
module.exports = WalletService;