88//! The payment receiver would verify the received receipt and store it to be
99//! accumulated with other received receipts in the future.
1010
11+ use std:: time:: { SystemTime , SystemTimeError , UNIX_EPOCH } ;
12+
1113use alloy:: { primitives:: Address , sol} ;
1214use rand:: { thread_rng, Rng } ;
1315use serde:: { Deserialize , Serialize } ;
1416use tap_eip712_message:: Eip712SignedMessage ;
1517use tap_receipt:: WithValueAndTimestamp ;
1618
17- /// A signed receipt message
19+ /// A Receipt wrapped in an Eip712SignedMessage
1820pub type SignedReceipt = Eip712SignedMessage < Receipt > ;
1921
2022sol ! {
21- /// Holds information needed for promise of payment signed with ECDSA
23+ /// Receipt struct used to pay for an off-chain service
2224 #[ derive( Debug , Serialize , Deserialize , Eq , PartialEq ) ]
2325 struct Receipt {
2426 /// Unique allocation id this receipt belongs to
@@ -32,10 +34,14 @@ sol! {
3234 }
3335}
3436
37+ fn get_current_timestamp_u64_ns ( ) -> Result < u64 , SystemTimeError > {
38+ Ok ( SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) ?. as_nanos ( ) as u64 )
39+ }
40+
3541impl Receipt {
3642 /// Returns a receipt with provided values
37- pub fn new ( allocation_id : Address , value : u128 ) -> Result < Self , crate :: Error > {
38- let timestamp_ns = crate :: get_current_timestamp_u64_ns ( ) ?;
43+ pub fn new ( allocation_id : Address , value : u128 ) -> Result < Self , SystemTimeError > {
44+ let timestamp_ns = get_current_timestamp_u64_ns ( ) ?;
3945 let nonce = thread_rng ( ) . gen :: < u64 > ( ) ;
4046 Ok ( Self {
4147 allocation_id,
0 commit comments