33
44
55class Account (Client ):
6+ PAGE_NUM_PATTERN = re .compile (
7+ '[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0' )
8+
69 def __init__ (self , address = Client .dao_address , api_key = 'YourApiKeyToken' ):
710 Client .__init__ (self , address = address , api_key = api_key )
811 self .url_dict [self .MODULE ] = 'account'
@@ -21,9 +24,11 @@ def get_balance_multiple(self):
2124 req = self .connect ()
2225 return req ['result' ]
2326
24- def get_transaction_page (self , page = 1 , offset = 10000 , sort = 'asc' , internal = False ) -> list :
27+ def get_transaction_page (self , page = 1 , offset = 10000 , sort = 'asc' ,
28+ internal = False ) -> list :
2529 """
26- Get a page of transactions, each transaction returns list of dict with keys:
30+ Get a page of transactions, each transaction
31+ returns list of dict with keys:
2732 nonce
2833 hash
2934 cumulativeGasUsed
@@ -62,7 +67,8 @@ def get_transaction_page(self, page=1, offset=10000, sort='asc', internal=False)
6267 req = self .connect ()
6368 return req ['result' ]
6469
65- def get_all_transactions (self , offset = 10000 , sort = 'asc' , internal = False ) -> list :
70+ def get_all_transactions (self , offset = 10000 , sort = 'asc' ,
71+ internal = False ) -> list :
6672 if internal :
6773 self .url_dict [self .ACTION ] = 'txlistinternal'
6874 else :
@@ -77,19 +83,23 @@ def get_all_transactions(self, offset=10000, sort='asc', internal=False) -> list
7783 self .build_url ()
7884 req = self .connect ()
7985 if "No transactions found" in req ['message' ]:
80- print ("Total number of transactions: {}" .format (len (trans_list )))
86+ print (
87+ "Total number of transactions: {}" .format (len (trans_list )))
8188 self .page = ''
8289 return trans_list
8390 else :
8491 trans_list += req ['result' ]
8592 # Find any character block that is a integer of any length
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 ])
93+ page_number = re .findall (Account .PAGE_NUM_PATTERN ,
94+ self .url_dict [self .PAGE ])
8795 print ("page {} added" .format (page_number [0 ]))
8896 self .url_dict [self .PAGE ] = str (int (page_number [0 ]) + 1 )
8997
90- def get_blocks_mined_page (self , blocktype = 'blocks' , page = 1 , offset = 10000 ) -> list :
98+ def get_blocks_mined_page (self , blocktype = 'blocks' , page = 1 ,
99+ offset = 10000 ) -> list :
91100 """
92- Get a page of blocks mined by given address, returns list of dict with keys:
101+ Get a page of blocks mined by given address,
102+ returns list of dict with keys:
93103 blockReward (in wei)
94104 blockNumber
95105 timeStamp
@@ -117,12 +127,15 @@ def get_all_blocks_mined(self, blocktype='blocks', offset=10000) -> list:
117127 req = self .connect ()
118128 print (req ['message' ])
119129 if "No transactions found" in req ['message' ]:
120- print ("Total number of blocks mined: {}" .format (len (blocks_list )))
130+ print (
131+ "Total number of blocks mined: {}" .format (
132+ len (blocks_list )))
121133 return blocks_list
122134 else :
123135 blocks_list += req ['result' ]
124136 # Find any character block that is a integer of any length
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 ])
137+ page_number = re .findall (Account .PAGE_NUM_PATTERN ,
138+ self .url_dict [self .PAGE ])
126139 print ("page {} added" .format (page_number [0 ]))
127140 self .url_dict [self .PAGE ] = str (int (page_number [0 ]) + 1 )
128141
@@ -135,6 +148,7 @@ def get_internal_by_hash(self, tx_hash=''):
135148
136149 def update_transactions (self , address , trans ):
137150 """
138- Gets last page of transactions (last 10k trans) and updates current trans book (book)
151+ Gets last page of transactions (last 10k trans)
152+ and updates current trans book (book)
139153 """
140154 pass
0 commit comments