-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminter_api.js
64 lines (52 loc) · 1.27 KB
/
minter_api.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
const axios = require("axios");
const MINTER_NODE = process.env.MINTER_API_URL || "http://localhost:8841";
async function get(endpoint) {
const url = `${MINTER_NODE}/${endpoint}`;
try {
const apiResponse = await axios.get(url, {
timeout: 5000
});
return apiResponse.data.result;
} catch (e) {
console.error("minter request failed", endpoint);
if (e.response && e.response.data) {
console.error(e.response.data);
} else {
console.error(e);
}
return null;
}
}
async function getStatus() {
return await get("status");
}
async function getBlock(height) {
return await get(`block?height=${height}`);
}
async function getAddress(address) {
return await get(`address?address=${address}`);
}
async function getTransaction(hash) {
return await get(`transaction?hash=${hash}`);
}
const TransactionType = {
Send: 1,
SellCoin: 2,
SellAllCoin: 3,
BuyCoin: 4,
CreateCoin: 5,
DeclareCandidacy: 6,
Delegate: 7,
Unbond: 8,
RedeemCheck: 9,
SetCandidateOnline: 10,
SetCandidateOffline: 11,
CreateMultisig: 12,
Multisend: 13,
EditCandidate: 14
};
module.exports = {
getStatus,
getBlock,
TransactionType
};