-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaintedAddressBalances.py
68 lines (59 loc) · 2.49 KB
/
taintedAddressBalances.py
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
from taintedTokenBalance import TaintedTokenBalance
import json
from decimal import *
class TaintedAddressBalances:
#-----------------------------
# Initialize a new Tainted Address Balances object
# that trackes ETH and ERC20 token balances associated
# with a crypto address.
def __init__(self,address):
self.address = address
self.name = 'none'
self.category = 'none'
self.token_balances = {}
self.tainted_gas = 0
def loadTaintedAddressBalances(self,ta_json):
self.address = ta_json['address']
for tb in ta_json['tokenstates']:
if not tb['token'] in self.token_balances:
self.token_balances[tb['token']] = TaintedTokenBalance(tb['token'],int(tb['decimal']))
self.token_balances[tb['token']].loadTokenBalance(tb)
# keep track of how much "tainted" gas this address has spent
# over time some stolen funds will naturally be spent on gas
# which isn't really recoverable
def recordGas(self,value):
self.tainted_gas+=int(value)
def toString(self):
desc_str = '{}'.format(self.address)
for tb in self.token_balances:
desc_str = '{} {}'.format(desc_str,self.token_balances[tb].toString())
return desc_str
def toJson(self):
tb_jsonstr = ''
for tb in self.token_balances:
if len(self.token_balances[tb].token) < 8:
if tb_jsonstr == '':
tb_jsonstr = '{}'.format(self.token_balances[tb].toJson())
else:
tb_jsonstr = '{},\n{}'.format(tb_jsonstr,self.token_balances[tb].toJson())
return '{{"address":"{}", "name":"{}", "category":"{}", "tokenstates":[\n{}\n]}}'.format(self.address,self.name,self.category,tb_jsonstr)
##--------------
# UNIT TESTS
def main():
testq = TaintedAddressBalances('0x0')
print(testq.toString())
json_file = open('./TestData/testta.json')
json_str = json_file.read()
testtb = json.loads(json_str)
testq.loadTaintedAddressBalances(testtb)
print(testq.toString())
testq.token_balances['ETH'].processCredit('50000000000000000000')
print(testq.toString())
testq.token_balances['ETH'].processCredit('50000000000000000000')
print(testq.toString())
testq.token_balances['ETH'].processDebit('5000000000')
print(testq.toString())
testq.token_balances['ETH'].processDebit('70000000000000000000000')
print(testq.toString())
if __name__ == "__main__":
main()