@@ -45,35 +45,64 @@ def get_current_block_number(self) -> Optional[int]:
45
45
self .logger .warning (f"Error while fetching block number: { err } " )
46
46
return None
47
47
48
- def get_tx_hashes_by_block (
49
- self , start_block : int , end_block : int
50
- ) -> Optional [list [str ]]:
48
+ def get_filtered_receipts (
49
+ self , start_block : int , end_block : int , target : str , topics : list [ Any ]
50
+ ) -> Optional [list [Any ]]:
51
51
"""
52
- Function filters hashes by contract address, and block ranges
52
+ Function filters receipts by contract address, and block ranges
53
53
"""
54
54
filter_criteria : FilterParams = {
55
55
"fromBlock" : int (start_block ),
56
56
"toBlock" : int (end_block ),
57
- "address" : self .web_3 .to_checksum_address (SETTLEMENT_CONTRACT_ADDRESS ),
58
- "topics" : [
59
- HexStr (
60
- "0xa07a543ab8a018198e99ca0184c93fe9050a79400a0a723441f84de1d972cc17"
61
- )
62
- ],
57
+ "address" : self .web_3 .to_checksum_address (target ),
58
+ "topics" : topics ,
63
59
}
64
-
65
60
try :
66
61
log_receipts = self .web_3 .eth .filter (filter_criteria ).get_all_entries ()
67
62
except ValueError as err :
68
63
self .logger .warning (f"ValueError while fetching hashes: { err } " )
69
64
return None
65
+ return log_receipts
70
66
67
+ def get_tx_hashes_by_block (
68
+ self , start_block : int , end_block : int
69
+ ) -> Optional [list [str ]]:
70
+ """
71
+ Function filters hashes by contract address, and block ranges
72
+ """
73
+ topics = [
74
+ HexStr ("0xa07a543ab8a018198e99ca0184c93fe9050a79400a0a723441f84de1d972cc17" )
75
+ ]
76
+ log_receipts = self .get_filtered_receipts (
77
+ start_block , end_block , SETTLEMENT_CONTRACT_ADDRESS , topics
78
+ )
79
+
80
+ if log_receipts is None :
81
+ return None
71
82
settlement_hashes_list = list (
72
83
{log_receipt ["transactionHash" ].hex () for log_receipt in log_receipts }
73
84
)
74
-
75
85
return settlement_hashes_list
76
86
87
+ def get_eth_transfers_by_block_range (
88
+ self , start_block : int , end_block : int , target : str
89
+ ) -> Optional [float ]:
90
+ """
91
+ Function that computes total eth transfers to a target Safe address
92
+ within a certain block range
93
+ """
94
+ log_receipts = self .get_filtered_receipts (start_block , end_block , target , [])
95
+ if log_receipts is None :
96
+ return None
97
+ total_transfers_in_eth = 0.0
98
+ for txs in log_receipts :
99
+ if (
100
+ txs ["topics" ][0 ].hex ()
101
+ == "0x3d0ce9bfc3ed7d6862dbb28b2dea94561fe714a1b4d019aa8af39730d1ad7c3d"
102
+ ):
103
+ total_transfers_in_eth += int (txs ["data" ].hex (), 16 ) / 10 ** 18
104
+ return total_transfers_in_eth
105
+
77
106
def get_transaction (self , tx_hash : str ) -> Optional [TxData ]:
78
107
"""
79
108
Takes settlement hash as input, returns transaction data.
0 commit comments