@@ -118,39 +118,38 @@ def change_account(self, account_address: str):
118118 raise KeyError ("There is no account with such an address in wallet" )
119119 self .active_account = self .__accounts [account_address ]
120120
121- def construct_transaction (self , contract_method : web3 ._utils .datatypes , gas : int = None , value : int = 0 ) -> dict :
121+ def construct_transaction (self , contract_method : web3 ._utils .datatypes , parameters : dict = None ) -> dict :
122122 """
123123 Takes contract method call object and builds transaction dict with it
124124
125125 Parameters:
126126 contract_method: web3._utils.datatypes
127- gas: int (optional)
127+ parameters: dict (optional)
128128 Returns:
129129 constructed transaction in dict
130130 """
131131 try :
132- nonce = self .web3 .eth .getTransactionCount (self .active_account .address )
133-
134- if self ._fee_currency :
135- gas = gas if gas else self ._gas
136- gas_price = self ._gas_price if self ._gas_price else self .get_network_gas_price ()
137- base_rows = {'nonce' : nonce , 'gasPrice' : gas_price , 'gas' : gas ,
138- 'feeCurrency' : self ._fee_currency , 'from' : self .active_account .address }
139- else :
132+ if not self ._fee_currency :
140133 raise ValueError (
141134 "Can't construct transaction without fee currency, set fee currency please" )
142135
136+ nonce = self .web3 .eth .getTransactionCount (self .active_account .address )
137+ gas_price = self ._gas_price if self ._gas_price else self .get_network_gas_price ()
138+ base_rows = {'nonce' : nonce , 'gasPrice' : gas_price , 'gas' : self ._gas ,
139+ 'feeCurrency' : self ._fee_currency , 'from' : self .active_account .address }
140+
143141 if self ._gateway_fee_recipient :
144142 base_rows ['gatewayFeeRecipient' ] = self ._gateway_fee_recipient
145143
146144 if self ._gateway_fee :
147145 base_rows ['gatewayFee' ] = self ._gateway_fee
146+
147+ if parameters :
148+ for k , item in parameters .items ():
149+ base_rows [k ] = item
148150
149151 tx = contract_method .buildTransaction (base_rows )
150152
151- if value :
152- tx ['value' ] = value
153-
154153 return tx
155154 except :
156155 raise Exception (
@@ -191,19 +190,19 @@ def construct_and_sign_transaction(self, contract_method: web3._utils.datatypes)
191190 raise Exception (
192191 f"Error while sign transaction: { sys .exc_info ()[1 ]} " )
193192
194- def send_transaction (self , contract_method : web3 ._utils .datatypes , gas : int = None , value : int = 0 ) -> str :
193+ def send_transaction (self , contract_method : web3 ._utils .datatypes , parameters : dict = None ) -> str :
195194 """
196195 Takes contract method call object, call method to build transaction and push it to the blockchain
197196
198197 Parameters:
199198 contract_method: web3._utils.datatypes
200199 object of contract method call
201- gas: int (optional)
200+ parameters: dict (optional)
202201 Returns:
203202 hash of sended transaction
204203 """
205204 try :
206- tx = self .construct_transaction (contract_method , gas = gas )
205+ tx = self .construct_transaction (contract_method , parameters )
207206 signed_tx = self .sign_transaction (tx )
208207 return self .push_tx_to_blockchain (signed_tx .rawTransaction )
209208 except ValueError as e :
@@ -212,7 +211,7 @@ def send_transaction(self, contract_method: web3._utils.datatypes, gas: int = No
212211 print (
213212 "Got error about too low gas value. Increase gas value and try to send it again." )
214213 gas = gas + self .gas_increase_step if gas else self ._gas + self .gas_increase_step
215- self .send_transaction (contract_method , gas )
214+ self .send_transaction (contract_method , parameters = { ' gas' : gas } )
216215 else :
217216 raise ValueError (error_message )
218217 except :
0 commit comments