11// Copyright 2023-, Semiotic AI, Inc.
22// SPDX-License-Identifier: Apache-2.0
33
4- use std:: marker:: PhantomData ;
5-
64use alloy:: { dyn_abi:: Eip712Domain , sol_types:: SolStruct } ;
75use tap_receipt:: rav:: Aggregate ;
86
@@ -20,7 +18,7 @@ use crate::{
2018 Error ,
2119} ;
2220
23- pub struct Manager < E , Rcpt , Rav > {
21+ pub struct Manager < E , Rcpt > {
2422 /// Context that implements adapters
2523 context : E ,
2624
@@ -30,11 +28,9 @@ pub struct Manager<E, Rcpt, Rav> {
3028 /// Struct responsible for doing checks for receipt. Ownership stays with manager allowing manager
3129 /// to update configuration ( like minimum timestamp ).
3230 domain_separator : Eip712Domain ,
33-
34- _phantom : PhantomData < Rav > ,
3531}
3632
37- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav > {
33+ impl < E , Rcpt > Manager < E , Rcpt > {
3834 /// Creates new manager with provided `adapters`, any receipts received by this manager
3935 /// will complete all `required_checks` before being accepted or declined from RAV.
4036 /// `starting_min_timestamp` will be used as min timestamp until the first RAV request is created.
@@ -48,27 +44,40 @@ impl<E, Rcpt, Rav> Manager<E, Rcpt, Rav> {
4844 context,
4945 domain_separator,
5046 checks : checks. into ( ) ,
51- _phantom : PhantomData ,
5247 }
5348 }
54- }
5549
56- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav >
57- where
58- E : RavStore < Rav > + SignatureChecker ,
59- Rav : SolStruct + PartialEq < Rav > + Sync + std:: fmt:: Debug ,
60- {
50+ async fn get_previous_rav < Rav : SolStruct > (
51+ & self ,
52+ ) -> Result < Option < Eip712SignedMessage < Rav > > , Error >
53+ where
54+ E : RavRead < Rav > ,
55+ {
56+ let previous_rav = self
57+ . context
58+ . last_rav ( )
59+ . await
60+ . map_err ( |err| Error :: AdapterError {
61+ source_error : anyhow:: Error :: new ( err) ,
62+ } ) ?;
63+ Ok ( previous_rav)
64+ }
65+
6166 /// Verify `signed_rav` matches all values on `expected_rav`, and that `signed_rav` has a valid signer.
6267 ///
6368 /// # Errors
6469 ///
6570 /// Returns [`Error::AdapterError`] if there are any errors while storing RAV
6671 ///
67- pub async fn verify_and_store_rav (
72+ pub async fn verify_and_store_rav < Rav > (
6873 & self ,
6974 expected_rav : Rav ,
7075 signed_rav : Eip712SignedMessage < Rav > ,
71- ) -> std:: result:: Result < ( ) , Error > {
76+ ) -> std:: result:: Result < ( ) , Error >
77+ where
78+ E : RavStore < Rav > + SignatureChecker ,
79+ Rav : SolStruct + PartialEq < Rav > + Sync + std:: fmt:: Debug ,
80+ {
7281 self . context
7382 . check_signature ( & signed_rav, & self . domain_separator )
7483 . await ?;
@@ -91,27 +100,10 @@ where
91100 }
92101}
93102
94- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav >
103+ impl < E , Rcpt > Manager < E , Rcpt >
95104where
96- E : RavRead < Rav > ,
97- Rav : SolStruct ,
98- {
99- async fn get_previous_rav ( & self ) -> Result < Option < Eip712SignedMessage < Rav > > , Error > {
100- let previous_rav = self
101- . context
102- . last_rav ( )
103- . await
104- . map_err ( |err| Error :: AdapterError {
105- source_error : anyhow:: Error :: new ( err) ,
106- } ) ?;
107- Ok ( previous_rav)
108- }
109- }
110-
111- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav >
112- where
113- E : ReceiptRead < Rcpt > + SignatureChecker ,
114- Rcpt : WithUniqueId + WithValueAndTimestamp + Sync ,
105+ E : ReceiptRead < Rcpt > ,
106+ Rcpt : WithUniqueId + WithValueAndTimestamp ,
115107{
116108 async fn collect_receipts (
117109 & self ,
@@ -168,14 +160,7 @@ where
168160
169161 Ok ( ( checked_receipts, failed_receipts) )
170162 }
171- }
172163
173- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav >
174- where
175- E : ReceiptRead < Rcpt > + RavRead < Rav > + SignatureChecker ,
176- Rav : SolStruct + WithValueAndTimestamp + Clone + Aggregate < Rcpt > ,
177- Rcpt : WithUniqueId + WithValueAndTimestamp + Sync ,
178- {
179164 /// Completes remaining checks on all receipts up to
180165 /// (current time - `timestamp_buffer_ns`). Returns them in two lists
181166 /// (valid receipts and invalid receipts) along with the expected RAV that
@@ -191,12 +176,16 @@ where
191176 /// previous RAV is greater than the min timestamp. Caused by timestamp
192177 /// buffer being too large, or requests coming too soon.
193178 ///
194- pub async fn create_rav_request (
179+ pub async fn create_rav_request < Rav > (
195180 & self ,
196181 ctx : & Context ,
197182 timestamp_buffer_ns : u64 ,
198183 receipts_limit : Option < u64 > ,
199- ) -> Result < RavRequest < Rcpt , Rav > , Error > {
184+ ) -> Result < RavRequest < Rcpt , Rav > , Error >
185+ where
186+ E : RavRead < Rav > ,
187+ Rav : SolStruct + WithValueAndTimestamp + Clone + Aggregate < Rcpt > ,
188+ {
200189 let previous_rav = self . get_previous_rav ( ) . await ?;
201190 let min_timestamp_ns = previous_rav
202191 . as_ref ( )
@@ -218,10 +207,9 @@ where
218207 }
219208}
220209
221- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav >
210+ impl < E , Rcpt > Manager < E , Rcpt >
222211where
223- E : ReceiptDelete + RavRead < Rav > ,
224- Rav : SolStruct + WithValueAndTimestamp ,
212+ E : ReceiptDelete ,
225213{
226214 /// Removes obsolete receipts from storage. Obsolete receipts are receipts
227215 /// that are older than the last RAV, and therefore already aggregated into the RAV.
@@ -233,7 +221,11 @@ where
233221 /// Returns [`Error::AdapterError`] if there are any errors while retrieving
234222 /// last RAV or removing receipts
235223 ///
236- pub async fn remove_obsolete_receipts ( & self ) -> Result < ( ) , Error > {
224+ pub async fn remove_obsolete_receipts < Rav > ( & self ) -> Result < ( ) , Error >
225+ where
226+ E : RavRead < Rav > ,
227+ Rav : SolStruct + WithValueAndTimestamp ,
228+ {
237229 match self . get_previous_rav ( ) . await ? {
238230 Some ( last_rav) => {
239231 self . context
@@ -249,7 +241,7 @@ where
249241 }
250242}
251243
252- impl < E , Rcpt , Rav > Manager < E , Rcpt , Rav >
244+ impl < E , Rcpt > Manager < E , Rcpt >
253245where
254246 E : ReceiptStore < Rcpt > ,
255247{
0 commit comments