@@ -93,11 +93,10 @@ impl From<RequestRow> for RequestStatus {
9393pub struct History {
9494 pool : Pool < Sqlite > ,
9595 write_queue : mpsc:: Sender < RequestStatus > ,
96- writer_thread : Arc < tokio:: task:: JoinHandle < ( ) > > ,
96+ _writer_thread : Arc < tokio:: task:: JoinHandle < ( ) > > ,
9797}
9898
9999impl History {
100- const MAX_HISTORY : usize = 1_000_000 ;
101100 const MAX_WRITE_QUEUE : usize = 1_000 ;
102101 pub async fn new ( ) -> Self {
103102 Self :: new_with_url ( "sqlite:fortuna.db" ) . await
@@ -124,14 +123,14 @@ impl History {
124123 Self {
125124 pool,
126125 write_queue : sender,
127- writer_thread : Arc :: new ( writer_thread) ,
126+ _writer_thread : Arc :: new ( writer_thread) ,
128127 }
129128 }
130129
131130 async fn update_request_status ( pool : & Pool < Sqlite > , new_status : RequestStatus ) {
132131 let sequence = new_status. sequence as i64 ;
133132 let chain_id = new_status. chain_id ;
134- let state = match new_status. state {
133+ match new_status. state {
135134 RequestEntryState :: Pending => {
136135 let block_number = new_status. request_block_number as i64 ;
137136 let request_tx_hash: String = new_status. request_tx_hash . encode_hex ( ) ;
@@ -204,7 +203,7 @@ impl History {
204203 self . get_from_db ( request_key. clone ( ) ) . await
205204 }
206205
207- pub async fn get_request_logs_by_tx_hash ( & self , tx_hash : TxHash ) -> Vec < RequestStatus > {
206+ pub async fn get_requests_by_tx_hash ( & self , tx_hash : TxHash ) -> Vec < RequestStatus > {
208207 let tx_hash: String = tx_hash. encode_hex ( ) ;
209208 let rows = sqlx:: query_as!(
210209 RequestRow ,
@@ -218,6 +217,58 @@ impl History {
218217 rows. into_iter ( ) . map ( |row| row. into ( ) ) . collect ( )
219218 }
220219
220+ pub async fn get_requests_by_sender (
221+ & self ,
222+ sender : Address ,
223+ chain_id : Option < ChainId > ,
224+ ) -> Vec < RequestStatus > {
225+ let sender: String = sender. encode_hex ( ) ;
226+ let rows = match chain_id {
227+ Some ( chain_id) => sqlx:: query_as!(
228+ RequestRow ,
229+ "SELECT * FROM request WHERE sender = ? AND chain_id = ?" ,
230+ sender,
231+ chain_id,
232+ )
233+ . fetch_all ( & self . pool )
234+ . await
235+ . unwrap ( ) ,
236+ None => sqlx:: query_as!( RequestRow , "SELECT * FROM request WHERE sender = ?" , sender, )
237+ . fetch_all ( & self . pool )
238+ . await
239+ . unwrap ( ) ,
240+ } ;
241+ rows. into_iter ( ) . map ( |row| row. into ( ) ) . collect ( )
242+ }
243+
244+ pub async fn get_requests_by_sequence (
245+ & self ,
246+ sequence : u64 ,
247+ chain_id : Option < ChainId > ,
248+ ) -> Vec < RequestStatus > {
249+ let sequence = sequence as i64 ;
250+ let rows = match chain_id {
251+ Some ( chain_id) => sqlx:: query_as!(
252+ RequestRow ,
253+ "SELECT * FROM request WHERE sequence = ? AND chain_id = ?" ,
254+ sequence,
255+ chain_id,
256+ )
257+ . fetch_all ( & self . pool )
258+ . await
259+ . unwrap ( ) ,
260+ None => sqlx:: query_as!(
261+ RequestRow ,
262+ "SELECT * FROM request WHERE sequence = ?" ,
263+ sequence,
264+ )
265+ . fetch_all ( & self . pool )
266+ . await
267+ . unwrap ( ) ,
268+ } ;
269+ rows. into_iter ( ) . map ( |row| row. into ( ) ) . collect ( )
270+ }
271+
221272 pub async fn get_latest_requests (
222273 & self ,
223274 chain_id : Option < & ChainId > ,
@@ -251,7 +302,8 @@ impl History {
251302}
252303
253304mod tests {
254- use super :: * ;
305+ use crate :: history:: { History , RequestEntryState , RequestStatus } ;
306+ use ethers:: types:: { Address , TxHash } ;
255307 use tokio:: time:: sleep;
256308
257309 #[ tokio:: test]
@@ -274,7 +326,7 @@ mod tests {
274326
275327 #[ tokio:: test( flavor = "multi_thread" ) ]
276328 async fn test_writer_thread ( ) {
277- let mut history = History :: new_in_memory ( ) . await ;
329+ let history = History :: new_in_memory ( ) . await ;
278330 let status = RequestStatus {
279331 chain_id : "ethereum" . to_string ( ) ,
280332 sequence : 1 ,
0 commit comments