-
Notifications
You must be signed in to change notification settings - Fork 17
/
crawlByGetPastEvent.js
42 lines (34 loc) · 1.37 KB
/
crawlByGetPastEvent.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
'use strict'
const db = require('./models/mongodb')
const q = require('./queues')
const tomocoin = require('./models/blockchain/tomocoin')
tomocoin.getPastEvents('Transfer', {
filter: {},
fromBlock: 0,
}, function (error, events) {
if (!error){
for (let i=0; i < events.length; i++) {
let event = events[i]
if (event.event === 'Transfer') {
let blockNumber = event.blockNumber
let transactionHash = event.transactionHash
let fromWallet = event.returnValues.from
let toWallet = event.returnValues.to
let tokenAmount = parseFloat(event.returnValues.value) / 10 ** 18
console.log(blockNumber, transactionHash, fromWallet, toWallet, tokenAmount)
console.log('--------------------')
let tran = new db.Transaction({
hash: transactionHash,
block: blockNumber,
fromWallet: fromWallet,
toWallet: toWallet,
tokenAmount: tokenAmount,
isProcess: false
})
tran.save()
q.create('newTransaction', {fromWallet: fromWallet, toWallet: toWallet, tokenAmount: tokenAmount})
.priority('high').removeOnComplete(true).save()
}
}
}
})