11import os
2+ from typing import Tuple
23import requests
34import json
45from decimal import Decimal
@@ -33,17 +34,20 @@ def get_current_block() -> int:
3334 return result
3435
3536
36- def get_asset_transfers (node_address : str , block_start : int , block_end : int ) -> list :
37+ def get_asset_transfers (
38+ from_address : str , from_block : int , to_block : int , max_count = 1000 , page_key = None
39+ ) -> Tuple [list , str ]:
3740 """
3841 params:
39- node_address: wallet address associated with the OCR node
42+ from_address: Address to look for transactions from
4043 block_start: INT
4144 block_end: INT
42- returns: A dictionary, internal/external asset transfers for the address
45+ returns: [list, str]
46+ A Tuple, index 0 is the list of transfers, index 1 is the page key or None
4347 """
44- from_block = str (hex (block_start ))
45- to_block = str (hex (block_end ))
46- address = node_address .lower ()
48+ from_block = str (hex (from_block ))
49+ to_block = str (hex (to_block ))
50+ address = from_address .lower ()
4751 payload = {
4852 "id" : 1 ,
4953 "jsonrpc" : "2.0" ,
@@ -53,16 +57,21 @@ def get_asset_transfers(node_address: str, block_start: int, block_end: int) ->
5357 "fromBlock" : from_block ,
5458 "toBlock" : to_block ,
5559 "fromAddress" : address ,
56- "category" : ["external" , "internal" ],
60+ "category" : ["external" , "internal" , "erc20" , "erc721" , "specialnft" ],
5761 "excludeZeroValue" : False ,
62+ "maxCount" : hex (max_count ),
5863 }
5964 ],
6065 }
66+ if page_key :
67+ payload ["params" ][0 ]["pageKey" ] = page_key
6168 response = requests .post (BASE_URL , json = payload , headers = HEADERS )
62- response = json . loads ( response .text )
63- result = response ["result" ]
69+ json_response = response .json ( )
70+ result = json_response ["result" ]
6471 transfers = result ["transfers" ]
65- return transfers
72+ if "pageKey" in result :
73+ return transfers , result ["pageKey" ]
74+ return transfers , None
6675
6776
6877def get_transaction_receipt (transaction_hash : str ):
@@ -79,8 +88,8 @@ def get_transaction_receipt(transaction_hash: str):
7988 "params" : [transaction_hash ],
8089 }
8190 response = requests .post (BASE_URL , json = payload , headers = HEADERS )
82- response = json . loads ( response .text )
83- result = response ["result" ]
91+ json_respnse = response .json ( )
92+ result = json_respnse ["result" ]
8493 return result
8594
8695
0 commit comments