-
Notifications
You must be signed in to change notification settings - Fork 8
/
job.ts
63 lines (39 loc) · 1.52 KB
/
job.ts
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
import axios from 'axios'
import {BoostPowJob} from 'boostpow'
export async function main() {
const newJob = BoostPowJob.fromObject({
content: process.argv[2],
diff: 1,
tag: Buffer.from(process.argv[3], 'utf8').toString('hex'),
category: Buffer.from(process.argv[4] || '1234', 'utf8').toString('hex')
})
var { tag, category } = newJob.toObject()
tag = Buffer.from(tag, 'hex').toString("utf8")
category = Buffer.from(category, 'hex').toString("utf8")
console.log('job from sdk', newJob.toObject())
console.log({ tag, category })
const content = process.argv[2]
const { data } = await axios.post(`https://pow.co/api/v1/boost/scripts`, {
tag,
difficulty: 1,
content,
category
})
console.log(data)
const job = BoostPowJob.fromHex(data.script.hex)
const jobJson = job.toObject()
console.log(Object.assign(jobJson, {
tag: Buffer.from(jobJson.tag).toString('utf8'),
category: Buffer.from(jobJson.category).toString('utf8')
}))
const { data: thirdWay } = await axios.get(`https://pow.co/api/v1/boostpow/${content}/new?difficulty=1&tag=${tag}&category=${category}`)
const thirdJob = BoostPowJob.fromHex(data.script.hex)
const thirdJobJson = job.toObject()
console.log(Object.assign(thirdJobJson, {
tag: Buffer.from(thirdJobJson.tag).toString('utf8'),
category: Buffer.from(thirdJobJson.category).toString('utf8')
}))
}
if (require.main === module) {
main()
}