@@ -16,12 +16,11 @@ use alloy::{
1616 rpc:: types:: Log ,
1717} ;
1818use anyhow:: { Context , Result } ;
19+ use async_trait:: async_trait;
1920use duckdb:: { Connection , OptionalExt , types:: ValueRef } ;
2021use serde_json:: { Map , Number , Value , json} ;
2122use std:: {
2223 collections:: { HashMap , HashSet } ,
23- future:: Future ,
24- pin:: Pin ,
2524 string:: ToString ,
2625 sync:: { Mutex , RwLock } ,
2726} ;
@@ -61,107 +60,63 @@ impl Clone for DuckDBStorage {
6160 }
6261}
6362
63+ #[ async_trait]
6464impl Storage for DuckDBStorage {
65- fn add_events (
66- & self ,
67- chain_id : u64 ,
68- events : & [ Log ] ,
69- ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' _ > > {
70- Box :: pin ( std:: future:: ready ( self . add_events_sync ( chain_id, events) ) )
65+ async fn add_events ( & self , chain_id : u64 , events : & [ Log ] ) -> Result < ( ) > {
66+ self . add_events_sync ( chain_id, events)
7167 }
7268
73- fn list_indexed_events (
74- & self ,
75- ) -> Pin < Box < dyn Future < Output = Result < Vec < EventDescriptorDb > > > + Send + ' _ > > {
76- Box :: pin ( std:: future:: ready ( self . list_indexed_events_sync ( ) ) )
69+ async fn list_indexed_events ( & self ) -> Result < Vec < EventDescriptorDb > > {
70+ self . list_indexed_events_sync ( )
7771 }
7872
79- fn last_block (
80- & self ,
81- chain_id : u64 ,
82- event : & Event ,
83- ) -> Pin < Box < dyn Future < Output = Result < u64 > > + Send + ' _ > > {
84- Box :: pin ( std:: future:: ready ( self . last_block_sync ( chain_id, event) ) )
73+ async fn last_block ( & self , chain_id : u64 , event : & Event ) -> Result < u64 > {
74+ self . last_block_sync ( chain_id, event)
8575 }
8676
87- fn first_block (
88- & self ,
89- chain_id : u64 ,
90- event : & Event ,
91- ) -> Pin < Box < dyn Future < Output = Result < u64 > > + Send + ' _ > > {
92- Box :: pin ( std:: future:: ready ( self . first_block_sync ( chain_id, event) ) )
77+ async fn first_block ( & self , chain_id : u64 , event : & Event ) -> Result < u64 > {
78+ self . first_block_sync ( chain_id, event)
9379 }
9480
95- fn include_events (
96- & self ,
97- chain_id : u64 ,
98- events : & [ Event ] ,
99- ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' _ > > {
100- Box :: pin ( std:: future:: ready (
101- self . include_events_sync ( chain_id, events) ,
102- ) )
81+ async fn include_events ( & self , chain_id : u64 , events : & [ Event ] ) -> Result < ( ) > {
82+ self . include_events_sync ( chain_id, events)
10383 }
10484
105- fn get_event_signature (
106- & self ,
107- event_hash : & str ,
108- ) -> Pin < Box < dyn Future < Output = Result < String > > + Send + ' _ > > {
109- Box :: pin ( std:: future:: ready (
110- self . get_event_signature_sync ( event_hash) ,
111- ) )
85+ async fn get_event_signature ( & self , event_hash : & str ) -> Result < String > {
86+ self . get_event_signature_sync ( event_hash)
11287 }
11388
114- fn event_index_status (
89+ async fn event_index_status (
11590 & self ,
11691 chain_id : u64 ,
11792 event : & Event ,
118- ) -> Pin < Box < dyn Future < Output = Result < Option < EventStatus > > > + Send + ' _ > > {
119- Box :: pin ( std:: future:: ready (
120- self . event_index_status_sync ( chain_id, event) ,
121- ) )
93+ ) -> Result < Option < EventStatus > > {
94+ self . event_index_status_sync ( chain_id, event)
12295 }
12396
124- fn synchronize_events (
97+ async fn synchronize_events (
12598 & self ,
12699 chain_id : u64 ,
127100 event_selectors : & [ B256 ] ,
128101 last_processed : Option < u64 > ,
129- ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' _ > > {
130- Box :: pin ( std:: future:: ready ( self . synchronize_events_sync (
131- chain_id,
132- event_selectors,
133- last_processed,
134- ) ) )
102+ ) -> Result < ( ) > {
103+ self . synchronize_events_sync ( chain_id, event_selectors, last_processed)
135104 }
136105
137- fn send_raw_query (
138- & self ,
139- query : & str ,
140- ) -> Pin < Box < dyn Future < Output = Result < Value > > + Send + ' _ > > {
141- Box :: pin ( std:: future:: ready ( self . send_raw_query_sync ( query) ) )
106+ async fn send_raw_query ( & self , query : & str ) -> Result < Value > {
107+ self . send_raw_query_sync ( query)
142108 }
143109
144- fn list_contracts (
145- & self ,
146- ) -> Pin < Box < dyn Future < Output = Result < Vec < ContractDescriptorDb > > > + Send + ' _ > > {
147- Box :: pin ( std:: future:: ready ( self . list_contracts_sync ( ) ) )
110+ async fn list_contracts ( & self ) -> Result < Vec < ContractDescriptorDb > > {
111+ self . list_contracts_sync ( )
148112 }
149113
150- fn set_first_block (
151- & self ,
152- chain_id : u64 ,
153- event : & Event ,
154- block_number : u64 ,
155- ) -> Pin < Box < dyn Future < Output = Result < ( ) > > + Send + ' _ > > {
156- Box :: pin ( std:: future:: ready ( self . set_first_block_sync (
157- chain_id,
158- event,
159- block_number,
160- ) ) )
114+ async fn set_first_block ( & self , chain_id : u64 , event : & Event , block_number : u64 ) -> Result < ( ) > {
115+ self . set_first_block_sync ( chain_id, event, block_number)
161116 }
162117
163- fn describe_database ( & self ) -> Pin < Box < dyn Future < Output = Result < Value > > + Send + ' _ > > {
164- Box :: pin ( std :: future :: ready ( self . describe_database_sync ( ) ) )
118+ async fn describe_database ( & self ) -> Result < Value > {
119+ self . describe_database_sync ( )
165120 }
166121}
167122
0 commit comments