Skip to content

Commit

Permalink
feat: clean to_eth_transaction_receipt (#701)
Browse files Browse the repository at this point in the history
replace events parsing with create_address call
  • Loading branch information
greged93 authored Jan 10, 2024
1 parent a6304b0 commit 6164ee0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ lint:
- shfmt@3.6.0
- taplo@0.8.1
- terrascan@1.18.11
- trivy@0.48.1
- trufflehog@3.63.7
- trivy@0.48.2
- trufflehog@3.63.8
- yamllint@1.33.0
actions:
disabled:
Expand Down
22 changes: 2 additions & 20 deletions src/models/transaction_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use reth_primitives::contract::create_address;
use reth_primitives::{Bloom, H256, U128, U256, U64, U8};
use reth_rpc_types::TransactionReceipt as EthTransactionReceipt;
use starknet::core::types::{
Expand All @@ -8,9 +9,7 @@ use starknet::providers::Provider;
use super::event::StarknetEvent;
use super::felt::Felt252Wrapper;
use super::transaction::transaction::StarknetTransaction;
use crate::starknet_client::constants::selectors::EVM_CONTRACT_DEPLOYED;
use crate::starknet_client::errors::EthApiError;
use crate::starknet_client::helpers::DataDecodingError;
use crate::starknet_client::KakarotClient;

pub struct StarknetTransactionReceipt(MaybePendingTransactionReceipt);
Expand Down Expand Up @@ -65,24 +64,7 @@ impl StarknetTransactionReceipt {
// If to is Some, means contract_address should be None as it is a normal transaction
Some(_) => None,
// If to is None, is a contract creation transaction so contract_address should be Some
None => {
let event = events
.iter()
.find(|event| event.keys.iter().any(|key| *key == EVM_CONTRACT_DEPLOYED))
.ok_or(EthApiError::Other(anyhow::anyhow!(
"Kakarot Core: No contract deployment event found in Kakarot transaction receipt"
)))?;

let evm_address =
event.data.first().ok_or(DataDecodingError::InvalidReturnArrayLength {
entrypoint: "deployment".into(),
expected: 1,
actual: 0,
})?;

let evm_address = Felt252Wrapper::from(*evm_address);
Some(evm_address.try_into()?)
}
None => Some(create_address(eth_tx.from, eth_tx.nonce.as_u64())),
}
}
ExecutionResult::Reverted { ref reason } => {
Expand Down

0 comments on commit 6164ee0

Please sign in to comment.