-
Notifications
You must be signed in to change notification settings - Fork 0
/
claim.js
executable file
·104 lines (85 loc) · 2.41 KB
/
claim.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
95
96
97
98
99
100
101
102
103
const fs = require('fs')
const requestProxy = require("request").defaults({
proxy: "http://127.0.0.1:7890",
rejectUnauthorized: false,
})
const claim_url = 'https://api.poap.xyz/actions/claim-qr'
// helper methods
let synchronous_request = function (url, params) {
let options = {
url: url,
form: params
}
if (params == undefined) {
return new Promise(function (resolve, reject) {
// If you don't use proxy, require("request").get(...) is ok
// require("request").get(options, function (error, response, body) {
requestProxy.get(options, function (error, response, body) {
if (error) {
reject(error)
} else {
resolve(body)
}
})
})
} else {
return new Promise(function (resolve, reject) {
// If you don't use proxy, require("request").post(...) is ok
// require("request").post(options, function (error, response, body) {
requestProxy.post(options, function (error, response, body) {
if (error) {
reject(error)
} else {
resolve(body)
}
})
})
}
}
//claim poap by qr_hash
async function main() {
if (process.argv.length < 3) {
console.log('argv: qr_hash address')
return
}
let a = process.argv[2].split('/')
let qr_hash = a[a.length - 1]
let url = claim_url + '?qr_hash=' + qr_hash
let body = await synchronous_request(url)
console.log(body)
let o = JSON.parse(body)
if (o.claimed == false) {
if (process.argv.length < 4) {
console.log('node claim qr_hash address')
return
}
let address = process.argv[3]
if (!address.startsWith('0x')) {
address = get_real_address(address)
if (address == undefined) {
console.log('bad account alias: ' + process.argv[3])
return
}
}
let body = await synchronous_request(claim_url, {
qr_hash: o.qr_hash,
address: address,
secret: o.secret,
})
console.log(body)
console.log('\n* claimed for ' + process.argv[3])
} else {
console.log('\n' + o.beneficiary + ' had claimed this poap')
}
}
function get_real_address(account_name) {
let list = fs.readFileSync('address_list.txt')
let lines = list.toString().split('\n')
for (let index in lines) {
let line = lines[index]
let arr = line.split(':')
if (arr[0] == account_name) return arr[1]
}
return undefined
}
main()