-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
49 lines (40 loc) · 1.27 KB
/
db.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
const fs = require('fs')
const {getCurrentTimestamp} = require("./utils");
const Crypto = require('kryptokrona-crypto').Crypto
const xkr = new Crypto()
const saveAddress = async (address) => {
const hash = await hashAddress(address)
fs.readFile('./claimed.json', function (err, data) {
let json = JSON.parse(data)
json.push({
"hash": hash,
"timestamp": getCurrentTimestamp()
})
fs.writeFile('./claimed.json', JSON.stringify(json), () => {
console.log('🚨 SAVED HASH')
})
})
}
const checkAddress = async (address) => {
const hash = await hashAddress(address)
const data = fs.readFileSync('./claimed.json')
const json = JSON.parse(data)
const claimed = json.find(i => i.hash === hash)
return !!claimed
}
const getHowManyClaimers = async () => {
const data = fs.readFileSync('./claimed.json')
const json = JSON.parse(data)
return json.length
}
async function hashAddress(address) {
return await xkr.cn_turtle_lite_slow_hash_v2(toHex(address))
}
function toHex(str) {
let result = '';
for (let i = 0; i < str.length; i++) {
result += str.charCodeAt(i).toString(16);
}
return result;
}
module.exports = {saveAddress, checkAddress, getHowManyClaimers}