mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-16 15:58:14 +00:00
add response bases
This commit is contained in:
parent
9188b13330
commit
be7ca959b8
5 changed files with 69 additions and 10 deletions
24
rpc/types/src/data/access_request_base.rs
Normal file
24
rpc/types/src/data/access_request_base.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Status;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- ResponseBase
|
||||
/// TODO
|
||||
///
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h#L114-L122>.
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct AccessRequestBase {
|
||||
/// TODO
|
||||
client: String,
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
}
|
27
rpc/types/src/data/access_response_base.rs
Normal file
27
rpc/types/src/data/access_response_base.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::data::ResponseBase;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- ResponseBase
|
||||
/// TODO
|
||||
///
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h#L124-L136>.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct AccessResponseBase {
|
||||
/// TODO
|
||||
#[serde(flatten)]
|
||||
response_base: ResponseBase,
|
||||
/// TODO
|
||||
credits: u64,
|
||||
/// TODO
|
||||
top_hash: String,
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
}
|
|
@ -2,8 +2,10 @@
|
|||
//!
|
||||
//! TODO
|
||||
|
||||
mod access_response_base;
|
||||
mod binary_string;
|
||||
mod response_base;
|
||||
|
||||
pub use access_response_base::AccessResponseBase;
|
||||
pub use binary_string::BinaryString;
|
||||
pub use response_base::ResponseBase;
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
//! TODO
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Status;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- ResponseBase
|
||||
/// TODO
|
||||
///
|
||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h#L101-L112>.
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct ResponseBase {
|
||||
/// TODO
|
||||
status: Status,
|
||||
|
|
|
@ -60,10 +60,12 @@ use crate::constants::{
|
|||
/// assert_eq!(format!("{:?}", Status::PaymentRequired), "PaymentRequired");
|
||||
/// assert_eq!(format!("{:?}", other), "Other(\"hello\")");
|
||||
/// ```
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
||||
)]
|
||||
pub enum Status {
|
||||
// FIXME:
|
||||
// `#[serde(rename = "")]` onlys takes raw string literals?
|
||||
// `#[serde(rename = "")]` only takes raw string literals?
|
||||
// We have to re-type the constants here...
|
||||
/// Successful RPC response, everything is OK; [`CORE_RPC_STATUS_OK`].
|
||||
#[serde(rename = "OK")]
|
||||
|
@ -82,12 +84,12 @@ pub enum Status {
|
|||
#[serde(rename = "PAYMENT REQUIRED")]
|
||||
PaymentRequired,
|
||||
|
||||
#[serde(untagged)]
|
||||
#[serde(other)]
|
||||
/// Some unknown other string.
|
||||
///
|
||||
/// This exists to act as a catch-all if `monerod` adds
|
||||
/// a string and a Cuprate node hasn't updated yet.
|
||||
Other(String),
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl From<String> for Status {
|
||||
|
@ -97,7 +99,7 @@ impl From<String> for Status {
|
|||
CORE_RPC_STATUS_BUSY => Self::Busy,
|
||||
CORE_RPC_STATUS_NOT_MINING => Self::NotMining,
|
||||
CORE_RPC_STATUS_PAYMENT_REQUIRED => Self::PaymentRequired,
|
||||
_ => Self::Other(s),
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +111,7 @@ impl AsRef<str> for Status {
|
|||
Self::Busy => CORE_RPC_STATUS_BUSY,
|
||||
Self::NotMining => CORE_RPC_STATUS_NOT_MINING,
|
||||
Self::PaymentRequired => CORE_RPC_STATUS_PAYMENT_REQUIRED,
|
||||
Self::Other(s) => s,
|
||||
Self::Unknown => "UNKNOWN",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,10 +137,7 @@ impl EpeeValue for Status {
|
|||
}
|
||||
|
||||
fn should_write(&self) -> bool {
|
||||
match self {
|
||||
Self::Ok | Self::Busy | Self::NotMining | Self::PaymentRequired => true,
|
||||
Self::Other(s) => !s.is_empty(),
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn epee_default_value() -> Option<Self> {
|
||||
|
|
Loading…
Reference in a new issue