11use alloy_eips:: { BlockId , BlockNumberOrTag } ;
22use alloy_primitives:: Address ;
3- use alloy_rpc_types:: { AccessList , SignedAuthorization , TransactionRequest } ;
3+ use alloy_rpc_types:: {
4+ AccessList , FilterBlockOption , FilterSet , SignedAuthorization , Topic , TransactionRequest ,
5+ } ;
46use polkadot_sdk:: {
57 pallet_revive:: evm:: {
6- AccessListEntry , AuthorizationListEntry , BlockNumberOrTagOrHash , BlockTag , Byte , Bytes ,
7- GenericTransaction , InputOrData ,
8+ self , AccessListEntry , AddressOrAddresses , AuthorizationListEntry , BlockNumberOrTagOrHash ,
9+ BlockTag , Byte , Bytes , Filter , FilterTopic , FilterTopics , GenericTransaction , InputOrData ,
810 } ,
911 sp_core,
1012} ;
@@ -67,6 +69,27 @@ impl From<ReviveAddress> for Address {
6769 }
6870}
6971
72+ pub struct ReviveBlockNumberOrTag ( pub evm:: BlockNumberOrTag ) ;
73+
74+ impl From < BlockNumberOrTag > for ReviveBlockNumberOrTag {
75+ fn from ( value : BlockNumberOrTag ) -> Self {
76+ Self ( match value {
77+ BlockNumberOrTag :: Latest => evm:: BlockNumberOrTag :: BlockTag ( BlockTag :: Latest ) ,
78+ BlockNumberOrTag :: Finalized => evm:: BlockNumberOrTag :: BlockTag ( BlockTag :: Finalized ) ,
79+ BlockNumberOrTag :: Safe => evm:: BlockNumberOrTag :: BlockTag ( BlockTag :: Safe ) ,
80+ BlockNumberOrTag :: Earliest => evm:: BlockNumberOrTag :: BlockTag ( BlockTag :: Earliest ) ,
81+ BlockNumberOrTag :: Pending => evm:: BlockNumberOrTag :: BlockTag ( BlockTag :: Pending ) ,
82+ BlockNumberOrTag :: Number ( num) => evm:: BlockNumberOrTag :: U256 ( evm:: U256 :: from ( num) ) ,
83+ } )
84+ }
85+ }
86+
87+ impl ReviveBlockNumberOrTag {
88+ pub fn inner ( self ) -> evm:: BlockNumberOrTag {
89+ self . 0
90+ }
91+ }
92+
7093#[ derive( Debug , Clone ) ]
7194pub struct ReviveBlockId ( BlockNumberOrTagOrHash ) ;
7295
@@ -84,22 +107,9 @@ impl From<Option<BlockId>> for ReviveBlockId {
84107 BlockId :: Hash ( rpc_hash) => BlockNumberOrTagOrHash :: BlockHash ( H256 :: from_slice (
85108 rpc_hash. block_hash . as_slice ( ) ,
86109 ) ) ,
87- BlockId :: Number ( number_or_tag) => match number_or_tag {
88- BlockNumberOrTag :: Number ( num) => BlockNumberOrTagOrHash :: BlockNumber (
89- polkadot_sdk:: pallet_revive:: U256 :: from ( num) ,
90- ) ,
91- BlockNumberOrTag :: Latest => BlockNumberOrTagOrHash :: BlockTag ( BlockTag :: Latest ) ,
92- BlockNumberOrTag :: Earliest => {
93- BlockNumberOrTagOrHash :: BlockTag ( BlockTag :: Earliest )
94- }
95- BlockNumberOrTag :: Pending => {
96- BlockNumberOrTagOrHash :: BlockTag ( BlockTag :: Pending )
97- }
98- BlockNumberOrTag :: Safe => BlockNumberOrTagOrHash :: BlockTag ( BlockTag :: Safe ) ,
99- BlockNumberOrTag :: Finalized => {
100- BlockNumberOrTagOrHash :: BlockTag ( BlockTag :: Finalized )
101- }
102- } ,
110+ BlockId :: Number ( number_or_tag) => {
111+ ReviveBlockNumberOrTag :: from ( number_or_tag) . inner ( ) . into ( )
112+ }
103113 } ,
104114 ) )
105115 }
@@ -220,3 +230,85 @@ pub(crate) fn convert_to_generic_transaction(
220230 value : transaction_request. value . map ( |value| SubstrateU256 :: from ( value) . inner ( ) ) ,
221231 }
222232}
233+
234+ struct ReviveFilterTopics ( FilterTopics ) ;
235+
236+ impl ReviveFilterTopics {
237+ fn into_inner ( self ) -> FilterTopics {
238+ self . 0
239+ }
240+ }
241+
242+ impl From < [ Topic ; 4 ] > for ReviveFilterTopics {
243+ fn from ( value : [ Topic ; 4 ] ) -> Self {
244+ let topics: Vec < FilterTopic > = value
245+ . into_iter ( )
246+ . filter ( |t| !t. is_empty ( ) )
247+ . map ( |topic| {
248+ let hashes: Vec < H256 > =
249+ topic. into_iter ( ) . map ( |hash| H256 :: from_slice ( hash. as_ref ( ) ) ) . collect ( ) ;
250+ match hashes. len ( ) {
251+ 1 => FilterTopic :: Single ( hashes[ 0 ] ) ,
252+ _ => FilterTopic :: Multiple ( hashes) ,
253+ }
254+ } )
255+ . collect ( ) ;
256+ Self ( topics)
257+ }
258+ }
259+
260+ struct ReviveAddressOrAddresses ( AddressOrAddresses ) ;
261+
262+ impl ReviveAddressOrAddresses {
263+ fn into_inner ( self ) -> AddressOrAddresses {
264+ self . 0
265+ }
266+ }
267+
268+ impl From < FilterSet < Address > > for ReviveAddressOrAddresses {
269+ fn from ( value : FilterSet < Address > ) -> Self {
270+ let addresses: Vec < Address > = value. into_iter ( ) . collect ( ) ;
271+ let address_or_addresses = match addresses. len ( ) {
272+ 0 => AddressOrAddresses :: Address ( Default :: default ( ) ) ,
273+ 1 => AddressOrAddresses :: Address ( ReviveAddress :: from ( addresses[ 0 ] ) . inner ( ) ) ,
274+ _ => AddressOrAddresses :: Addresses (
275+ addresses. into_iter ( ) . map ( |address| ReviveAddress :: from ( address) . inner ( ) ) . collect ( ) ,
276+ ) ,
277+ } ;
278+ Self ( address_or_addresses)
279+ }
280+ }
281+
282+ pub struct ReviveFilter ( Filter ) ;
283+
284+ impl ReviveFilter {
285+ pub fn into_inner ( self ) -> Filter {
286+ self . 0
287+ }
288+ }
289+
290+ impl From < alloy_rpc_types:: Filter > for ReviveFilter {
291+ fn from ( value : alloy_rpc_types:: Filter ) -> Self {
292+ let address = if value. address . is_empty ( ) {
293+ None
294+ } else {
295+ Some ( ReviveAddressOrAddresses :: from ( value. address ) . into_inner ( ) )
296+ } ;
297+ let topics = if value. topics . iter ( ) . all ( |t| t. is_empty ( ) ) {
298+ None
299+ } else {
300+ Some ( ReviveFilterTopics :: from ( value. topics ) . into_inner ( ) )
301+ } ;
302+ let ( from_block, to_block, block_hash) = match value. block_option {
303+ FilterBlockOption :: Range { from_block, to_block } => (
304+ from_block. map ( |fb| ReviveBlockNumberOrTag :: from ( fb) . inner ( ) ) ,
305+ to_block. map ( |tb| ReviveBlockNumberOrTag :: from ( tb) . inner ( ) ) ,
306+ None ,
307+ ) ,
308+ FilterBlockOption :: AtBlockHash ( hash) => {
309+ ( None , None , Some ( H256 :: from_slice ( hash. as_ref ( ) ) ) )
310+ }
311+ } ;
312+ Self ( Filter { address, from_block, to_block, block_hash, topics } )
313+ }
314+ }
0 commit comments