|
1 | 1 | from time import sleep
|
2 | 2 | from typing import Optional
|
3 | 3 |
|
| 4 | +from eth_typing import BlockNumber |
4 | 5 | from web3.eth import Eth
|
5 | 6 | from web3.exceptions import ContractLogicError
|
6 |
| -from web3.types import FilterParams, LogReceipt, CallOverride, BlockIdentifier, TxParams |
| 7 | +from web3.types import FilterParams, LogReceipt, CallOverride, BlockIdentifier, TxParams, BlockData |
7 | 8 |
|
8 | 9 | from IceCreamSwapWeb3 import Web3Advanced
|
9 | 10 |
|
@@ -41,7 +42,7 @@ class EthAdvanced(Eth):
|
41 | 42 | METHODS_TO_RETRY = [
|
42 | 43 | 'fee_history', 'create_access_list', 'estimate_gas',
|
43 | 44 | 'get_transaction', 'get_raw_transaction', 'get_raw_transaction_by_block',
|
44 |
| - 'send_transaction', 'send_raw_transaction', 'get_block', 'get_balance', |
| 45 | + 'send_transaction', 'send_raw_transaction', 'get_balance', |
45 | 46 | 'get_code', 'get_transaction_count', 'get_transaction_receipt',
|
46 | 47 | 'wait_for_transaction_receipt', 'get_storage_at', 'replace_transaction',
|
47 | 48 | 'modify_transaction', 'sign', 'sign_transaction', 'sign_typed_data', 'filter',
|
@@ -94,6 +95,29 @@ def call(
|
94 | 95 | no_retry=no_retry,
|
95 | 96 | )
|
96 | 97 |
|
| 98 | + def get_block_number(self, no_retry: bool = False, ignore_latest_seen_block: bool = False) -> BlockNumber: |
| 99 | + block_number: BlockNumber = exponential_retry(func_name="get_block_number")(super().get_block_number)( |
| 100 | + no_retry=no_retry or not self.w3.should_retry, |
| 101 | + ) |
| 102 | + if not ignore_latest_seen_block and self.w3.latest_seen_block < block_number: |
| 103 | + self.w3.latest_seen_block = block_number |
| 104 | + return block_number |
| 105 | + |
| 106 | + def get_block( |
| 107 | + self, |
| 108 | + block_identifier: BlockIdentifier, |
| 109 | + full_transactions: bool = False, |
| 110 | + no_retry: bool = False |
| 111 | + ) -> BlockData: |
| 112 | + block: BlockData = exponential_retry(func_name="get_block")(super().get_block)( |
| 113 | + block_identifier=block_identifier, |
| 114 | + full_transactions=full_transactions, |
| 115 | + no_retry=no_retry or not self.w3.should_retry, |
| 116 | + ) |
| 117 | + if self.w3.latest_seen_block < block["number"]: |
| 118 | + self.w3.latest_seen_block = block["number"] |
| 119 | + return block |
| 120 | + |
97 | 121 | def get_logs(
|
98 | 122 | self,
|
99 | 123 | filter_params: FilterParams,
|
|
0 commit comments