@@ -840,25 +840,10 @@ def _get_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
840
840
return transact_transaction
841
841
842
842
@combomethod
843
- def buildTransaction (self , transaction : Optional [TxParams ] = None ) -> TxParams :
844
- """
845
- Build the transaction dictionary without sending
846
- """
847
-
848
- if transaction is None :
849
- built_transaction : TxParams = {}
850
- else :
851
- built_transaction = cast (TxParams , dict (** transaction ))
852
- self .check_forbidden_keys_in_transaction (built_transaction ,
853
- ["data" , "to" ])
854
-
855
- if self .w3 .eth .default_account is not empty :
856
- # type ignored b/c check prevents an empty default_account
857
- built_transaction .setdefault ('from' , self .w3 .eth .default_account ) # type: ignore
858
-
859
- built_transaction ['data' ] = self .data_in_transaction
843
+ def _build_transaction (self , transaction : Optional [TxParams ] = None ) -> TxParams :
844
+ built_transaction = self ._get_transaction (transaction )
860
845
built_transaction ['to' ] = Address (b'' )
861
- return fill_transaction_defaults ( self . w3 , built_transaction )
846
+ return built_transaction
862
847
863
848
@staticmethod
864
849
def check_forbidden_keys_in_transaction (
@@ -877,6 +862,22 @@ class ContractConstructor(BaseContractConstructor):
877
862
def transact (self , transaction : Optional [TxParams ] = None ) -> HexBytes :
878
863
return self .w3 .eth .send_transaction (self ._get_transaction (transaction ))
879
864
865
+ @combomethod
866
+ def build_transaction (self , transaction : Optional [TxParams ] = None ) -> TxParams :
867
+ """
868
+ Build the transaction dictionary without sending
869
+ """
870
+ built_transaction = self ._build_transaction (transaction )
871
+ return fill_transaction_defaults (self .w3 , built_transaction )
872
+
873
+ @combomethod
874
+ @deprecated_for ("build_transaction" )
875
+ def buildTransaction (self , transaction : Optional [TxParams ] = None ) -> TxParams :
876
+ """
877
+ Build the transaction dictionary without sending
878
+ """
879
+ return self .build_transaction (transaction )
880
+
880
881
881
882
class AsyncContractConstructor (BaseContractConstructor ):
882
883
@@ -885,6 +886,14 @@ async def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
885
886
return await self .w3 .eth .send_transaction ( # type: ignore
886
887
self ._get_transaction (transaction ))
887
888
889
+ @combomethod
890
+ async def build_transaction (self , transaction : Optional [TxParams ] = None ) -> TxParams :
891
+ """
892
+ Build the transaction dictionary without sending
893
+ """
894
+ built_transaction = self ._build_transaction (transaction )
895
+ return fill_transaction_defaults (self .w3 , built_transaction )
896
+
888
897
889
898
class ConciseMethod :
890
899
ALLOWED_MODIFIERS = {'call' , 'estimateGas' , 'transact' , 'buildTransaction' }
@@ -1364,7 +1373,7 @@ async def call(
1364
1373
self ._return_data_normalizers ,
1365
1374
self .function_identifier ,
1366
1375
call_transaction ,
1367
- block_id ,
1376
+ block_id , # type: ignore
1368
1377
self .contract_abi ,
1369
1378
self .abi ,
1370
1379
state_override ,
@@ -2020,11 +2029,11 @@ def parse_block_identifier(w3: 'Web3', block_identifier: BlockIdentifier) -> Blo
2020
2029
2021
2030
async def async_parse_block_identifier (w3 : 'Web3' ,
2022
2031
block_identifier : BlockIdentifier
2023
- ) -> BlockIdentifier :
2032
+ ) -> Awaitable [ BlockIdentifier ] :
2024
2033
if isinstance (block_identifier , int ):
2025
- return parse_block_identifier_int (w3 , block_identifier )
2034
+ return await async_parse_block_identifier_int (w3 , block_identifier )
2026
2035
elif block_identifier in ['latest' , 'earliest' , 'pending' ]:
2027
- return block_identifier
2036
+ return block_identifier # type: ignore
2028
2037
elif isinstance (block_identifier , bytes ) or is_hex_encoded_block_hash (block_identifier ):
2029
2038
return await w3 .eth .get_block (block_identifier )['number' ] # type: ignore
2030
2039
else :
@@ -2042,6 +2051,18 @@ def parse_block_identifier_int(w3: 'Web3', block_identifier_int: int) -> BlockNu
2042
2051
return BlockNumber (block_num )
2043
2052
2044
2053
2054
+ async def async_parse_block_identifier_int (w3 : 'Web3' , block_identifier_int : int
2055
+ ) -> Awaitable [BlockNumber ]:
2056
+ if block_identifier_int >= 0 :
2057
+ block_num = block_identifier_int
2058
+ else :
2059
+ last_block = await w3 .eth .get_block ('latest' )['number' ] # type: ignore
2060
+ block_num = last_block + block_identifier_int + 1
2061
+ if block_num < 0 :
2062
+ raise BlockNumberOutofRange
2063
+ return BlockNumber (block_num ) # type: ignore
2064
+
2065
+
2045
2066
def transact_with_contract_function (
2046
2067
address : ChecksumAddress ,
2047
2068
w3 : 'Web3' ,
@@ -2167,7 +2188,7 @@ def async_find_functions_by_identifier(
2167
2188
2168
2189
def get_function_by_identifier (
2169
2190
fns : Sequence [ContractFunction ], identifier : str
2170
- ) -> ContractFunction :
2191
+ ) -> Union [ ContractFunction , AsyncContractFunction ] :
2171
2192
if len (fns ) > 1 :
2172
2193
raise ValueError (
2173
2194
f'Found multiple functions with matching { identifier } . '
0 commit comments