Skip to content

Commit

Permalink
feat: chain id hex str
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Nov 18, 2024
1 parent bb7b907 commit 3208d94
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion hdp/src/preprocessor/compile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy::hex;
use alloy::primitives::U256;
use config::CompilerConfig;
use std::hash::Hash;
Expand Down Expand Up @@ -145,7 +146,7 @@ impl CompilationResult {
.unwrap_or_default();

let processed_block = ProcessedBlockProofs::Evm(EvmBlockProofs {
chain_id,
chain_id: format!("0x{}", hex::encode(chain_id.to_be_bytes())),
mmr_with_headers: mmr_with_headers.into_iter().collect(),
accounts: accounts.into_iter().collect(),
storages: storages.into_iter().collect(),
Expand Down
2 changes: 2 additions & 0 deletions hdp/src/preprocessor/compile/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ impl Compilable for ModuleVec {
.get(&chain_id)
.expect("target task's chain had not been configured.");
let provider = new_provider_from_config(target_provider_config);

// TODO: handle starknet
let results = provider
.fetch_proofs_from_keys(keys)
.await?
Expand Down
10 changes: 5 additions & 5 deletions hdp/src/primitives/processed_types/block_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub enum ProcessedBlockProofs {
}

impl ProcessedBlockProofs {
pub fn get_chain_id(&self) -> u128 {
pub fn get_chain_id(&self) -> String {
match self {
ProcessedBlockProofs::Evm(evm) => evm.chain_id,
ProcessedBlockProofs::StarkNet(starknet) => starknet.chain_id,
ProcessedBlockProofs::Evm(evm) => evm.chain_id.to_owned(),
ProcessedBlockProofs::StarkNet(starknet) => starknet.chain_id.to_owned(),
}
}

Expand All @@ -39,7 +39,7 @@ impl ProcessedBlockProofs {

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct StarkNetBlockProofs {
pub chain_id: u128,
pub chain_id: String,
pub mmr_with_headers: Vec<MMRWithHeaderStarkNet>,
pub storages: Vec<starknet::storage::ProcessedStorage>,
// Since accounts, transactions, and transaction_receipts do not exist for StarkNet,
Expand All @@ -57,7 +57,7 @@ pub struct MMRWithHeaderStarkNet {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct EvmBlockProofs {
pub chain_id: u128,
pub chain_id: String,
pub mmr_with_headers: Vec<MMRWithHeader>,
pub accounts: Vec<ProcessedAccount>,
pub storages: Vec<ProcessedStorage>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl AsCairoFormat for BaseProcessedBlockProofs {

#[derive(Serialize, Deserialize)]
pub struct ProcessedBlockProofs {
pub chain_id: u128,
pub chain_id: String,
pub mmr_with_headers: Vec<MMRWithHeader>,
pub accounts: Vec<ProcessedAccount>,
pub storages: Vec<ProcessedStorage>,
Expand Down
3 changes: 2 additions & 1 deletion hdp/src/provider/evm/from_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::provider::key::{
CategorizedFetchKeys, EvmAccountKey, EvmBlockReceiptKey, EvmBlockTxKey, EvmHeaderKey,
EvmStorageKey,
};
use alloy::hex;
use alloy::primitives::{Address, BlockNumber, Bytes, TxIndex, B256};
use alloy::transports::{RpcError, TransportErrorKind};
use eth_trie_proofs::tx_receipt_trie::TxReceiptsMptHandler;
Expand Down Expand Up @@ -56,7 +57,7 @@ impl EvmProvider {
accounts.extend(accounts_from_storage_key);
let accounts_result: Vec<ProcessedAccount> = accounts.into_iter().collect();
Ok(ProcessedBlockProofs::Evm(EvmBlockProofs {
chain_id,
chain_id: format!("0x{}", hex::encode(chain_id.to_be_bytes())),
mmr_with_headers: convert_to_mmr_with_headers(mmr_with_headers),
accounts: accounts_result,
storages: storages.into_iter().collect(),
Expand Down
3 changes: 2 additions & 1 deletion hdp/src/provider/starknet/from_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
time::Instant,
};

use alloy::hex;
use starknet_crypto::Felt;
use tracing::info;

Expand Down Expand Up @@ -37,7 +38,7 @@ impl StarknetProvider {
};

Ok(ProcessedBlockProofs::StarkNet(StarkNetBlockProofs {
chain_id,
chain_id: format!("0x{}", hex::encode(chain_id.to_be_bytes())),
mmr_with_headers: convert_to_mmr_with_sn_headers(mmr_with_headers),
storages: storages.into_iter().collect(),
}))
Expand Down

0 comments on commit 3208d94

Please sign in to comment.