diff --git a/crates/core/src/models/test_data/conversion/eth/transaction.json b/crates/core/src/models/test_data/conversion/eth/transaction.json index d734f9623..721de80b5 100644 --- a/crates/core/src/models/test_data/conversion/eth/transaction.json +++ b/crates/core/src/models/test_data/conversion/eth/transaction.json @@ -9,5 +9,6 @@ "value": "0x64", "gas": "0x64", "maxPriorityFeePerGas": "0x0", - "input": "0x608060405234801561001057600080fd5b506000805561023c806100246000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806306661abd14610067578063371303c0146100825780637c507cbd1461008c578063b3bcfa8214610094578063d826f88f1461009c578063f0707ea9146100a5575b600080fd5b61007060005481565b60405190815260200160405180910390f35b61008a6100ad565b005b61008a6100c6565b61008a610106565b61008a60008055565b61008a610139565b60016000808282546100bf919061017c565b9091555050565b60008054116100f05760405162461bcd60e51b81526004016100e790610195565b60405180910390fd5b6000805490806100ff836101dc565b9190505550565b60008054116101275760405162461bcd60e51b81526004016100e790610195565b60016000808282546100bf91906101f3565b600080541161015a5760405162461bcd60e51b81526004016100e790610195565b60008054600019019055565b634e487b7160e01b600052601160045260246000fd5b8082018082111561018f5761018f610166565b92915050565b60208082526027908201527f636f756e742073686f756c64206265207374726963746c7920677265617465726040820152660207468616e20360cc1b606082015260800190565b6000816101eb576101eb610166565b506000190190565b8181038181111561018f5761018f61016656fea26469706673582212203091d34e6cbebc53198d4c0d09786b51423a7ae0de314456c74c68aaccc311e364736f6c63430008110033" + "input": "0x608060405234801561001057600080fd5b506000805561023c806100246000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806306661abd14610067578063371303c0146100825780637c507cbd1461008c578063b3bcfa8214610094578063d826f88f1461009c578063f0707ea9146100a5575b600080fd5b61007060005481565b60405190815260200160405180910390f35b61008a6100ad565b005b61008a6100c6565b61008a610106565b61008a60008055565b61008a610139565b60016000808282546100bf919061017c565b9091555050565b60008054116100f05760405162461bcd60e51b81526004016100e790610195565b60405180910390fd5b6000805490806100ff836101dc565b9190505550565b60008054116101275760405162461bcd60e51b81526004016100e790610195565b60016000808282546100bf91906101f3565b600080541161015a5760405162461bcd60e51b81526004016100e790610195565b60008054600019019055565b634e487b7160e01b600052601160045260246000fd5b8082018082111561018f5761018f610166565b92915050565b60208082526027908201527f636f756e742073686f756c64206265207374726963746c7920677265617465726040820152660207468616e20360cc1b606082015260800190565b6000816101eb576101eb610166565b506000190190565b8181038181111561018f5761018f61016656fea26469706673582212203091d34e6cbebc53198d4c0d09786b51423a7ae0de314456c74c68aaccc311e364736f6c63430008110033", + "blockNumber": "0x4d2" } diff --git a/crates/core/src/models/transaction.rs b/crates/core/src/models/transaction.rs index 0fa7007ad..3c55f3929 100644 --- a/crates/core/src/models/transaction.rs +++ b/crates/core/src/models/transaction.rs @@ -1,8 +1,10 @@ use async_trait::async_trait; use reth_primitives::{TransactionSigned, H256, U256}; use reth_rpc_types::{Signature, Transaction as EthTransaction}; -use starknet::core::types::{BlockId as StarknetBlockId, BlockTag, FieldElement, InvokeTransaction, Transaction}; -use starknet::providers::Provider; +use starknet::core::types::{ + BlockId as StarknetBlockId, BlockTag, FieldElement, InvokeTransaction, StarknetError, Transaction, +}; +use starknet::providers::{MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage}; use super::felt::Felt252Wrapper; use super::ConversionError; @@ -80,14 +82,28 @@ impl ConvertibleStarknetTransaction for StarknetTransaction { let hash: H256 = self.transaction_hash()?.into(); - let nonce: U256 = match &self.0 { + let starknet_block_id = match block_hash { + Some(block_hash) => StarknetBlockId::Hash(TryInto::::try_into(block_hash)?.into()), + None => match block_number { + Some(block_number) => StarknetBlockId::Number(block_number.as_limbs()[0]), + None => { + return Err(EthApiError::RequestError(ProviderError::StarknetError(StarknetErrorWithMessage { + code: MaybeUnknownErrorCode::Known(StarknetError::BlockNotFound), + message: "Block hash or block number must be provided".into(), + }))); + } + }, + }; + let nonce: Felt252Wrapper = match &self.0 { Transaction::Invoke(invoke_tx) => match invoke_tx { - InvokeTransaction::V0(_) => Felt252Wrapper::ZERO, + InvokeTransaction::V0(_) => { + client.starknet_provider().get_nonce(starknet_block_id, sender_address).await?.into() + } InvokeTransaction::V1(v1) => v1.nonce.into(), }, _ => return Err(EthApiError::KakarotDataFilteringError("Transaction".into())), - } - .into(); + }; + let nonce: U256 = nonce.into(); let from = client.get_evm_address(&sender_address, &starknet_block_latest).await?; @@ -181,7 +197,8 @@ mod tests { let client = init_mock_client(Some(fixtures)); // When - let eth_transaction = starknet_transaction.to_eth_transaction(&client, None, None, None).await.unwrap(); + let eth_transaction = + starknet_transaction.to_eth_transaction(&client, None, Some(U256::from(1234u64)), None).await.unwrap(); // Then let expected: EthTransaction = diff --git a/crates/core/src/models/transaction_receipt.rs b/crates/core/src/models/transaction_receipt.rs index a56bf7b5f..51c77e49a 100644 --- a/crates/core/src/models/transaction_receipt.rs +++ b/crates/core/src/models/transaction_receipt.rs @@ -62,7 +62,7 @@ impl ConvertibleStarknetTransactionReceipt for StarknetTransactionReceipt { let block_number: Felt252Wrapper = block_number.into(); let block_number: Option = Some(block_number.into()); - let eth_tx = starknet_tx.to_eth_transaction(client, None, None, None).await?; + let eth_tx = starknet_tx.to_eth_transaction(client, block_hash, block_number, None).await?; let from = eth_tx.from; let to = eth_tx.to; let contract_address = match to {