@@ -36,22 +36,19 @@ pub async fn check_and_aggregate_receipts(
3636 // Get the allocation id from the first receipt, return error if there are no receipts
3737 let allocation_id = match receipts. get ( 0 ) {
3838 Some ( receipt) => receipt. message . allocation_id ,
39- None => {
40- return Err ( tap_core:: Error :: InvalidCheckError {
41- check_string : "No receipts" . into ( ) ,
42- }
43- . into ( ) )
44- }
39+ None => return Err ( tap_core:: Error :: NoValidReceiptsForRAVRequest . into ( ) ) ,
4540 } ;
4641
4742 // Check that the receipts all have the same allocation id
4843 check_allocation_id ( receipts, allocation_id) ?;
4944
5045 // Check that the rav has the correct allocation id
5146 if let Some ( previous_rav) = & previous_rav {
52- if previous_rav. message . allocation_id != allocation_id {
53- return Err ( tap_core:: Error :: InvalidCheckError {
54- check_string : "Previous rav allocation id does not match receipts" . into ( ) ,
47+ let prev_id = previous_rav. message . allocation_id ;
48+ if prev_id != allocation_id {
49+ return Err ( tap_core:: Error :: RavAllocationIdMismatch {
50+ prev_id : format ! ( "{prev_id:#X}" ) ,
51+ new_id : format ! ( "{allocation_id:#X}" ) ,
5552 }
5653 . into ( ) ) ;
5754 }
@@ -71,10 +68,7 @@ fn check_allocation_id(
7168 for receipt in receipts. iter ( ) {
7269 let receipt = & receipt. message ;
7370 if receipt. allocation_id != allocation_id {
74- return Err ( tap_core:: Error :: InvalidCheckError {
75- check_string : "Receipts allocation id is not uniform" . into ( ) ,
76- }
77- . into ( ) ) ;
71+ return Err ( tap_core:: Error :: RavAllocationIdNotUniform . into ( ) ) ;
7872 }
7973 }
8074 Ok ( ( ) )
@@ -84,13 +78,9 @@ fn check_signatures_unique(receipts: &[EIP712SignedMessage<Receipt>]) -> Result<
8478 let mut receipt_signatures: hash_set:: HashSet < Signature > = hash_set:: HashSet :: new ( ) ;
8579 for receipt in receipts. iter ( ) {
8680 let signature = receipt. signature ;
87- if receipt_signatures. contains ( & signature) {
88- return Err ( tap_core:: Error :: InvalidCheckError {
89- check_string : "Duplicate receipt signature" . into ( ) ,
90- }
91- . into ( ) ) ;
81+ if !receipt_signatures. insert ( signature) {
82+ return Err ( tap_core:: Error :: DuplicateReceiptSignature ( signature. to_string ( ) ) . into ( ) ) ;
9283 }
93- receipt_signatures. insert ( signature) ;
9484 }
9585 Ok ( ( ) )
9686}
@@ -103,9 +93,9 @@ fn check_receipt_timestamps(
10393 for receipt in receipts. iter ( ) {
10494 let receipt = & receipt. message ;
10595 if previous_rav. message . timestamp_ns >= receipt. timestamp_ns {
106- return Err ( tap_core:: Error :: InvalidCheckError {
107- check_string : "Receipt timestamp is less or equal then previous rav timestamp"
108- . into ( ) ,
96+ return Err ( tap_core:: Error :: ReceiptTimestampLowerThanRav {
97+ rav_ts : previous_rav . message . timestamp_ns ,
98+ receipt_ts : receipt . timestamp_ns ,
10999 }
110100 . into ( ) ) ;
111101 }
0 commit comments