From 0ffffd99cf4d5526c970a3d6cfc83e9ec7ae84d9 Mon Sep 17 00:00:00 2001 From: laruh Date: Sun, 1 Dec 2024 20:13:31 +0700 Subject: [PATCH] require BlockNumber field in call_request func, use BlockNumber::Pending in payment_status_v2, leave todo in legacy payment_status to use BlockNumber::Pending instead of Latest --- mm2src/coins/eth.rs | 28 +++++++++++++++++++--------- mm2src/coins/eth/eth_swap_v2/mod.rs | 14 ++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index e88230758b..be08e3471f 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -4568,7 +4568,9 @@ impl EthCoin { let function = ERC20_CONTRACT.function("balanceOf")?; let data = function.encode_input(&[Token::Address(address)])?; - let res = coin.call_request(address, *token_addr, None, Some(data.into())).await?; + let res = coin + .call_request(address, *token_addr, None, Some(data.into()), BlockNumber::Latest) + .await?; let decoded = function.decode_output(&res.0)?; match decoded[0] { Token::Uint(number) => Ok(number), @@ -4632,7 +4634,7 @@ impl EthCoin { let function = ERC20_CONTRACT.function("balanceOf")?; let data = function.encode_input(&[Token::Address(address)])?; let res = self - .call_request(address, token_address, None, Some(data.into())) + .call_request(address, token_address, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&res.0)?; @@ -4659,7 +4661,7 @@ impl EthCoin { let my_address = self.derivation_method.single_addr_or_err().await?; let data = function.encode_input(&[Token::Address(my_address), Token::Uint(token_id_u256)])?; let result = self - .call_request(my_address, token_addr, None, Some(data.into())) + .call_request(my_address, token_addr, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&result.0)?; match decoded[0] { @@ -4690,7 +4692,7 @@ impl EthCoin { let data = function.encode_input(&[Token::Uint(token_id_u256)])?; let my_address = self.derivation_method.single_addr_or_err().await?; let result = self - .call_request(my_address, token_addr, None, Some(data.into())) + .call_request(my_address, token_addr, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&result.0)?; match decoded[0] { @@ -4768,6 +4770,7 @@ impl EthCoin { to: Address, value: Option, data: Option, + block_number: BlockNumber, ) -> Result { let request = CallRequest { from: Some(from), @@ -4779,7 +4782,7 @@ impl EthCoin { ..CallRequest::default() }; - self.call(request, Some(BlockId::Number(BlockNumber::Latest))).await + self.call(request, Some(BlockId::Number(block_number))).await } fn allowance(&self, spender: Address) -> Web3RpcFut { @@ -4795,7 +4798,7 @@ impl EthCoin { let data = function.encode_input(&[Token::Address(my_address), Token::Address(spender)])?; let res = coin - .call_request(my_address, *token_addr, None, Some(data.into())) + .call_request(my_address, *token_addr, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&res.0)?; @@ -5228,9 +5231,16 @@ impl EthCoin { .single_addr_or_err() .await .map_err(|e| ERRL!("{}", e))?; - coin.call_request(my_address, swap_contract_address, None, Some(data.into())) - .await - .map_err(|e| ERRL!("{}", e)) + coin.call_request( + my_address, + swap_contract_address, + None, + Some(data.into()), + // TODO worth changing this to BlockNumber::Pending + BlockNumber::Latest, + ) + .await + .map_err(|e| ERRL!("{}", e)) }; Box::new(fut.boxed().compat().and_then(move |bytes| { diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index 798a232d56..0b903a9b78 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -7,7 +7,7 @@ use futures::compat::Future01CompatExt; use mm2_err_handle::mm_error::MmError; use mm2_number::BigDecimal; use num_traits::Signed; -use web3::types::Transaction as Web3Tx; +use web3::types::{BlockNumber, Transaction as Web3Tx}; pub(crate) mod eth_maker_swap_v2; pub(crate) mod eth_taker_swap_v2; @@ -82,7 +82,13 @@ impl EthCoin { let function = contract_abi.function(function_name)?; let data = function.encode_input(&[swap_id])?; let bytes = self - .call_request(self.my_addr().await, swap_address, None, Some(data.into())) + .call_request( + self.my_addr().await, + swap_address, + None, + Some(data.into()), + BlockNumber::Pending, + ) .await?; let decoded_tokens = function.decode_output(&bytes.0)?; @@ -133,8 +139,8 @@ pub(crate) fn validate_from_to_and_status( ) -> Result<(), MmError> { if status != U256::from(expected_status) { return MmError::err(ValidatePaymentV2Err::UnexpectedPaymentState(format!( - "Payment state is not `PaymentSent`, got {}", - status + "tx {:?} Payment state is not `PaymentSent`, got {}", + tx_from_rpc.hash, status ))); } if tx_from_rpc.from != Some(expected_from) {