@@ -7,15 +7,15 @@ use graph::{
7
7
blockchain:: {
8
8
self , Block as BlockchainBlock , BlockPtr , BlockTime , ChainStoreBlock , ChainStoreData ,
9
9
} ,
10
+ components:: ethereum:: { AnyBlock , AnyHeader , AnyRpcHeader , AnyRpcTransaction , AnyTxEnvelope } ,
10
11
prelude:: {
11
12
alloy:: {
12
13
self ,
13
- consensus:: { ReceiptEnvelope , ReceiptWithBloom , TxEnvelope , TxType } ,
14
+ consensus:: { ReceiptWithBloom , TxEnvelope , TxType } ,
15
+ network:: AnyReceiptEnvelope ,
14
16
primitives:: { aliases:: B2048 , Address , Bloom , Bytes , LogData , B256 , U256 } ,
15
- rpc:: types:: {
16
- AccessList , AccessListItem , Block as AlloyBlock , Transaction ,
17
- TransactionReceipt as AlloyTransactionReceipt ,
18
- } ,
17
+ rpc:: types:: { self as alloy_rpc_types, AccessList , AccessListItem , Transaction } ,
18
+ serde:: WithOtherFields ,
19
19
} ,
20
20
BlockNumber , Error , EthereumBlock , EthereumBlockWithCalls , EthereumCall ,
21
21
LightEthereumBlock ,
@@ -378,10 +378,10 @@ impl TryInto<BlockFinality> for &Block {
378
378
}
379
379
}
380
380
381
- impl TryInto < AlloyBlock > for & Block {
381
+ impl TryInto < AnyBlock > for & Block {
382
382
type Error = Error ;
383
383
384
- fn try_into ( self ) -> Result < AlloyBlock , Self :: Error > {
384
+ fn try_into ( self ) -> Result < AnyBlock , Self :: Error > {
385
385
let header = self . header ( ) ;
386
386
387
387
let block_hash = self . hash . try_decode_proto ( "block hash" ) ?;
@@ -466,19 +466,31 @@ impl TryInto<AlloyBlock> for &Block {
466
466
. map ( |u| u. hash . try_decode_proto ( "uncle hash" ) )
467
467
. collect :: < Result < Vec < B256 > , _ > > ( ) ?;
468
468
469
- Ok ( AlloyBlock :: new (
470
- rpc_header,
471
- alloy:: rpc:: types:: BlockTransactions :: Full ( transactions) ,
472
- )
473
- . with_uncles ( uncles) )
469
+ use alloy:: rpc:: types:: Block ;
470
+
471
+ let any_header: AnyRpcHeader = rpc_header. map ( AnyHeader :: from) ;
472
+
473
+ let any_transactions: Vec < AnyRpcTransaction > = transactions
474
+ . into_iter ( )
475
+ . map ( |tx| AnyRpcTransaction :: new ( WithOtherFields :: new ( tx. map ( AnyTxEnvelope :: Ethereum ) ) ) )
476
+ . collect ( ) ;
477
+
478
+ let any_block = Block {
479
+ header : any_header,
480
+ transactions : alloy:: rpc:: types:: BlockTransactions :: Full ( any_transactions) ,
481
+ uncles,
482
+ withdrawals : None ,
483
+ } ;
484
+
485
+ Ok ( AnyBlock :: new ( WithOtherFields :: new ( any_block) ) )
474
486
}
475
487
}
476
488
477
489
impl TryInto < EthereumBlockWithCalls > for & Block {
478
490
type Error = Error ;
479
491
480
492
fn try_into ( self ) -> Result < EthereumBlockWithCalls , Self :: Error > {
481
- let alloy_block: AlloyBlock = self . try_into ( ) ?;
493
+ let alloy_block: AnyBlock = self . try_into ( ) ?;
482
494
483
495
let transaction_receipts = self
484
496
. transaction_traces
@@ -494,7 +506,7 @@ impl TryInto<EthereumBlockWithCalls> for &Block {
494
506
#[ allow( unreachable_code) ]
495
507
let block = EthereumBlockWithCalls {
496
508
ethereum_block : EthereumBlock {
497
- block : Arc :: new ( LightEthereumBlock :: new ( alloy_block. into ( ) ) ) ,
509
+ block : Arc :: new ( LightEthereumBlock :: new ( alloy_block) ) ,
498
510
transaction_receipts,
499
511
} ,
500
512
// Comment (437a9f17-67cc-478f-80a3-804fe554b227): This Some() will avoid calls in the triggers_in_block
@@ -521,7 +533,7 @@ impl TryInto<EthereumBlockWithCalls> for &Block {
521
533
fn transaction_trace_to_alloy_txn_reciept (
522
534
t : & TransactionTrace ,
523
535
block : & Block ,
524
- ) -> Result < Option < AlloyTransactionReceipt < ReceiptEnvelope < alloy:: rpc :: types :: Log > > > , Error > {
536
+ ) -> Result < Option < alloy:: network :: AnyTransactionReceipt > , Error > {
525
537
use alloy:: consensus:: { Eip658Value , Receipt } ;
526
538
let r = t. receipt . as_ref ( ) ;
527
539
@@ -600,15 +612,20 @@ fn transaction_trace_to_alloy_txn_reciept(
600
612
)
601
613
} ) ?;
602
614
603
- let envelope = match tx_type {
604
- TxType :: Legacy => ReceiptEnvelope :: Legacy ( receipt_with_bloom) ,
605
- TxType :: Eip2930 => ReceiptEnvelope :: Eip2930 ( receipt_with_bloom) ,
606
- TxType :: Eip1559 => ReceiptEnvelope :: Eip1559 ( receipt_with_bloom) ,
607
- TxType :: Eip4844 => ReceiptEnvelope :: Eip4844 ( receipt_with_bloom) ,
608
- TxType :: Eip7702 => ReceiptEnvelope :: Eip7702 ( receipt_with_bloom) ,
615
+ let ty = match tx_type {
616
+ TxType :: Legacy => 0 ,
617
+ TxType :: Eip2930 => 1 ,
618
+ TxType :: Eip1559 => 2 ,
619
+ TxType :: Eip4844 => 3 ,
620
+ TxType :: Eip7702 => 4 ,
621
+ } ;
622
+
623
+ let any_envelope = AnyReceiptEnvelope {
624
+ inner : receipt_with_bloom,
625
+ r#type : ty,
609
626
} ;
610
627
611
- Ok ( Some ( AlloyTransactionReceipt {
628
+ let receipt = alloy_rpc_types :: TransactionReceipt {
612
629
transaction_hash : t. hash . try_decode_proto ( "transaction hash" ) ?,
613
630
transaction_index : Some ( t. index as u64 ) ,
614
631
block_hash : Some ( block. hash . try_decode_proto ( "transaction block hash" ) ?) ,
@@ -626,8 +643,10 @@ fn transaction_trace_to_alloy_txn_reciept(
626
643
let val: U256 = x. into ( ) ;
627
644
val. to :: < u128 > ( )
628
645
} ) ,
629
- inner : envelope,
630
- } ) )
646
+ inner : any_envelope,
647
+ } ;
648
+
649
+ Ok ( Some ( WithOtherFields :: new ( receipt) ) )
631
650
}
632
651
633
652
impl BlockHeader {
0 commit comments