-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.js
60 lines (51 loc) · 1.42 KB
/
seeds.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
const { JsonRpc, Api, Serialize } = require('eosjs')
const fetch = require('node-fetch')
const rpc = new JsonRpc('https://node.hypha.earth', {
fetch
})
// getDefferedSeeds
const getGratitudeStats = async () => {
const statsTable = await rpc.get_table_rows({
code: 'gratz.seeds',
scope: 'gratz.seeds',
table: 'stats',
json: true
})
if (statsTable.rows) {
return statsTable.rows[statsTable.rows.length-1];
}
return [];
}
const getRemainingGratitude = async account => {
const balanceTable = await rpc.get_table_rows({
code: 'gratz.seeds',
scope: 'gratz.seeds',
table: 'balances',
json: true
})
const balance = balanceTable.rows.filter(r => r.account == account)
var res = 0;
if (balance.length > 0) {
res = parseInt(balance[0].remaining);
}
return res;
}
const getReceivedGratitude = async account => {
const balanceTable = await rpc.get_table_rows({
code: 'gratz.seeds',
scope: 'gratz.seeds',
table: 'balances',
json: true
})
const balance = balanceTable.rows.filter(r => r.account == account)
var res = 0;
if (balance.length > 0) {
res = parseInt(balance[0].received);
}
return res
}
const getBalance = async (account) => {
const balance = await rpc.get_currency_balance('token.seeds', account, 'SEEDS')
return Number.parseInt(balance[0])
}
module.exports = { getReceivedGratitude, getRemainingGratitude, getBalance, getGratitudeStats }