5
5
class Account (Client ):
6
6
def __init__ (self , address = Client .dao_address , api_key = 'YourApiKeyToken' ):
7
7
Client .__init__ (self , address = address , api_key = api_key )
8
- self .module = self .URL_BASES ['module' ] + 'account'
9
-
10
- def make_url (self , call_type = '' ):
11
- if call_type == 'balance' :
12
- self .url = self .URL_BASES ['prefix' ] \
13
- + self .module \
14
- + self .action \
15
- + self .address \
16
- + self .tag \
17
- + self .key
18
- elif call_type == 'transactions' :
19
- self .url = self .URL_BASES ['prefix' ] \
20
- + self .module \
21
- + self .action \
22
- + self .address \
23
- + self .offset \
24
- + self .page \
25
- + self .key
26
- elif call_type == 'blocks' :
27
- self .url = self .URL_BASES ['prefix' ] \
28
- + self .module \
29
- + self .action \
30
- + self .address \
31
- + self .blocktype \
32
- + self .offset \
33
- + self .page \
34
- + self .key
8
+ self .url_dict [self .MODULE ] = 'account'
35
9
36
10
def get_balance (self ):
37
- self .action = self .URL_BASES [ 'action' ] + 'balance'
38
- self .tag = self .URL_BASES [ 'tag' ] + 'latest'
39
- self .make_url ( call_type = 'transactions' )
11
+ self .url_dict [ self .ACTION ] = 'balance'
12
+ self .url_dict [ self .TAG ] = 'latest'
13
+ self .build_url ( )
40
14
req = self .connect ()
41
15
return req ['result' ]
42
16
43
17
def get_balance_multiple (self ):
44
- self .action = self .URL_BASES [ 'action' ] + 'balancemulti'
45
- self .tag = self .URL_BASES [ 'tag' ] + 'latest'
46
- self .make_url ( call_type = 'balance' )
18
+ self .url_dict [ self .ACTION ] = 'balancemulti'
19
+ self .url_dict [ self .TAG ] = 'latest'
20
+ self .build_url ( )
47
21
req = self .connect ()
48
22
return req ['result' ]
49
23
@@ -78,29 +52,29 @@ def get_transaction_page(self, page=1, offset=10000, sort='asc', internal=False)
78
52
False -> (default) get normal external transactions
79
53
"""
80
54
if internal :
81
- self .action = self .URL_BASES [ 'action' ] + 'txlistinternal'
55
+ self .url_dict [ self .ACTION ] = 'txlistinternal'
82
56
else :
83
- self .action = self .URL_BASES [ 'action' ] + 'txlist'
84
- self .page = self .URL_BASES [ 'page' ] + str (page )
85
- self .offset = self .URL_BASES [ 'offset' ] + str (offset )
86
- self .sort = self .URL_BASES [ 'sort' ] + sort
87
- self .make_url ( call_type = 'transactions' )
57
+ self .url_dict [ self .ACTION ] = 'txlist'
58
+ self .url_dict [ self .PAGE ] = str (page )
59
+ self .url_dict [ self .OFFSET ] = str (offset )
60
+ self .url_dict [ self .SORT ] = sort
61
+ self .build_url ( )
88
62
req = self .connect ()
89
63
return req ['result' ]
90
64
91
65
def get_all_transactions (self , offset = 10000 , sort = 'asc' , internal = False ) -> list :
92
66
if internal :
93
- self .action = self .URL_BASES [ 'action' ] + 'txlistinternal'
67
+ self .url_dict [ self .ACTION ] = 'txlistinternal'
94
68
else :
95
- self .action = self .URL_BASES [ 'action' ] + 'txlist'
96
- self .page = self .URL_BASES [ 'page' ] + str (1 )
97
- self .offset = self .URL_BASES [ 'offset' ] + str (offset )
98
- self .sort = self .URL_BASES [ 'sort' ] + sort
99
- self .make_url ( call_type = 'transactions' )
69
+ self .url_dict [ self .ACTION ] = 'txlist'
70
+ self .url_dict [ self .PAGE ] = str (1 )
71
+ self .url_dict [ self .OFFSET ] = str (offset )
72
+ self .url_dict [ self .SORT ] = sort
73
+ self .build_url ( )
100
74
101
75
trans_list = []
102
76
while True :
103
- self .make_url ( call_type = 'transactions' )
77
+ self .build_url ( )
104
78
req = self .connect ()
105
79
if "No transactions found" in req ['message' ]:
106
80
print ("Total number of transactions: {}" .format (len (trans_list )))
@@ -109,9 +83,9 @@ def get_all_transactions(self, offset=10000, sort='asc', internal=False) -> list
109
83
else :
110
84
trans_list += req ['result' ]
111
85
# Find any character block that is a integer of any length
112
- page_number = re .findall (r'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0' , self .page )
86
+ page_number = re .findall (r'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0' , self .url_dict [ self . PAGE ] )
113
87
print ("page {} added" .format (page_number [0 ]))
114
- self .page = self .URL_BASES [ 'page' ] + str (int (page_number [0 ]) + 1 )
88
+ self .url_dict [ self .PAGE ] = str (int (page_number [0 ]) + 1 )
115
89
116
90
def get_blocks_mined_page (self , blocktype = 'blocks' , page = 1 , offset = 10000 ) -> list :
117
91
"""
@@ -124,22 +98,22 @@ def get_blocks_mined_page(self, blocktype='blocks', page=1, offset=10000) -> lis
124
98
'blocks' -> full blocks only
125
99
'uncles' -> uncles only
126
100
"""
127
- self .action = self .URL_BASES [ 'action' ] + 'getminedblocks'
128
- self .blocktype = self .URL_BASES [ 'blocktype' ] + blocktype
129
- self .page = self .URL_BASES [ 'page' ] + str (page )
130
- self .offset = self .URL_BASES [ 'offset' ] + str (offset )
131
- self .make_url ( call_type = 'blocks' )
101
+ self .url_dict [ self .ACTION ] = 'getminedblocks'
102
+ self .url_dict [ self .BLOCK_TYPE ] = blocktype
103
+ self .url_dict [ self .PAGE ] = str (page )
104
+ self .url_dict [ self .OFFSET ] = str (offset )
105
+ self .build_url ( )
132
106
req = self .connect ()
133
107
return req ['result' ]
134
108
135
109
def get_all_blocks_mined (self , blocktype = 'blocks' , offset = 10000 ) -> list :
136
- self .action = self .URL_BASES [ 'action' ] + 'getminedblocks'
137
- self .blocktype = self .URL_BASES [ 'blocktype' ] + blocktype
138
- self .page = self .URL_BASES [ 'page' ] + str (1 )
139
- self .offset = self .URL_BASES [ 'offset' ] + str (offset )
110
+ self .url_dict [ self .ACTION ] = 'getminedblocks'
111
+ self .url_dict [ self .BLOCK_TYPE ] = blocktype
112
+ self .url_dict [ self .PAGE ] = str (1 )
113
+ self .url_dict [ self .OFFSET ] = str (offset )
140
114
blocks_list = []
141
115
while True :
142
- self .make_url ( call_type = 'blocks' )
116
+ self .build_url ( )
143
117
req = self .connect ()
144
118
print (req ['message' ])
145
119
if "No transactions found" in req ['message' ]:
@@ -148,9 +122,9 @@ def get_all_blocks_mined(self, blocktype='blocks', offset=10000) -> list:
148
122
else :
149
123
blocks_list += req ['result' ]
150
124
# Find any character block that is a integer of any length
151
- page_number = re .findall (r'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0' , self .page )
125
+ page_number = re .findall (r'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0' , self .url_dict [ self . PAGE ] )
152
126
print ("page {} added" .format (page_number [0 ]))
153
- self .page = self .URL_BASES [ 'page' ] + str (int (page_number [0 ]) + 1 )
127
+ self .url_dict [ self .PAGE ] = str (int (page_number [0 ]) + 1 )
154
128
155
129
def get_internal_by_hash (self , tx_hash = '' ):
156
130
"""
0 commit comments