@@ -2,7 +2,11 @@ use super::runtime_adapter::UnresolvedContractCall;
22use crate :: trigger:: {
33 EthereumBlockData , EthereumCallData , EthereumEventData , EthereumTransactionData ,
44} ;
5+ use anyhow:: anyhow;
56use graph:: abi;
7+ use graph:: prelude:: alloy;
8+ use graph:: prelude:: alloy:: network:: ReceiptResponse ;
9+ use graph:: prelude:: alloy:: primitives:: B256 ;
610use graph:: {
711 prelude:: {
812 web3:: types:: { Log , TransactionReceipt , H256 } ,
@@ -82,6 +86,20 @@ impl ToAscObj<AscTopicArray> for Vec<H256> {
8286 }
8387}
8488
89+ impl ToAscObj < AscTopicArray > for & [ alloy:: primitives:: B256 ] {
90+ fn to_asc_obj < H : AscHeap + ?Sized > (
91+ & self ,
92+ heap : & mut H ,
93+ gas : & GasCounter ,
94+ ) -> Result < AscTopicArray , HostExportError > {
95+ let topics = self
96+ . iter ( )
97+ . map ( |topic| asc_new ( heap, topic, gas) )
98+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
99+ Ok ( AscTopicArray ( Array :: new ( & topics, heap, gas) ?) )
100+ }
101+ }
102+
85103impl AscIndexId for AscTopicArray {
86104 const INDEX_ASC_TYPE_ID : IndexForAscTypeId = IndexForAscTypeId :: ArrayH256 ;
87105}
@@ -101,6 +119,20 @@ impl AscType for AscLogArray {
101119 }
102120}
103121
122+ impl ToAscObj < AscLogArray > for & [ alloy:: rpc:: types:: Log ] {
123+ fn to_asc_obj < H : AscHeap + ?Sized > (
124+ & self ,
125+ heap : & mut H ,
126+ gas : & GasCounter ,
127+ ) -> Result < AscLogArray , HostExportError > {
128+ let logs = self
129+ . iter ( )
130+ . map ( |log| asc_new ( heap, & log, gas) )
131+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
132+ Ok ( AscLogArray ( Array :: new ( & logs, heap, gas) ?) )
133+ }
134+ }
135+
104136impl ToAscObj < AscLogArray > for Vec < Log > {
105137 fn to_asc_obj < H : AscHeap + ?Sized > (
106138 & self ,
@@ -627,6 +659,50 @@ where
627659 }
628660}
629661
662+ impl < ' a , T , B > ToAscObj < AscEthereumEvent_0_0_7 < T , B > >
663+ for (
664+ EthereumEventData < ' a > ,
665+ Option < & alloy:: rpc:: types:: TransactionReceipt > ,
666+ )
667+ where
668+ T : AscType + AscIndexId ,
669+ B : AscType + AscIndexId ,
670+ EthereumTransactionData < ' a > : ToAscObj < T > ,
671+ EthereumBlockData < ' a > : ToAscObj < B > ,
672+ {
673+ fn to_asc_obj < H : AscHeap + ?Sized > (
674+ & self ,
675+ heap : & mut H ,
676+ gas : & GasCounter ,
677+ ) -> Result < AscEthereumEvent_0_0_7 < T , B > , HostExportError > {
678+ let ( event_data, optional_receipt) = self ;
679+ let AscEthereumEvent {
680+ address,
681+ log_index,
682+ transaction_log_index,
683+ log_type,
684+ block,
685+ transaction,
686+ params,
687+ } = event_data. to_asc_obj ( heap, gas) ?;
688+ let receipt = if let Some ( receipt_data) = optional_receipt {
689+ asc_new ( heap, receipt_data, gas) ?
690+ } else {
691+ AscPtr :: null ( )
692+ } ;
693+ Ok ( AscEthereumEvent_0_0_7 {
694+ address,
695+ log_index,
696+ transaction_log_index,
697+ log_type,
698+ block,
699+ transaction,
700+ params,
701+ receipt,
702+ } )
703+ }
704+ }
705+
630706impl ToAscObj < AscEthereumLog > for Log {
631707 fn to_asc_obj < H : AscHeap + ?Sized > (
632708 & self ,
@@ -674,6 +750,92 @@ impl ToAscObj<AscEthereumLog> for Log {
674750 }
675751}
676752
753+ impl ToAscObj < AscEthereumLog > for alloy:: rpc:: types:: Log {
754+ fn to_asc_obj < H : AscHeap + ?Sized > (
755+ & self ,
756+ heap : & mut H ,
757+ gas : & GasCounter ,
758+ ) -> Result < AscEthereumLog , HostExportError > {
759+ Ok ( AscEthereumLog {
760+ address : asc_new ( heap, & self . address ( ) , gas) ?,
761+ topics : asc_new ( heap, & self . topics ( ) , gas) ?,
762+ data : asc_new ( heap, self . data ( ) . data . as_ref ( ) , gas) ?,
763+ block_hash : self
764+ . block_hash
765+ . map ( |block_hash| asc_new ( heap, & block_hash, gas) )
766+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
767+ block_number : self
768+ . block_number
769+ . map ( |block_number| asc_new ( heap, & BigInt :: from ( block_number) , gas) )
770+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
771+ transaction_hash : self
772+ . transaction_hash
773+ . map ( |txn_hash| asc_new ( heap, & txn_hash, gas) )
774+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
775+ transaction_index : self
776+ . transaction_index
777+ . map ( |txn_index| asc_new ( heap, & BigInt :: from ( txn_index) , gas) )
778+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
779+ log_index : self
780+ . log_index
781+ . map ( |log_index| asc_new ( heap, & BigInt :: from ( log_index) , gas) )
782+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
783+ transaction_log_index : AscPtr :: null ( ) , // TODO(alloy): figure out how to get transaction log index
784+ log_type : AscPtr :: null ( ) , // TODO(alloy): figure out how to get log type
785+ removed : asc_new (
786+ heap,
787+ & AscWrapped {
788+ inner : self . removed ,
789+ } ,
790+ gas,
791+ ) ?,
792+ } )
793+ }
794+ }
795+
796+ impl ToAscObj < AscEthereumTransactionReceipt > for & alloy:: rpc:: types:: TransactionReceipt {
797+ fn to_asc_obj < H : AscHeap + ?Sized > (
798+ & self ,
799+ heap : & mut H ,
800+ gas : & GasCounter ,
801+ ) -> Result < AscEthereumTransactionReceipt , HostExportError > {
802+ Ok ( AscEthereumTransactionReceipt {
803+ transaction_hash : asc_new ( heap, & self . transaction_hash , gas) ?,
804+ transaction_index : asc_new (
805+ heap,
806+ & BigInt :: from (
807+ self . transaction_index
808+ . ok_or ( HostExportError :: Unknown ( anyhow ! (
809+ "Transaction index is missing"
810+ ) ) ) ?,
811+ ) ,
812+ gas,
813+ ) ?,
814+ block_hash : self
815+ . block_hash
816+ . map ( |block_hash| asc_new ( heap, & block_hash, gas) )
817+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
818+ block_number : self
819+ . block_number
820+ . map ( |block_number| asc_new ( heap, & BigInt :: from ( block_number) , gas) )
821+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
822+ cumulative_gas_used : asc_new ( heap, & BigInt :: from ( self . gas_used ) , gas) ?,
823+ gas_used : asc_new ( heap, & BigInt :: from ( self . gas_used ) , gas) ?,
824+ contract_address : self
825+ . contract_address
826+ . map ( |contract_address| asc_new ( heap, & contract_address, gas) )
827+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
828+ logs : asc_new ( heap, & self . logs ( ) , gas) ?,
829+ status : asc_new ( heap, & BigInt :: from ( self . status ( ) as u64 ) , gas) ?,
830+ root : self
831+ . state_root ( )
832+ . map ( |root| asc_new ( heap, & root, gas) )
833+ . unwrap_or ( Ok ( AscPtr :: null ( ) ) ) ?,
834+ logs_bloom : asc_new ( heap, self . inner . logs_bloom ( ) . as_slice ( ) , gas) ?,
835+ } )
836+ }
837+ }
838+
677839impl ToAscObj < AscEthereumTransactionReceipt > for & TransactionReceipt {
678840 fn to_asc_obj < H : AscHeap + ?Sized > (
679841 & self ,
0 commit comments