@@ -170,6 +170,67 @@ impl From<revault_tx::Error> for CommandError {
170170 }
171171}
172172
173+ impl CommandError {
174+ pub fn code ( & self ) -> ErrorCode {
175+ match self {
176+ CommandError :: UnknownOutpoint ( _) => ErrorCode :: RESOURCE_NOT_FOUND_ERROR ,
177+ CommandError :: InvalidStatus ( ..) => ErrorCode :: INVALID_STATUS_ERROR ,
178+ CommandError :: InvalidStatusFor ( ..) => ErrorCode :: INVALID_STATUS_ERROR ,
179+ CommandError :: InvalidParams ( _) => ErrorCode :: INVALID_PARAMS ,
180+ CommandError :: Communication ( e) => match e {
181+ CommunicationError :: Net ( _) => ErrorCode :: TRANSPORT_ERROR ,
182+ CommunicationError :: WatchtowerNack ( _, _) => ErrorCode :: WT_SIG_NACK ,
183+ CommunicationError :: SignatureStorage => ErrorCode :: COORDINATOR_SIG_STORE_ERROR ,
184+ CommunicationError :: SpendTxStorage => ErrorCode :: COORDINATOR_SPEND_STORE_ERROR ,
185+ CommunicationError :: CosigAlreadySigned => ErrorCode :: COSIGNER_ALREADY_SIGN_ERROR ,
186+ CommunicationError :: CosigInsanePsbt => ErrorCode :: COSIGNER_INSANE_ERROR ,
187+ } ,
188+ CommandError :: Bitcoind ( _) => ErrorCode :: BITCOIND_ERROR ,
189+ CommandError :: Tx ( _) => ErrorCode :: INTERNAL_ERROR ,
190+ CommandError :: SpendFeerateTooLow ( _, _) => ErrorCode :: INVALID_PARAMS ,
191+ // TODO: some of these probably need specific error codes
192+ CommandError :: SpendTooLarge
193+ | CommandError :: SpendUnknownUnVault ( _)
194+ | CommandError :: UnknownSpend ( _)
195+ | CommandError :: SpendSpent ( _)
196+ | CommandError :: SpendNotEnoughSig ( _, _)
197+ | CommandError :: SpendInvalidSig ( _)
198+ | CommandError :: MissingCpfpKey => ErrorCode :: INVALID_PARAMS ,
199+
200+ CommandError :: StakeholderOnly | CommandError :: ManagerOnly => ErrorCode :: INVALID_REQUEST ,
201+ CommandError :: Race => ErrorCode :: INTERNAL_ERROR ,
202+ }
203+ }
204+ }
205+
206+ #[ allow( non_camel_case_types) ]
207+ pub enum ErrorCode {
208+ /// Invalid Params (identical to jsonrpc error code)
209+ INVALID_PARAMS = -32602 ,
210+ /// Invalid Request (identical to jsonrpc error code)
211+ INVALID_REQUEST = -32600 ,
212+ /// Internal error (identical to jsonrpc error code)
213+ INTERNAL_ERROR = -32603 ,
214+ /// An error internal to revault_net, generally a transport error
215+ TRANSPORT_ERROR = 12000 ,
216+ /// The watchtower refused our signatures
217+ WT_SIG_NACK = 13_000 ,
218+ /// The Coordinator told us they could not store our signature
219+ COORDINATOR_SIG_STORE_ERROR = 13100 ,
220+ /// The Coordinator told us they could not store our Spend transaction
221+ COORDINATOR_SPEND_STORE_ERROR = 13101 ,
222+ /// The Cosigning Server returned null to our request!
223+ COSIGNER_ALREADY_SIGN_ERROR = 13201 ,
224+ /// The Cosigning Server tried to fool us!
225+ COSIGNER_INSANE_ERROR = 13202 ,
226+ /// Bitcoind error
227+ BITCOIND_ERROR = 14000 ,
228+ /// Resource not found
229+ RESOURCE_NOT_FOUND_ERROR = 15000 ,
230+ /// Vault status was invalid
231+ INVALID_STATUS_ERROR = 15001 ,
232+ }
233+
173234macro_rules! stakeholder_only {
174235 ( $revaultd: ident) => {
175236 if !$revaultd. is_stakeholder( ) {
0 commit comments