2020-05-11 14:47:40 -07:00
|
|
|
use jsonrpc_core::{Error, ErrorCode};
|
|
|
|
use solana_sdk::clock::Slot;
|
|
|
|
|
|
|
|
const JSON_RPC_SERVER_ERROR_0: i64 = -32000;
|
|
|
|
const JSON_RPC_SERVER_ERROR_1: i64 = -32001;
|
2020-05-29 23:16:35 -07:00
|
|
|
const JSON_RPC_SERVER_ERROR_2: i64 = -32002;
|
2020-05-11 14:47:40 -07:00
|
|
|
|
|
|
|
pub enum RpcCustomError {
|
|
|
|
NonexistentClusterRoot {
|
|
|
|
cluster_root: Slot,
|
|
|
|
node_root: Slot,
|
|
|
|
},
|
|
|
|
BlockCleanedUp {
|
|
|
|
slot: Slot,
|
|
|
|
first_available_block: Slot,
|
|
|
|
},
|
2020-05-29 23:16:35 -07:00
|
|
|
SendTransactionPreflightFailure {
|
|
|
|
message: String,
|
|
|
|
},
|
2020-05-11 14:47:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RpcCustomError> for Error {
|
|
|
|
fn from(e: RpcCustomError) -> Self {
|
|
|
|
match e {
|
|
|
|
RpcCustomError::NonexistentClusterRoot {
|
|
|
|
cluster_root,
|
|
|
|
node_root,
|
|
|
|
} => Self {
|
|
|
|
code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_0),
|
|
|
|
message: format!(
|
|
|
|
"Cluster largest_confirmed_root {} does not exist on node. Node root: {}",
|
|
|
|
cluster_root, node_root,
|
|
|
|
),
|
|
|
|
data: None,
|
|
|
|
},
|
|
|
|
RpcCustomError::BlockCleanedUp {
|
|
|
|
slot,
|
|
|
|
first_available_block,
|
|
|
|
} => Self {
|
|
|
|
code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_1),
|
|
|
|
message: format!(
|
|
|
|
"Block {} cleaned up, does not exist on node. First available block: {}",
|
|
|
|
slot, first_available_block,
|
|
|
|
),
|
|
|
|
data: None,
|
|
|
|
},
|
2020-05-29 23:16:35 -07:00
|
|
|
RpcCustomError::SendTransactionPreflightFailure { message } => Self {
|
|
|
|
code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_2),
|
|
|
|
message,
|
|
|
|
data: None,
|
|
|
|
},
|
2020-05-11 14:47:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|