Skip to content

Commit

Permalink
fix: bump cainome and revert temporary fix (#1019)
Browse files Browse the repository at this point in the history
* bump cainome and revert temporary fix

* fix lints

* limit chain id value

---------

Co-authored-by: Gregory Edison <[email protected]>
  • Loading branch information
0xicosahedron and greged93 authored Apr 26, 2024
1 parent 472bcfb commit 76bdd73
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 43 deletions.
101 changes: 90 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use_self = "allow"

[dependencies]
# Starknet dependencies
cainome = { git = "https://github.com/cartridge-gg/cainome.git", tag = "v0.2.5", default-features = false, features = [
cainome = { git = "https://github.com/cartridge-gg/cainome.git", tag = "v0.2.6", default-features = false, features = [
"abigen-rs",
] }
cairo-lang-starknet = { version = "2.5.4", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion src/eth_provider/database/types/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> StoredHeader {
gas_limit: u64::arbitrary(u).unwrap() as u128,
gas_used: u64::arbitrary(u).unwrap() as u128,
number: Some(u64::arbitrary(u).unwrap()),
..Self::arbitrary(u)?.header
..Header::arbitrary(u)?
},
})
}
Expand Down
1 change: 1 addition & 0 deletions src/eth_provider/database/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<'a> StoredTransaction {
..reth_rpc_types::Signature::arbitrary(u)?
}),
transaction_type: Some(transaction_type),
chain_id: Some(u32::arbitrary(u)? as u64),
other: Default::default(),
access_list: Some(reth_rpc_types::AccessList::arbitrary(u)?),
..transaction
Expand Down
41 changes: 11 additions & 30 deletions src/eth_provider/provider.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::eth_provider::starknet::kakarot_core::account_contract::BytecodeOutput;
use crate::models::transaction::rpc_to_primitive_transaction;
use alloy_rlp::{Decodable, Encodable};
use async_trait::async_trait;
use auto_impl::auto_impl;
use cainome::cairo_serde::CairoArrayLegacy;
use cainome::cairo_serde::CairoSerde;
use eyre::Result;
use itertools::Itertools;
use mongodb::bson::doc;
Expand All @@ -19,8 +16,8 @@ use reth_rpc_types::{
};
use reth_rpc_types::{SyncInfo, SyncStatus};
use reth_rpc_types_compat::transaction::from_recovered;
use starknet::core::types::{FunctionCall, SyncStatusType};
use starknet::core::utils::{get_selector_from_name, get_storage_var_address};
use starknet::core::types::SyncStatusType;
use starknet::core::utils::get_storage_var_address;
use starknet_crypto::FieldElement;

use super::constant::{CALL_REQUEST_GAS_LIMIT, HASH_PADDING, MAX_RETRIES, U64_PADDING};
Expand All @@ -42,6 +39,7 @@ use super::utils::{contract_not_found, entrypoint_not_found, into_filter, split_
use crate::eth_provider::utils::format_hex;
use crate::models::block::{EthBlockId, EthBlockNumberOrTag};
use crate::models::felt::Felt252Wrapper;
use crate::models::transaction::rpc_to_primitive_transaction;
use crate::{into_via_try_wrapper, into_via_wrapper};

pub type EthProviderResult<T> = Result<T, EthApiError>;
Expand Down Expand Up @@ -368,36 +366,18 @@ where
}

async fn get_code(&self, address: Address, block_id: Option<BlockId>) -> EthProviderResult<Bytes> {
// TODO: temporary fix to handle empty bytecode until
// https://github.com/cartridge-gg/cainome/issues/24 is solved
let bytecode = self
.starknet_provider
.call(
FunctionCall {
contract_address: starknet_address(address),
entry_point_selector: get_selector_from_name("bytecode").unwrap(),
calldata: Default::default(),
},
self.to_starknet_block_id(block_id).await?,
)
.await
.map_err(cainome::cairo_serde::Error::Provider);

if contract_not_found(&bytecode) || entrypoint_not_found(&bytecode) {
return Ok(Bytes::default());
}
let starknet_block_id = self.to_starknet_block_id(block_id).await?;

let bytecode_raw = bytecode.map_err(KakarotError::from)?;
let address = starknet_address(address);
let account_contract = AccountContractReader::new(address, &self.starknet_provider);
let bytecode = account_contract.bytecode().block_id(starknet_block_id).call().await;

// If the bytecode is empty, return an empty Bytes
if bytecode_raw.len() == 1 && bytecode_raw[0] == FieldElement::ZERO {
if contract_not_found(&bytecode) || entrypoint_not_found(&bytecode) {
return Ok(Bytes::default());
}

// Deserialize the bytecode
Ok(Bytes::from(try_from_u8_iterator::<_, Vec<u8>>(
BytecodeOutput::cairo_deserialize(&bytecode_raw, 0).map_err(KakarotError::from)?.bytecode.0,
)))
let bytecode = bytecode.map_err(KakarotError::from)?.bytecode.0;
Ok(Bytes::from(try_from_u8_iterator::<_, Vec<u8>>(bytecode)))
}

async fn get_logs(&self, filter: Filter) -> EthProviderResult<FilterChanges> {
Expand Down Expand Up @@ -918,6 +898,7 @@ where
use crate::eth_provider::constant::{DEPLOY_WALLET, DEPLOY_WALLET_NONCE};
use starknet::accounts::{Call, Execution};
use starknet::core::types::BlockTag;
use starknet::core::utils::get_selector_from_name;

let signer_starknet_address = starknet_address(signer);
let account_contract = AccountContractReader::new(signer_starknet_address, &self.starknet_provider);
Expand Down

0 comments on commit 76bdd73

Please sign in to comment.