-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-eventlog.rb
101 lines (71 loc) · 2.41 KB
/
test-eventlog.rb
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
require 'json'
require 'rest-client'
require_relative "utils"
require_relative "EtherscanAPI"
api_key = File.file?('api.key') ? File.open('api.key').read : ''
sl = sl = SimpleLog.new({:verbose => true})
sl.p "\n\n----------{ running #{$0} - #{Time.now.utc} }----------\n\n"
e = EtherscanAPI.new(api_key, sl, {:print_query => true})
###############################################################################
#
# Get event log for an address (all events after block 4000000)
#
sl.h1 'Eventlog for an address (all events after block 4000000)'
contractaddress = '0x4994e81897a920c0FEA235eb8CEdEEd3c6fFF697'
topics = {
:topic0 => '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
}
res = e.get_eventlog(contractaddress, topics, 4000000, 'latest')
sl.p
sl.p 'Result: ' + res.inspect
sl.p
res[:result].each do |h|
from = '0x' + h[:topics][1].split(//).last(40).join
to = '0x' + h[:topics][2].split(//).last(40).join
block = h[:blockNumber].to_i(16)
t = h[:timeStamp].to_i(16)
t = Time.at(t).utc
amount = h[:data].to_i(16)
tx_hash = h[:transactionHash]
sl.p
sl.p "#{t} block #{block}"
sl.p "Tx Hash: #{tx_hash}"
sl.p "From: #{from}"
sl.p "To: #{to}"
sl.p "Amount: #{amount} (#{amount/1e18})"
end
###############################################################################
#
# Get event log for an address (list only tokens received by a specific account since block 3000000)
#
sl.h1 'Eventlog for an address (list only tokens received by a specific account)'
contractaddress = '0x4994e81897a920c0FEA235eb8CEdEEd3c6fFF697'
topics = {
:topic0 => '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
:topic0_2_opr => 'and',
:topic2 => '0x00000000000000000000000040D50fC288BC5488813c17e7f403CA9BbE7914aD'
}
res = e.get_eventlog(contractaddress, topics, 3000000, 'latest')
sl.p
sl.p 'Result: ' + res.inspect
sl.p
res[:result].each do |h|
from = '0x' + h[:topics][1].split(//).last(40).join
to = '0x' + h[:topics][2].split(//).last(40).join
block = h[:blockNumber].to_i(16)
t = h[:timeStamp].to_i(16)
t = Time.at(t).utc
amount = h[:data].to_i(16)
tx_hash = h[:transactionHash]
sl.p
sl.p "#{t} block #{block}"
sl.p "Tx Hash: #{tx_hash}"
sl.p "From: #{from}"
sl.p "To: #{to}"
sl.p "Amount: #{amount} (#{amount/1e18})"
end
###############################################################################
#
# write to log and exit
#
write_to_file(sl.sLog, 'sLog.log', 'a')