55use ink:: storage:: Mapping ;
66#[ cfg( not( feature = "std" ) ) ]
77use scale_info:: prelude:: { string:: String , vec:: Vec } ;
8+ use propchain_traits:: * ;
89
910pub mod tests;
1011
@@ -16,21 +17,96 @@ mod propchain_escrow {
1617 #[ derive( Debug , PartialEq , Eq , scale:: Encode , scale:: Decode ) ]
1718 #[ cfg_attr( feature = "std" , derive( scale_info:: TypeInfo ) ) ]
1819 pub enum Error {
20+ /// Escrow does not exist
1921 EscrowNotFound ,
22+ /// Caller is not authorized
2023 Unauthorized ,
24+ /// Invalid escrow status for operation
2125 InvalidStatus ,
26+ /// Insufficient funds in escrow
2227 InsufficientFunds ,
28+ /// Required conditions not met
2329 ConditionsNotMet ,
30+ /// Signature threshold not reached
2431 SignatureThresholdNotMet ,
32+ /// Already signed this request
2533 AlreadySigned ,
34+ /// Document does not exist
2635 DocumentNotFound ,
36+ /// Dispute is currently active
2737 DisputeActive ,
38+ /// Time lock period still active
2839 TimeLockActive ,
40+ /// Invalid configuration parameters
2941 InvalidConfiguration ,
42+ /// Escrow already funded
3043 EscrowAlreadyFunded ,
44+ /// Participant not found
3145 ParticipantNotFound ,
3246 }
3347
48+ impl core:: fmt:: Display for Error {
49+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
50+ match self {
51+ Error :: EscrowNotFound => write ! ( f, "Escrow does not exist" ) ,
52+ Error :: Unauthorized => write ! ( f, "Caller is not authorized" ) ,
53+ Error :: InvalidStatus => write ! ( f, "Invalid escrow status for operation" ) ,
54+ Error :: InsufficientFunds => write ! ( f, "Insufficient funds in escrow" ) ,
55+ Error :: ConditionsNotMet => write ! ( f, "Required conditions not met" ) ,
56+ Error :: SignatureThresholdNotMet => write ! ( f, "Signature threshold not reached" ) ,
57+ Error :: AlreadySigned => write ! ( f, "Already signed this request" ) ,
58+ Error :: DocumentNotFound => write ! ( f, "Document does not exist" ) ,
59+ Error :: DisputeActive => write ! ( f, "Dispute is currently active" ) ,
60+ Error :: TimeLockActive => write ! ( f, "Time lock period still active" ) ,
61+ Error :: InvalidConfiguration => write ! ( f, "Invalid configuration parameters" ) ,
62+ Error :: EscrowAlreadyFunded => write ! ( f, "Escrow already funded" ) ,
63+ Error :: ParticipantNotFound => write ! ( f, "Participant not found" ) ,
64+ }
65+ }
66+ }
67+
68+ impl ContractError for Error {
69+ fn error_code ( & self ) -> u32 {
70+ match self {
71+ Error :: EscrowNotFound => propchain_traits:: errors:: escrow_codes:: ESCROW_NOT_FOUND ,
72+ Error :: Unauthorized => propchain_traits:: errors:: escrow_codes:: UNAUTHORIZED_ACCESS ,
73+ Error :: InvalidStatus => propchain_traits:: errors:: escrow_codes:: INVALID_STATUS ,
74+ Error :: InsufficientFunds => propchain_traits:: errors:: escrow_codes:: INSUFFICIENT_ESCROW_FUNDS ,
75+ Error :: ConditionsNotMet => propchain_traits:: errors:: escrow_codes:: CONDITIONS_NOT_MET ,
76+ Error :: SignatureThresholdNotMet => propchain_traits:: errors:: escrow_codes:: SIGNATURE_THRESHOLD_NOT_MET ,
77+ Error :: AlreadySigned => propchain_traits:: errors:: escrow_codes:: ALREADY_SIGNED_ESCROW ,
78+ Error :: DocumentNotFound => propchain_traits:: errors:: escrow_codes:: DOCUMENT_NOT_FOUND ,
79+ Error :: DisputeActive => propchain_traits:: errors:: escrow_codes:: DISPUTE_ACTIVE ,
80+ Error :: TimeLockActive => propchain_traits:: errors:: escrow_codes:: TIME_LOCK_ACTIVE ,
81+ Error :: InvalidConfiguration => propchain_traits:: errors:: escrow_codes:: INVALID_CONFIGURATION ,
82+ Error :: EscrowAlreadyFunded => propchain_traits:: errors:: escrow_codes:: ESCROW_ALREADY_FUNDED ,
83+ Error :: ParticipantNotFound => propchain_traits:: errors:: escrow_codes:: PARTICIPANT_NOT_FOUND ,
84+ }
85+ }
86+
87+ fn error_description ( & self ) -> & ' static str {
88+ match self {
89+ Error :: EscrowNotFound => "The specified escrow does not exist" ,
90+ Error :: Unauthorized => "Caller does not have permission to perform this operation" ,
91+ Error :: InvalidStatus => "The escrow is not in the required state for this operation" ,
92+ Error :: InsufficientFunds => "The escrow does not have sufficient funds" ,
93+ Error :: ConditionsNotMet => "Not all required conditions have been met" ,
94+ Error :: SignatureThresholdNotMet => "Insufficient signatures collected" ,
95+ Error :: AlreadySigned => "You have already signed this request" ,
96+ Error :: DocumentNotFound => "The requested document does not exist" ,
97+ Error :: DisputeActive => "A dispute is currently active on this escrow" ,
98+ Error :: TimeLockActive => "The time lock period has not yet expired" ,
99+ Error :: InvalidConfiguration => "The escrow configuration is invalid" ,
100+ Error :: EscrowAlreadyFunded => "This escrow has already been funded" ,
101+ Error :: ParticipantNotFound => "The specified participant is not in the escrow" ,
102+ }
103+ }
104+
105+ fn error_category ( & self ) -> ErrorCategory {
106+ ErrorCategory :: Escrow
107+ }
108+ }
109+
34110 /// Escrow status enumeration
35111 #[ derive( Debug , Clone , PartialEq , Eq , scale:: Encode , scale:: Decode ) ]
36112 #[ cfg_attr( feature = "std" , derive( scale_info:: TypeInfo ) ) ]
0 commit comments