|
| 1 | +use core::fmt; |
1 | 2 | use soroban_sdk::contracterror; |
2 | 3 |
|
3 | 4 | #[derive(Debug, Copy, Clone, PartialEq)] |
@@ -51,136 +52,148 @@ pub enum ContractError { |
51 | 52 | MilestoneToUpdateDoesNotExist = 46, |
52 | 53 | } |
53 | 54 |
|
54 | | -// impl fmt::Display for ContractError { |
55 | | -// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
56 | | -// match self { |
57 | | -// ContractError::AmountCannotBeZero => { |
58 | | -// write!(f, "Amount cannot be equal to or less than zero") |
59 | | -// } |
60 | | -// ContractError::EscrowAlreadyInitialized => write!(f, "Escrow already initialized"), |
61 | | -// ContractError::EscrowNotFound => write!(f, "Escrow not found"), |
62 | | -// ContractError::OnlyReleaseSignerCanReleaseEarnings => { |
63 | | -// write!(f, "Only the release signer can release the escrow earnings") |
64 | | -// } |
65 | | -// ContractError::EscrowNotCompleted => { |
66 | | -// write!(f, "The escrow must be completed to release earnings") |
67 | | -// } |
68 | | -// ContractError::EscrowBalanceNotEnoughToSendEarnings => write!( |
69 | | -// f, |
70 | | -// "The escrow balance must be equal to the amount of earnings defined for the escrow" |
71 | | -// ), |
72 | | -// ContractError::OnlyPlatformAddressExecuteThisFunction => write!( |
73 | | -// f, |
74 | | -// "Only the platform address should be able to execute this function" |
75 | | -// ), |
76 | | -// ContractError::OnlyServiceProviderChangeMilstoneStatus => { |
77 | | -// write!(f, "Only the service provider can change milestone status") |
78 | | -// } |
79 | | -// ContractError::NoMilestoneDefined => write!(f, "Escrow initialized without milestone"), |
80 | | -// ContractError::InvalidMileStoneIndex => write!(f, "Invalid milestone index"), |
81 | | -// ContractError::OnlyApproverChangeMilstoneFlag => { |
82 | | -// write!(f, "Only the approver can change milestone flag") |
83 | | -// } |
84 | | -// ContractError::OnlyDisputeResolverCanExecuteThisFunction => { |
85 | | -// write!(f, "Only the dispute resolver can execute this function") |
86 | | -// } |
87 | | -// ContractError::EscrowAlreadyInDispute => write!(f, "Escrow already in dispute"), |
88 | | -// ContractError::EscrowNotInDispute => write!(f, "Escrow not in dispute"), |
89 | | -// ContractError::InsufficientFundsForResolution => { |
90 | | -// write!(f, "Insufficient funds for resolution") |
91 | | -// } |
92 | | -// ContractError::EscrowOpenedForDisputeResolution => { |
93 | | -// write!(f, "Escrow has been opened for dispute resolution") |
94 | | -// } |
95 | | -// ContractError::InsufficientApproverFundsForCommissions => { |
96 | | -// write!(f, "Insufficient approver funds for commissions") |
97 | | -// } |
98 | | -// ContractError::InsufficientServiceProviderFundsForCommissions => { |
99 | | -// write!(f, "Insufficient Service Provider funds for commissions") |
100 | | -// } |
101 | | -// ContractError::MilestoneApprovedCantChangeEscrowProperties => { |
102 | | -// write!( |
103 | | -// f, |
104 | | -// "You can't change the escrow properties after the milestone is approved" |
105 | | -// ) |
106 | | -// } |
107 | | -// ContractError::EscrowHasFunds => write!(f, "Escrow has funds"), |
108 | | -// ContractError::Overflow => write!(f, "This operation can cause an Overflow"), |
109 | | -// ContractError::Underflow => write!(f, "This operation can cause an Underflow"), |
110 | | -// ContractError::DivisionError => write!(f, "This operation can cause Division error"), |
111 | | -// ContractError::EscrowAlreadyResolved => write!(f, "This escrow is already resolved"), |
112 | | -// ContractError::TooManyEscrowsRequested => { |
113 | | -// write!(f, "You have requested too many escrows") |
114 | | -// } |
115 | | -// ContractError::UnauthorizedToChangeDisputeFlag => { |
116 | | -// write!(f, "You are not authorized to change the dispute flag") |
117 | | -// } |
118 | | -// ContractError::TooManyMilestones => { |
119 | | -// write!(f, "Cannot define more than 50 milestones in an escrow") |
120 | | -// } |
121 | | -// ContractError::ReceiverAndApproverFundsNotEqual => { |
122 | | -// write!( |
123 | | -// f, |
124 | | -// "The approver's and receiver's funds must equal the current escrow balance." |
125 | | -// ) |
126 | | -// } |
127 | | -// ContractError::AmountsToBeTransferredShouldBePositive => { |
128 | | -// write!( |
129 | | -// f, |
130 | | -// "None of the amounts to be transferred should be less or equal than 0." |
131 | | -// ) |
132 | | -// } |
133 | | -// ContractError::DistributionsMustEqualEscrowBalance => { |
134 | | -// write!(f, "The sum of distributions must equal the current escrow balance when resolving an escrow dispute.") |
135 | | -// } |
136 | | -// ContractError::MilestoneHasAlreadyBeenApproved => { |
137 | | -// write!( |
138 | | -// f, |
139 | | -// "You cannot approve a milestone that has already been approved previously" |
140 | | -// ) |
141 | | -// } |
142 | | -// ContractError::EmptyMilestoneStatus => { |
143 | | -// write!(f, "The milestone status cannot be empty") |
144 | | -// } |
145 | | -// ContractError::PlatformFeeTooHigh => { |
146 | | -// write!(f, "The platform fee cannot exceed 99%") |
147 | | -// } |
148 | | -// ContractError::FlagsMustBeFalse => { |
149 | | -// write!(f, "All flags (approved, disputed, released) must be false in order to execute this function.") |
150 | | -// } |
151 | | -// ContractError::EscrowPropertiesMismatch => { |
152 | | -// write!( |
153 | | -// f, |
154 | | -// "The provided escrow properties do not match the stored escrow." |
155 | | -// ) |
156 | | -// } |
157 | | -// ContractError::ApproverOrReceiverFundsLessThanZero => { |
158 | | -// write!( |
159 | | -// f, |
160 | | -// "The funds of the approver or receiver must not be less or equal than 0." |
161 | | -// ) |
162 | | -// } |
163 | | -// ContractError::EscrowAlreadyReleased => { |
164 | | -// write!(f, "The escrow funds have been released.") |
165 | | -// } |
166 | | -// ContractError::IncompatibleEscrowWasmHash => { |
167 | | -// write!( |
168 | | -// f, |
169 | | -// "The provided contract address is not an instance of this escrow contract." |
170 | | -// ) |
171 | | -// } |
172 | | -// ContractError::PlatformAddressCannotBeChanged => { |
173 | | -// write!(f, "The platform address of the escrow cannot be changed.") |
174 | | -// } |
175 | | -// ContractError::DisputeResolverCannotDisputeTheEscrow => { |
176 | | -// write!(f, "The dispute resolver cannot dispute the escrow.") |
177 | | -// } |
178 | | -// ContractError::TotalAmountCannotBeZero => { |
179 | | -// write!(f, "The total amount to be distributed cannot be equal to zero.") |
180 | | -// } |
181 | | -// ContractError::InsufficientFundsForEscrowFunding => { |
182 | | -// write!(f, "The signer has insufficient funds to fund the escrow.") |
183 | | -// } |
184 | | -// } |
185 | | -// } |
186 | | -// } |
| 55 | +impl fmt::Display for ContractError { |
| 56 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 57 | + match self { |
| 58 | + ContractError::AmountCannotBeZero => { |
| 59 | + write!(f, "Amount cannot be equal to or less than zero") |
| 60 | + } |
| 61 | + ContractError::EscrowAlreadyInitialized => write!(f, "Escrow already initialized"), |
| 62 | + ContractError::EscrowNotFound => write!(f, "Escrow not found"), |
| 63 | + ContractError::OnlyReleaseSignerCanReleaseEarnings => { |
| 64 | + write!(f, "Only the release signer can release the escrow earnings") |
| 65 | + } |
| 66 | + ContractError::EscrowNotCompleted => { |
| 67 | + write!(f, "The escrow must be completed to release earnings") |
| 68 | + } |
| 69 | + ContractError::EscrowBalanceNotEnoughToSendEarnings => write!( |
| 70 | + f, |
| 71 | + "The escrow balance must be equal to the amount of earnings defined for the escrow" |
| 72 | + ), |
| 73 | + ContractError::OnlyPlatformAddressExecuteThisFunction => write!( |
| 74 | + f, |
| 75 | + "Only the platform address should be able to execute this function" |
| 76 | + ), |
| 77 | + ContractError::OnlyServiceProviderChangeMilstoneStatus => { |
| 78 | + write!(f, "Only the service provider can change milestone status") |
| 79 | + } |
| 80 | + ContractError::NoMilestoneDefined => write!(f, "Escrow initialized without milestone"), |
| 81 | + ContractError::InvalidMileStoneIndex => write!(f, "Invalid milestone index"), |
| 82 | + ContractError::OnlyApproverChangeMilstoneFlag => { |
| 83 | + write!(f, "Only the approver can change milestone flag") |
| 84 | + } |
| 85 | + ContractError::OnlyDisputeResolverCanExecuteThisFunction => { |
| 86 | + write!(f, "Only the dispute resolver can execute this function") |
| 87 | + } |
| 88 | + ContractError::EscrowAlreadyInDispute => write!(f, "Escrow already in dispute"), |
| 89 | + ContractError::EscrowNotInDispute => write!(f, "Escrow not in dispute"), |
| 90 | + ContractError::InsufficientFundsForResolution => { |
| 91 | + write!(f, "Insufficient funds for resolution") |
| 92 | + } |
| 93 | + ContractError::EscrowOpenedForDisputeResolution => { |
| 94 | + write!(f, "Escrow has been opened for dispute resolution") |
| 95 | + } |
| 96 | + ContractError::InsufficientApproverFundsForCommissions => { |
| 97 | + write!(f, "Insufficient approver funds for commissions") |
| 98 | + } |
| 99 | + ContractError::InsufficientServiceProviderFundsForCommissions => { |
| 100 | + write!(f, "Insufficient Service Provider funds for commissions") |
| 101 | + } |
| 102 | + ContractError::MilestoneApprovedCantChangeEscrowProperties => { |
| 103 | + write!( |
| 104 | + f, |
| 105 | + "You can't change the escrow properties after the milestone is approved" |
| 106 | + ) |
| 107 | + } |
| 108 | + ContractError::EscrowHasFunds => write!(f, "Escrow has funds"), |
| 109 | + ContractError::Overflow => write!(f, "This operation can cause an Overflow"), |
| 110 | + ContractError::Underflow => write!(f, "This operation can cause an Underflow"), |
| 111 | + ContractError::DivisionError => write!(f, "This operation can cause Division error"), |
| 112 | + ContractError::EscrowAlreadyResolved => write!(f, "This escrow is already resolved"), |
| 113 | + ContractError::TooManyEscrowsRequested => { |
| 114 | + write!(f, "You have requested too many escrows") |
| 115 | + } |
| 116 | + ContractError::UnauthorizedToChangeDisputeFlag => { |
| 117 | + write!(f, "You are not authorized to change the dispute flag") |
| 118 | + } |
| 119 | + ContractError::TooManyMilestones => { |
| 120 | + write!(f, "Cannot define more than 50 milestones in an escrow") |
| 121 | + } |
| 122 | + ContractError::ReceiverAndApproverFundsNotEqual => { |
| 123 | + write!( |
| 124 | + f, |
| 125 | + "The approver's and receiver's funds must equal the current escrow balance." |
| 126 | + ) |
| 127 | + } |
| 128 | + ContractError::AmountsToBeTransferredShouldBePositive => { |
| 129 | + write!( |
| 130 | + f, |
| 131 | + "None of the amounts to be transferred should be less or equal than 0." |
| 132 | + ) |
| 133 | + } |
| 134 | + ContractError::DistributionsMustEqualEscrowBalance => { |
| 135 | + write!(f, "The sum of distributions must equal the current escrow balance when resolving an escrow dispute.") |
| 136 | + } |
| 137 | + ContractError::MilestoneHasAlreadyBeenApproved => { |
| 138 | + write!( |
| 139 | + f, |
| 140 | + "You cannot approve a milestone that has already been approved previously" |
| 141 | + ) |
| 142 | + } |
| 143 | + ContractError::EmptyMilestoneStatus => { |
| 144 | + write!(f, "The milestone status cannot be empty") |
| 145 | + } |
| 146 | + ContractError::PlatformFeeTooHigh => { |
| 147 | + write!(f, "The platform fee cannot exceed 99%") |
| 148 | + } |
| 149 | + ContractError::FlagsMustBeFalse => { |
| 150 | + write!(f, "All flags (approved, disputed, released) must be false in order to execute this function.") |
| 151 | + } |
| 152 | + ContractError::EscrowPropertiesMismatch => { |
| 153 | + write!( |
| 154 | + f, |
| 155 | + "The provided escrow properties do not match the stored escrow." |
| 156 | + ) |
| 157 | + } |
| 158 | + ContractError::ApproverOrReceiverFundsLessThanZero => { |
| 159 | + write!( |
| 160 | + f, |
| 161 | + "The funds of the approver or receiver must not be less or equal than 0." |
| 162 | + ) |
| 163 | + } |
| 164 | + ContractError::EscrowAlreadyReleased => { |
| 165 | + write!(f, "The escrow funds have been released.") |
| 166 | + } |
| 167 | + ContractError::IncompatibleEscrowWasmHash => { |
| 168 | + write!( |
| 169 | + f, |
| 170 | + "The provided contract address is not an instance of this escrow contract." |
| 171 | + ) |
| 172 | + } |
| 173 | + ContractError::PlatformAddressCannotBeChanged => { |
| 174 | + write!(f, "The platform address of the escrow cannot be changed.") |
| 175 | + } |
| 176 | + ContractError::DisputeResolverCannotDisputeTheEscrow => { |
| 177 | + write!(f, "The dispute resolver cannot dispute the escrow.") |
| 178 | + } |
| 179 | + ContractError::TotalAmountCannotBeZero => { |
| 180 | + write!(f, "The total amount to be distributed cannot be equal to zero.") |
| 181 | + } |
| 182 | + ContractError::InsufficientFundsForEscrowFunding => { |
| 183 | + write!(f, "The signer has insufficient funds to fund the escrow.") |
| 184 | + } |
| 185 | + ContractError::MilestoneToApproveDoesNotExist => { |
| 186 | + write!(f, "The milestone to approve does not exist") |
| 187 | + } |
| 188 | + ContractError::EscrowNotFullyProcessed => { |
| 189 | + write!(f, "The escrow must be fully processed before withdrawing remaining funds") |
| 190 | + } |
| 191 | + ContractError::TooManyDistributions => { |
| 192 | + write!(f, "Cannot define more than 50 distributions when resolving dispute") |
| 193 | + } |
| 194 | + ContractError::MilestoneToUpdateDoesNotExist => { |
| 195 | + write!(f, "The milestone to update does not exist") |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | +} |
0 commit comments