-
Notifications
You must be signed in to change notification settings - Fork 1
/
golos_tools.js
53 lines (44 loc) · 1.15 KB
/
golos_tools.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
const m = require("./messages");
const ga = require("golos-addons");
const golos = ga.golos;
module.exports.check_account = async (acc) => {
let ok = true;
let errmsg = null;
if (!(await golos.getAccount(acc))) {
ok = false;
errmsg = m.golos.account_does_not_exists(acc);
}
return {
ok, acc, errmsg
}
}
module.exports.check_amount = async (acc_name, _amount) => {
const amount = parseFloat(_amount);
let errmsg = null;
let ok = !isNaN(amount);
if (!ok || amount < 0) {
errmsg = m.golos.not_a_number(_amount);
}
if (ok) {
//check available balance
const { sbd_balance, balance } = await golos.getAccount(acc_name);
const sbd = parseFloat(sbd_balance.split(" ")[0]);
if (sbd < amount) {
errmsg = m.golos.not_enough_balance(sbd_balance, amount);
ok = false;
}
}
return {
amount, ok, errmsg
}
}
module.exports.check_wif = async (wif) => {
let ok = golos.golos.auth.isWif(wif);
let errmsg = null;
if (!ok) {
errmsg = m.golos.wrong_wif();
}
return {
wif, ok, errmsg
}
}