mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: Make deserialization work 2
This commit is contained in:
@ -1,10 +1,19 @@
|
|||||||
//! Copy of reth codebase to preserve serialization compatibility
|
//! Copy of reth codebase to preserve serialization compatibility
|
||||||
use alloy_consensus::{Header, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy};
|
use alloy_consensus::{
|
||||||
|
Header, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy, TypedTransaction,
|
||||||
|
};
|
||||||
|
use alloy_primitives::{Address, BlockHash, Signature, TxKind, U256};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::sync::{Arc, LazyLock, Mutex};
|
||||||
|
use tokio::runtime::Handle;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use alloy_primitives::{BlockHash, Signature};
|
use crate::node::spot_meta::{self, erc20_contract_to_spot_token, SpotId};
|
||||||
|
use crate::{
|
||||||
use crate::{node::types::ReadPrecompileCalls, HlBlock, HlBlockBody};
|
node::types::{ReadPrecompileCalls, SystemTx},
|
||||||
|
HlBlock, HlBlockBody,
|
||||||
|
};
|
||||||
|
|
||||||
/// A raw transaction.
|
/// A raw transaction.
|
||||||
///
|
///
|
||||||
@ -69,16 +78,69 @@ pub struct SealedBlock {
|
|||||||
body: BlockBody,
|
body: BlockBody,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn system_tx_to_reth_transaction(
|
||||||
|
transaction: &SystemTx,
|
||||||
|
chain_id: u64,
|
||||||
|
) -> reth_primitives::TransactionSigned {
|
||||||
|
static EVM_MAP: LazyLock<Arc<Mutex<BTreeMap<Address, SpotId>>>> =
|
||||||
|
LazyLock::new(|| Arc::new(Mutex::new(BTreeMap::new())));
|
||||||
|
{
|
||||||
|
let Transaction::Legacy(tx) = &transaction.tx else {
|
||||||
|
panic!("Unexpected transaction type");
|
||||||
|
};
|
||||||
|
let TxKind::Call(to) = tx.to else {
|
||||||
|
panic!("Unexpected contract creation");
|
||||||
|
};
|
||||||
|
let s = if tx.input.is_empty() {
|
||||||
|
U256::from(0x1)
|
||||||
|
} else {
|
||||||
|
loop {
|
||||||
|
if let Some(spot) = EVM_MAP.lock().unwrap().get(&to) {
|
||||||
|
break spot.to_s();
|
||||||
|
}
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Contract not found: {:?} from spot mapping, fetching again...",
|
||||||
|
to
|
||||||
|
);
|
||||||
|
let rt = Handle::current();
|
||||||
|
futures::executor::block_on(async {
|
||||||
|
rt.spawn(async move {
|
||||||
|
*EVM_MAP.lock().unwrap() =
|
||||||
|
erc20_contract_to_spot_token(chain_id).await.unwrap();
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("failed to spawn");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let signature = Signature::new(U256::from(0x1), s, true);
|
||||||
|
reth_primitives::TransactionSigned::Legacy(Signed::new_unhashed(tx.clone(), signature))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SealedBlock {
|
impl SealedBlock {
|
||||||
pub fn to_reth_block(&self, read_precompile_calls: ReadPrecompileCalls) -> HlBlock {
|
pub fn to_reth_block(
|
||||||
let block_body = HlBlockBody {
|
&self,
|
||||||
inner: reth_primitives::BlockBody {
|
read_precompile_calls: ReadPrecompileCalls,
|
||||||
transactions: self
|
system_txs: Vec<super::SystemTx>,
|
||||||
.body
|
chain_id: u64,
|
||||||
|
) -> HlBlock {
|
||||||
|
let mut merged_txs = vec![];
|
||||||
|
merged_txs.extend(
|
||||||
|
system_txs
|
||||||
|
.iter()
|
||||||
|
.map(|tx| system_tx_to_reth_transaction(tx, chain_id)),
|
||||||
|
);
|
||||||
|
merged_txs.extend(
|
||||||
|
self.body
|
||||||
.transactions
|
.transactions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tx| tx.to_reth_transaction())
|
.map(|tx| tx.to_reth_transaction()),
|
||||||
.collect(),
|
);
|
||||||
|
let block_body = HlBlockBody {
|
||||||
|
inner: reth_primitives::BlockBody {
|
||||||
|
transactions: merged_txs,
|
||||||
withdrawals: self.body.withdrawals.clone(),
|
withdrawals: self.body.withdrawals.clone(),
|
||||||
ommers: self.body.ommers.clone(),
|
ommers: self.body.ommers.clone(),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user