Skip to content

Commit

Permalink
Define RPCErrorCode enum
Browse files Browse the repository at this point in the history
Defines all the rpc error codes specified in bitcoin's protocol.h file
  • Loading branch information
Eunovo committed Oct 18, 2023
1 parent 8ac52f9 commit fd06fd9
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,106 @@ pub(crate) fn extract_bitcoind_error(err: &bitcoincore_rpc::Error) -> Option<&Rp
_ => None,
}
}

// Bitcoin RPC error codes
// https://github.com/bitcoin/bitcoin/blob/master/src/rpc/protocol.h
pub(crate) enum RPCErrorCode {
RpcInvalidRequest(i32),
RpcMethodNotFound(i32),
RpcInvalidParams(i32),
RpcInternalError(i32),
RpcParseError(i32),
RpcMiscError(i32),
RpcTypeError(i32),

RpcInvalidAddressOrKey(i32),
RpcOutOfMemory(i32),
RpcInvalidParameter(i32),
RpcDatabaseError(i32),
RpcDeserializationError(i32),
RpcVerifyError(i32),
RpcVerifyRejected(i32),
RpcVerifyAlreadyInChain(i32),
RpcInWarmup(i32),
RpcMethodDeprecated(i32),

RpcClientNotConnected(i32),
RpcClientInInitialDownload(i32),
RpcClientNodeAlreadyAdded(i32),
RpcClientNodeNotAdded(i32),
RpcClientNodeNotConnected(i32),
RpcClientInvalidIpOrSubnet(i32),
RpcClientP2pDisabled(i32),
RpcClientNodeCapacityReached(i32),
RpcClientMempoolDisabled(i32),

RpcWalletError(i32),
RpcWalletInsufficientFunds(i32),
RpcWalletInvalidLabelName(i32),
RpcWalletKeypoolRanOut(i32),
RpcWalletUnlockNeeded(i32),
RpcWalletPassphraseIncorrect(i32),
RpcWalletWrongEncState(i32),
RpcWalletEncryptionFailed(i32),
RpcWalletAlreadyUnlocked(i32),
RpcWalletNotFound(i32),
RpcWalletNotSpecified(i32),
RpcWalletAlreadyLoaded(i32),
RpcWalletAlreadyExisits(i32),

RpcForbiddenBySafeMode(i32),
}

impl RPCErrorCode {
pub(crate) fn parse_code(code: i32) -> Option<RPCErrorCode> {
match code {
-32600 => Some(RPCErrorCode::RpcInvalidRequest(code)),
-32601 => Some(RPCErrorCode::RpcMethodNotFound(code)),
-32602 => Some(RPCErrorCode::RpcInvalidParams(code)),
-32603 => Some(RPCErrorCode::RpcInternalError(code)),
-32700 => Some(RPCErrorCode::RpcParseError(code)),

-1 => Some(RPCErrorCode::RpcMiscError(code)),
-3 => Some(RPCErrorCode::RpcTypeError(code)),
-5 => Some(RPCErrorCode::RpcInvalidAddressOrKey(code)),
-7 => Some(RPCErrorCode::RpcOutOfMemory(code)),
-8 => Some(RPCErrorCode::RpcInvalidParameter(code)),

-20 => Some(RPCErrorCode::RpcDatabaseError(code)),
-22 => Some(RPCErrorCode::RpcDeserializationError(code)),
-25 => Some(RPCErrorCode::RpcVerifyError(code)),
-26 => Some(RPCErrorCode::RpcVerifyRejected(code)),
-27 => Some(RPCErrorCode::RpcVerifyAlreadyInChain(code)),
-28 => Some(RPCErrorCode::RpcInWarmup(code)),
-32 => Some(RPCErrorCode::RpcMethodDeprecated(code)),

-9 => Some(RPCErrorCode::RpcClientNotConnected(code)),
-10 => Some(RPCErrorCode::RpcClientInInitialDownload(code)),
-23 => Some(RPCErrorCode::RpcClientNodeAlreadyAdded(code)),
-24 => Some(RPCErrorCode::RpcClientNodeNotAdded(code)),
-29 => Some(RPCErrorCode::RpcClientNodeNotConnected(code)),
-30 => Some(RPCErrorCode::RpcClientInvalidIpOrSubnet(code)),
-31 => Some(RPCErrorCode::RpcClientP2pDisabled(code)),
-34 => Some(RPCErrorCode::RpcClientNodeCapacityReached(code)),

-33 => Some(RPCErrorCode::RpcClientMempoolDisabled(code)),

-4 => Some(RPCErrorCode::RpcWalletError(code)),
-6 => Some(RPCErrorCode::RpcWalletInsufficientFunds(code)),
-11 => Some(RPCErrorCode::RpcWalletInvalidLabelName(code)),
-12 => Some(RPCErrorCode::RpcWalletKeypoolRanOut(code)),
-13 => Some(RPCErrorCode::RpcWalletUnlockNeeded(code)),
-14 => Some(RPCErrorCode::RpcWalletPassphraseIncorrect(code)),
-15 => Some(RPCErrorCode::RpcWalletWrongEncState(code)),
-16 => Some(RPCErrorCode::RpcWalletEncryptionFailed(code)),
-17 => Some(RPCErrorCode::RpcWalletAlreadyUnlocked(code)),
-18 => Some(RPCErrorCode::RpcWalletNotFound(code)),
-19 => Some(RPCErrorCode::RpcWalletNotSpecified(code)),
-35 => Some(RPCErrorCode::RpcWalletAlreadyLoaded(code)),
-36 => Some(RPCErrorCode::RpcWalletAlreadyExisits(code)),

-2 => Some(RPCErrorCode::RpcForbiddenBySafeMode(code)),
_ => None,
}
}
}

0 comments on commit fd06fd9

Please sign in to comment.