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 22, 2023
1 parent 8ac52f9 commit eb63c2c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ crossbeam-channel = "0.5"
dirs-next = "2.0"
env_logger = "0.10"
log = "0.4"
num-traits = "0.2"
num-derive = "0.4"
parking_lot = "0.12"
prometheus = { version = "0.13", optional = true }
rayon = "1.8"
Expand Down
51 changes: 51 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,54 @@ 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
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive)]
pub(crate) enum RPCErrorCode {
RpcInvalidRequest = -32600,
RpcMethodNotFound = -32601,
RpcInvalidParams = -32602,
RpcInternalError = -32603,
RpcParseError = -32700,

RpcMiscError = -1,
RpcTypeError = -3,
RpcInvalidAddressOrKey = -5,
RpcOutOfMemory = -7,
RpcInvalidParameter = -8,

RpcDatabaseError = -20,
RpcDeserializationError = -22,
RpcVerifyError = -25,
RpcVerifyRejected = -26,
RpcVerifyAlreadyInChain = -27,
RpcInWarmup = -28,
RpcMethodDeprecated = -32,

RpcClientNotConnected = -9,
RpcClientInInitialDownload = -10,
RpcClientNodeAlreadyAdded = -23,
RpcClientNodeNotAdded = -24,
RpcClientNodeNotConnected = -29,
RpcClientInvalidIpOrSubnet = -30,
RpcClientP2pDisabled = -31,
RpcClientNodeCapacityReached = -34,
RpcClientMempoolDisabled = -33,

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

RpcForbiddenBySafeMode = -2,
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ extern crate anyhow;
#[macro_use]
extern crate log;

#[macro_use]
extern crate num_derive;

#[macro_use]
extern crate serde_derive;

Expand Down

0 comments on commit eb63c2c

Please sign in to comment.