@@ -36,6 +36,9 @@ use std::{
3636 sync:: { Arc , RwLock } ,
3737} ;
3838
39+ use tap_eip712_message:: Eip712Error ;
40+ use thegraph_core:: alloy:: dyn_abi:: Eip712Domain ;
41+
3942use super :: {
4043 state:: { Checking , Failed } ,
4144 Context , ReceiptError , ReceiptWithState , WithUniqueId , WithValueAndTimestamp ,
@@ -94,8 +97,9 @@ type CheckBatchResponse<Rcpt> = (
9497pub trait CheckBatch < Rcpt > {
9598 fn check_batch (
9699 & self ,
100+ domain_separator : & Eip712Domain ,
97101 receipts : Vec < ReceiptWithState < Checking , Rcpt > > ,
98- ) -> CheckBatchResponse < Rcpt > ;
102+ ) -> Result < CheckBatchResponse < Rcpt > , Eip712Error > ;
99103}
100104
101105/// Provides a built-in check to verify that the timestamp of a receipt
@@ -153,11 +157,9 @@ where
153157{
154158 fn check_batch (
155159 & self ,
160+ _domain_separator : & Eip712Domain ,
156161 receipts : Vec < ReceiptWithState < Checking , Rcpt > > ,
157- ) -> (
158- Vec < ReceiptWithState < Checking , Rcpt > > ,
159- Vec < ReceiptWithState < Failed , Rcpt > > ,
160- ) {
162+ ) -> Result < CheckBatchResponse < Rcpt > , Eip712Error > {
161163 let ( mut checking, mut failed) = ( vec ! [ ] , vec ! [ ] ) ;
162164 for receipt in receipts. into_iter ( ) {
163165 let receipt_timestamp_ns = receipt. signed_receipt ( ) . timestamp_ns ( ) ;
@@ -171,7 +173,7 @@ where
171173 } ) ) ;
172174 }
173175 }
174- ( checking, failed)
176+ Ok ( ( checking, failed) )
175177 }
176178}
177179
@@ -187,23 +189,21 @@ where
187189{
188190 fn check_batch (
189191 & self ,
192+ domain_separator : & Eip712Domain ,
190193 receipts : Vec < ReceiptWithState < Checking , Rcpt > > ,
191- ) -> (
192- Vec < ReceiptWithState < Checking , Rcpt > > ,
193- Vec < ReceiptWithState < Failed , Rcpt > > ,
194- ) {
194+ ) -> Result < CheckBatchResponse < Rcpt > , Eip712Error > {
195195 let mut signatures = HashSet :: new ( ) ;
196196 let ( mut checking, mut failed) = ( vec ! [ ] , vec ! [ ] ) ;
197197
198198 for received_receipt in receipts. into_iter ( ) {
199- let unique_id = received_receipt. receipt . unique_id ( ) ;
199+ let unique_id = received_receipt. receipt . unique_id ( domain_separator ) ? ;
200200 if signatures. insert ( unique_id) {
201201 checking. push ( received_receipt) ;
202202 } else {
203203 failed. push ( received_receipt. perform_state_error ( ReceiptError :: NonUniqueReceipt ) ) ;
204204 }
205205 }
206- ( checking, failed)
206+ Ok ( ( checking, failed) )
207207 }
208208}
209209
@@ -236,16 +236,20 @@ mod tests {
236236 }
237237 }
238238
239- fn create_signed_receipt_with_custom_value (
240- value : u128 ,
241- ) -> ReceiptWithState < Checking , Eip712SignedMessage < MyReceipt > > {
242- let wallet: PrivateKeySigner = PrivateKeySigner :: random ( ) ;
243- let eip712_domain_separator: Eip712Domain = eip712_domain ! {
239+ fn create_test_domain_separator ( ) -> Eip712Domain {
240+ eip712_domain ! {
244241 name: "TAP" ,
245242 version: "1" ,
246243 chain_id: 1 ,
247244 verifying_contract: Address :: from( [ 0x11u8 ; 20 ] ) ,
248- } ;
245+ }
246+ }
247+
248+ fn create_signed_receipt_with_custom_value (
249+ value : u128 ,
250+ ) -> ReceiptWithState < Checking , Eip712SignedMessage < MyReceipt > > {
251+ let wallet: PrivateKeySigner = PrivateKeySigner :: random ( ) ;
252+ let eip712_domain_separator = create_test_domain_separator ( ) ;
249253
250254 let timestamp = SystemTime :: now ( )
251255 . duration_since ( SystemTime :: UNIX_EPOCH )
@@ -273,7 +277,10 @@ mod tests {
273277 let signed_receipt_2 = create_signed_receipt_with_custom_value ( 15 ) ;
274278 let signed_receipt_copy = signed_receipt. clone ( ) ;
275279 let receipts_batch = vec ! [ signed_receipt, signed_receipt_2, signed_receipt_copy] ;
276- let ( valid_receipts, invalid_receipts) = UniqueCheck . check_batch ( receipts_batch) ;
280+ let domain_separator = create_test_domain_separator ( ) ;
281+ let ( valid_receipts, invalid_receipts) = UniqueCheck
282+ . check_batch ( & domain_separator, receipts_batch)
283+ . unwrap ( ) ;
277284 assert_eq ! ( valid_receipts. len( ) , 2 ) ;
278285 assert_eq ! ( invalid_receipts. len( ) , 1 ) ;
279286 }
@@ -282,10 +289,14 @@ mod tests {
282289 async fn test_receipt_timestamp_check ( ) {
283290 let signed_receipt = create_signed_receipt_with_custom_value ( 10 ) ;
284291 let signed_receipt_2 = create_signed_receipt_with_custom_value ( 15 ) ;
292+
293+ let domain_separator = create_test_domain_separator ( ) ;
294+
285295 let receipts_batch = vec ! [ signed_receipt. clone( ) , signed_receipt_2] ;
286296 let min_time_stamp = signed_receipt. receipt . message . timestamp_ns + 1 ;
287- let ( valid_receipts, invalid_receipts) =
288- TimestampCheck ( min_time_stamp) . check_batch ( receipts_batch) ;
297+ let ( valid_receipts, invalid_receipts) = TimestampCheck ( min_time_stamp)
298+ . check_batch ( & domain_separator, receipts_batch)
299+ . unwrap ( ) ;
289300 assert_eq ! ( valid_receipts. len( ) , 1 ) ;
290301 assert_eq ! ( invalid_receipts. len( ) , 1 ) ;
291302 }
0 commit comments