mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
Compare commits
2 commits
89191ce3bc
...
1719d7db84
Author | SHA1 | Date | |
---|---|---|---|
|
1719d7db84 | ||
|
3a799219b8 |
10 changed files with 218 additions and 166 deletions
|
@ -27,8 +27,8 @@ members = [
|
|||
"p2p/p2p-core",
|
||||
"p2p/bucket",
|
||||
"p2p/dandelion-tower",
|
||||
"p2p/address-book",
|
||||
"p2p/async-buffer",
|
||||
"p2p/address-book",
|
||||
|
||||
# Storage
|
||||
"storage/blockchain",
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[cfg(any(feature = "epee", feature = "serde"))]
|
||||
use crate::defaults::{default_false, default_zero};
|
||||
use crate::defaults::default;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Definitions
|
||||
define_request_and_response! {
|
||||
|
@ -36,7 +36,7 @@ define_request_and_response! {
|
|||
heights: Vec<u64>,
|
||||
},
|
||||
AccessResponseBase {
|
||||
blocks: Vec<BlockCompleteEntry>,
|
||||
blocks: Vec<BlockCompleteEntry> = default::<Vec<BlockCompleteEntry>>(), "default",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,11 +46,11 @@ define_request_and_response! {
|
|||
core_rpc_server_commands_defs.h => 309..=338,
|
||||
GetHashes,
|
||||
Request {
|
||||
block_ids: ByteArrayVec<32>,
|
||||
block_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
|
||||
start_height: u64,
|
||||
},
|
||||
AccessResponseBase {
|
||||
m_blocks_ids: ByteArrayVec<32>,
|
||||
m_blocks_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
|
||||
start_height: u64,
|
||||
current_height: u64,
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ define_request_and_response! {
|
|||
txid: [u8; 32],
|
||||
},
|
||||
AccessResponseBase {
|
||||
o_indexes: Vec<u64>,
|
||||
o_indexes: Vec<u64> = default::<Vec<u64>>(), "default",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,11 +92,11 @@ define_request_and_response! {
|
|||
core_rpc_server_commands_defs.h => 512..=565,
|
||||
GetOuts,
|
||||
Request {
|
||||
outputs: Vec<GetOutputsOut>,
|
||||
get_txid: bool = default_false(), "default_false",
|
||||
outputs: Vec<GetOutputsOut> = default::<Vec<GetOutputsOut>>(), "default",
|
||||
get_txid: bool,
|
||||
},
|
||||
AccessResponseBase {
|
||||
outs: Vec<OutKeyBin>,
|
||||
outs: Vec<OutKeyBin> = default::<Vec<OutKeyBin>>(), "default",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ define_request_and_response! {
|
|||
GetTransactionPoolHashes,
|
||||
Request {},
|
||||
AccessResponseBase {
|
||||
tx_hashes: ByteArrayVec<32>,
|
||||
tx_hashes: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,22 +119,22 @@ define_request_and_response! {
|
|||
GetBlocks,
|
||||
|
||||
Request {
|
||||
requested_info: u8 = default_zero::<u8>(), "default_zero",
|
||||
requested_info: u8 = default::<u8>(), "default",
|
||||
// FIXME: This is a `std::list` in `monerod` because...?
|
||||
block_ids: ByteArrayVec<32>,
|
||||
block_ids: ByteArrayVec<32> = default::<ByteArrayVec<32>>(), "default",
|
||||
start_height: u64,
|
||||
prune: bool,
|
||||
no_miner_tx: bool = default_false(), "default_false",
|
||||
pool_info_since: u64 = default_zero::<u64>(), "default_zero",
|
||||
no_miner_tx: bool,
|
||||
pool_info_since: u64 = default::<u64>(), "default",
|
||||
},
|
||||
|
||||
// TODO: add `top_block_hash` field
|
||||
// <https://github.com/monero-project/monero/blame/893916ad091a92e765ce3241b94e706ad012b62a/src/rpc/core_rpc_server_commands_defs.h#L263>
|
||||
AccessResponseBase {
|
||||
blocks: Vec<BlockCompleteEntry>,
|
||||
blocks: Vec<BlockCompleteEntry> = default::<Vec<BlockCompleteEntry>>(), "default",
|
||||
start_height: u64,
|
||||
current_height: u64,
|
||||
output_indices: Vec<BlockOutputIndices>,
|
||||
output_indices: Vec<BlockOutputIndices> = default::<Vec<BlockOutputIndices>>(), "default",
|
||||
daemon_time: u64,
|
||||
pool_info: PoolInfo,
|
||||
}
|
||||
|
|
|
@ -5,65 +5,29 @@
|
|||
//! has a [`crate::json::GetBlockRequest::height`]
|
||||
//! field and a [`crate::json::GetBlockRequest::hash`]
|
||||
//! field, when the RPC interface reads JSON without
|
||||
//! `height`, it will use [`default_height`] to fill that in.
|
||||
//! `height`, it will use [`default`] to fill that in.
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TODO
|
||||
/// Default [`bool`] type used in request/response types, `false`.
|
||||
#[inline]
|
||||
pub(crate) const fn default_false() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Default [`bool`] type used in _some_ request/response types, `true`.
|
||||
#[inline]
|
||||
pub(crate) const fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Default [`String`] type used in request/response types.
|
||||
#[inline]
|
||||
pub(crate) const fn default_string() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
/// Default block height used in request/response types.
|
||||
#[inline]
|
||||
pub(crate) const fn default_height() -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
/// Default [`Vec`] used in request/response types.
|
||||
#[inline]
|
||||
pub(crate) const fn default_vec<T>() -> Vec<T> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Default `0` value used in request/response types.
|
||||
#[inline]
|
||||
pub(crate) fn default_zero<T: From<u8>>() -> T {
|
||||
T::from(0)
|
||||
}
|
||||
|
||||
/// Default `1` value used in request/response types.
|
||||
#[inline]
|
||||
pub(crate) fn default_one<T: From<u8>>() -> T {
|
||||
T::from(1)
|
||||
}
|
||||
|
||||
/// Generate a default `T` to be used in request/response types.
|
||||
#[inline]
|
||||
pub(crate) fn default<T: Default>() -> T {
|
||||
T::default()
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
/// Tests that [`default_zero`] returns `0` on all unsigned numbers.
|
||||
#[test]
|
||||
fn zero() {
|
||||
assert_eq!(default_zero::<usize>(), 0);
|
||||
assert_eq!(default_zero::<u64>(), 0);
|
||||
assert_eq!(default_zero::<u32>(), 0);
|
||||
assert_eq!(default_zero::<u16>(), 0);
|
||||
assert_eq!(default_zero::<u8>(), 0);
|
||||
}
|
||||
}
|
||||
mod test {}
|
||||
|
|
|
@ -20,10 +20,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[cfg(any(feature = "epee", feature = "serde"))]
|
||||
use crate::defaults::{
|
||||
default_false, default_height, default_one, default_string, default_true, default_vec,
|
||||
default_zero,
|
||||
};
|
||||
use crate::defaults::{default, default_one, default_true};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Definitions
|
||||
// This generates 2 structs:
|
||||
|
@ -81,15 +78,15 @@ define_request_and_response! {
|
|||
//
|
||||
// This is a HACK since `serde`'s default attribute only takes in
|
||||
// string literals and macros (stringify) within attributes do not work.
|
||||
extra_nonce: String = default_string(), "default_string",
|
||||
prev_block: String = default_string(), "default_string",
|
||||
extra_nonce: String = default::<String>(), "default",
|
||||
prev_block: String = default::<String>(), "default",
|
||||
|
||||
// Another optional expression:
|
||||
// This indicates to the macro to (de)serialize
|
||||
// this field as another type in epee.
|
||||
//
|
||||
// See `cuprate_epee_encoding::epee_object` for info.
|
||||
reserve_size: u64 = default_zero::<u64>(), "default_zero" /* as Type */,
|
||||
reserve_size: u64 /* as Type */,
|
||||
|
||||
wallet_address: String,
|
||||
},
|
||||
|
@ -125,7 +122,7 @@ define_request_and_response! {
|
|||
difficulty: u64,
|
||||
expected_reward: u64,
|
||||
height: u64,
|
||||
next_seed_hash: String = default_string(), "default_string",
|
||||
next_seed_hash: String,
|
||||
prev_hash: Hex<32>,
|
||||
reserved_offset: u64,
|
||||
seed_hash: Hex<32>,
|
||||
|
@ -200,7 +197,7 @@ define_request_and_response! {
|
|||
|
||||
Request {
|
||||
amount_of_blocks: u64,
|
||||
prev_block: String = default_string(), "default_string",
|
||||
prev_block: String = default::<String>(), "default",
|
||||
starting_nonce: u32,
|
||||
wallet_address: String,
|
||||
},
|
||||
|
@ -220,7 +217,7 @@ define_request_and_response! {
|
|||
|
||||
#[derive(Copy)]
|
||||
Request {
|
||||
fill_pow_hash: bool = default_false(), "default_false",
|
||||
fill_pow_hash: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -235,14 +232,14 @@ define_request_and_response! {
|
|||
GetBlockHeaderByHash,
|
||||
|
||||
Request {
|
||||
hash: Hex<32>,
|
||||
hashes: Vec<Hex<32>> = default_vec::<Hex<32>>(), "default_vec",
|
||||
fill_pow_hash: bool = default_false(), "default_false",
|
||||
hash: Hex<32> = default::<Hex<32>>(), "default",
|
||||
hashes: Vec<Hex<32>> = default::<Vec<Hex<32>>>(), "default",
|
||||
fill_pow_hash: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
block_header: BlockHeader,
|
||||
block_headers: Vec<BlockHeader> = default_vec::<BlockHeader>(), "default_vec",
|
||||
block_headers: Vec<BlockHeader>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,7 +253,7 @@ define_request_and_response! {
|
|||
#[derive(Copy)]
|
||||
Request {
|
||||
height: u64,
|
||||
fill_pow_hash: bool = default_false(), "default_false",
|
||||
fill_pow_hash: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -275,7 +272,7 @@ define_request_and_response! {
|
|||
Request {
|
||||
start_height: u64,
|
||||
end_height: u64,
|
||||
fill_pow_hash: bool = default_false(), "default_false",
|
||||
fill_pow_hash: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -293,9 +290,9 @@ define_request_and_response! {
|
|||
// `monerod` has both `hash` and `height` fields.
|
||||
// In the RPC handler, if `hash.is_empty()`, it will use it, else, it uses `height`.
|
||||
// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2674>
|
||||
hash: String = default_string(), "default_string",
|
||||
height: u64 = default_height(), "default_height",
|
||||
fill_pow_hash: bool = default_false(), "default_false",
|
||||
hash: String = default::<String>(), "default",
|
||||
height: u64 = default::<u64>(), "default",
|
||||
fill_pow_hash: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -305,7 +302,7 @@ define_request_and_response! {
|
|||
/// to create this JSON string in a type-safe manner.
|
||||
json: String,
|
||||
miner_tx_hash: Hex<32>,
|
||||
tx_hashes: Vec<Hex<32>> = default_vec::<Hex<32>>(), "default_vec",
|
||||
tx_hashes: Vec<Hex<32>>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,7 +316,6 @@ define_request_and_response! {
|
|||
Request {},
|
||||
|
||||
ResponseBase {
|
||||
// FIXME: This is a `std::list` in `monerod` because...?
|
||||
connections: Vec<ConnectionInfo>,
|
||||
}
|
||||
}
|
||||
|
@ -449,7 +445,7 @@ define_request_and_response! {
|
|||
FlushTransactionPool (restricted),
|
||||
|
||||
Request {
|
||||
txids: Vec<Hex<32>> = default_vec::<Hex<32>>(), "default_vec",
|
||||
txids: Vec<Hex<32>> = default::<Vec<Hex<32>>>(), "default",
|
||||
},
|
||||
|
||||
#[repr(transparent)]
|
||||
|
@ -465,11 +461,11 @@ define_request_and_response! {
|
|||
GetOutputHistogram,
|
||||
|
||||
Request {
|
||||
amounts: Vec<u64>,
|
||||
min_count: u64 = default_zero::<u64>(), "default_zero",
|
||||
max_count: u64 = default_zero::<u64>(), "default_zero",
|
||||
unlocked: bool = default_false(), "default_false",
|
||||
recent_cutoff: u64 = default_zero::<u64>(), "default_zero",
|
||||
amounts: Vec<u64> = default::<Vec<u64>>(), "default",
|
||||
min_count: u64 = default::<u64>(), "default",
|
||||
max_count: u64 = default::<u64>(), "default",
|
||||
unlocked: bool = default::<bool>(), "default",
|
||||
recent_cutoff: u64 = default::<u64>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -510,9 +506,9 @@ define_request_and_response! {
|
|||
ResponseBase {
|
||||
version: u32,
|
||||
release: bool,
|
||||
current_height: u64 = default_zero::<u64>(), "default_zero",
|
||||
target_height: u64 = default_zero::<u64>(), "default_zero",
|
||||
hard_forks: Vec<HardForkEntry> = default_vec(), "default_vec",
|
||||
current_height: u64,
|
||||
target_height: u64,
|
||||
hard_forks: Vec<HardForkEntry>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -524,7 +520,7 @@ define_request_and_response! {
|
|||
GetFeeEstimate,
|
||||
|
||||
Request {
|
||||
grace_blocks: u64 = default_zero::<u64>(), "default_zero",
|
||||
grace_blocks: u64 = default::<u64>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -554,7 +550,7 @@ define_request_and_response! {
|
|||
RelayTx (restricted),
|
||||
|
||||
Request {
|
||||
txids: Vec<Hex<32>>,
|
||||
txids: Vec<Hex<32>> = default::<Vec<Hex<32>>>(), "default",
|
||||
},
|
||||
|
||||
#[repr(transparent)]
|
||||
|
@ -576,10 +572,8 @@ define_request_and_response! {
|
|||
height: u64,
|
||||
next_needed_pruning_seed: u32,
|
||||
overview: String,
|
||||
// FIXME: This is a `std::list` in `monerod` because...?
|
||||
peers: Vec<SyncInfoPeer> = default_vec::<SyncInfoPeer>(), "default_vec",
|
||||
// FIXME: This is a `std::list` in `monerod` because...?
|
||||
spans: Vec<Span> = default_vec::<Span>(), "default_vec",
|
||||
peers: Vec<SyncInfoPeer>,
|
||||
spans: Vec<Span>,
|
||||
target_height: u64,
|
||||
}
|
||||
}
|
||||
|
@ -610,10 +604,10 @@ define_request_and_response! {
|
|||
Request {
|
||||
amounts: Vec<u64>,
|
||||
binary: bool = default_true(), "default_true",
|
||||
compress: bool = default_false(), "default_false",
|
||||
cumulative: bool = default_false(), "default_false",
|
||||
from_height: u64 = default_zero::<u64>(), "default_zero",
|
||||
to_height: u64 = default_zero::<u64>(), "default_zero",
|
||||
compress: bool = default::<bool>(), "default",
|
||||
cumulative: bool = default::<bool>(), "default",
|
||||
from_height: u64 = default::<u64>(), "default",
|
||||
to_height: u64 = default::<u64>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
|
@ -649,7 +643,7 @@ define_request_and_response! {
|
|||
|
||||
#[derive(Copy)]
|
||||
Request {
|
||||
check: bool = default_false(), "default_false",
|
||||
check: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
ResponseBase {
|
||||
|
@ -688,8 +682,8 @@ define_request_and_response! {
|
|||
|
||||
#[derive(Copy)]
|
||||
Request {
|
||||
bad_txs: bool = default_false(), "default_false",
|
||||
bad_blocks: bool = default_false(), "default_false",
|
||||
bad_txs: bool,
|
||||
bad_blocks: bool,
|
||||
},
|
||||
|
||||
ResponseBase {}
|
||||
|
|
|
@ -291,6 +291,7 @@ macro_rules! define_response {
|
|||
}
|
||||
) => {
|
||||
$( #[$attr] )*
|
||||
#[cfg_attr(feature = "serde", serde(default))] // TODO: link epee field not serializing oddity
|
||||
pub struct $t {
|
||||
$(
|
||||
$( #[$field_attr] )*
|
||||
|
@ -328,6 +329,7 @@ macro_rules! define_response {
|
|||
}
|
||||
) => {
|
||||
$( #[$attr] )*
|
||||
#[cfg_attr(feature = "serde", serde(default))] // TODO: link epee field not serializing oddity
|
||||
pub struct $t {
|
||||
#[cfg_attr(feature = "serde", serde(flatten))]
|
||||
pub base: $base,
|
||||
|
|
|
@ -20,6 +20,7 @@ use cuprate_epee_encoding::{
|
|||
/// Used in [`crate::other::IsKeyImageSpentResponse`].
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(try_from = "u8", into = "u8"))]
|
||||
#[repr(u8)]
|
||||
pub enum KeyImageSpentStatus {
|
||||
Unspent = 0,
|
||||
|
@ -68,6 +69,19 @@ impl KeyImageSpentStatus {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<KeyImageSpentStatus> for u8 {
|
||||
fn from(value: KeyImageSpentStatus) -> Self {
|
||||
value.to_u8()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for KeyImageSpentStatus {
|
||||
type Error = u8;
|
||||
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
||||
Self::from_u8(value).ok_or(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "epee")]
|
||||
impl EpeeValue for KeyImageSpentStatus {
|
||||
const MARKER: Marker = u8::MARKER;
|
||||
|
|
|
@ -20,6 +20,7 @@ use cuprate_epee_encoding::{
|
|||
/// Used in [`crate::bin::GetBlocksRequest`].
|
||||
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(try_from = "u8", into = "u8"))]
|
||||
#[repr(u8)]
|
||||
pub enum RequestedInfo {
|
||||
#[default]
|
||||
|
@ -69,6 +70,19 @@ impl RequestedInfo {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<RequestedInfo> for u8 {
|
||||
fn from(value: RequestedInfo) -> Self {
|
||||
value.to_u8()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for RequestedInfo {
|
||||
type Error = u8;
|
||||
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
||||
Self::from_u8(value).ok_or(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "epee")]
|
||||
impl EpeeValue for RequestedInfo {
|
||||
const MARKER: Marker = u8::MARKER;
|
||||
|
|
|
@ -9,7 +9,7 @@ use cuprate_hex::Hex;
|
|||
use cuprate_types::HardFork;
|
||||
|
||||
#[cfg(any(feature = "epee", feature = "serde"))]
|
||||
use crate::defaults::default_zero;
|
||||
use crate::defaults::default;
|
||||
|
||||
use crate::macros::monero_definition_link;
|
||||
|
||||
|
@ -41,6 +41,7 @@ macro_rules! define_struct_and_impl_epee {
|
|||
$(
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
$( #[$struct_attr] )*
|
||||
pub struct $struct_name {
|
||||
$(
|
||||
|
@ -148,9 +149,7 @@ define_struct_and_impl_epee! {
|
|||
)]
|
||||
/// Used in [`crate::json::SetBansRequest`].
|
||||
SetBan {
|
||||
#[cfg_attr(feature = "serde", serde(default = "crate::defaults::default_string"))]
|
||||
host: String,
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_zero"))]
|
||||
ip: u32,
|
||||
ban: bool,
|
||||
seconds: u32,
|
||||
|
@ -293,8 +292,7 @@ define_struct_and_impl_epee! {
|
|||
relayed: bool,
|
||||
tx_blob: String,
|
||||
tx_json: cuprate_types::json::tx::Transaction,
|
||||
#[cfg_attr(feature = "serde", serde(default = "default_zero"))]
|
||||
weight: u64 = default_zero::<u64>(),
|
||||
weight: u64 = default::<u64>(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use cuprate_hex::Hex;
|
||||
use cuprate_types::rpc::{OutKey, Peer, PublicNode, TxpoolStats};
|
||||
|
||||
use crate::{
|
||||
|
@ -16,7 +17,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[cfg(any(feature = "serde", feature = "epee"))]
|
||||
use crate::defaults::{default_false, default_string, default_true, default_vec, default_zero};
|
||||
use crate::defaults::{default, default_true};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Definitions
|
||||
define_request_and_response! {
|
||||
|
@ -27,7 +28,7 @@ define_request_and_response! {
|
|||
Request {},
|
||||
|
||||
ResponseBase {
|
||||
hash: String,
|
||||
hash: Hex<32>,
|
||||
height: u64,
|
||||
}
|
||||
}
|
||||
|
@ -39,22 +40,22 @@ define_request_and_response! {
|
|||
GetTransactions,
|
||||
|
||||
Request {
|
||||
txs_hashes: Vec<String> = default_vec::<String>(), "default_vec",
|
||||
txs_hashes: Vec<Hex<32>>,
|
||||
// FIXME: this is documented as optional but it isn't serialized as an optional
|
||||
// but it is set _somewhere_ to false in `monerod`
|
||||
// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server_commands_defs.h#L382>
|
||||
decode_as_json: bool = default_false(), "default_false",
|
||||
prune: bool = default_false(), "default_false",
|
||||
split: bool = default_false(), "default_false",
|
||||
decode_as_json: bool = default::<bool>(), "default",
|
||||
prune: bool = default::<bool>(), "default",
|
||||
split: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
txs_as_hex: Vec<String> = default_vec::<String>(), "default_vec",
|
||||
txs_as_hex: Vec<String>,
|
||||
/// `cuprate_rpc_types::json::tx::Transaction` should be used
|
||||
/// to create this JSON string in a type-safe manner.
|
||||
txs_as_json: Vec<String> = default_vec::<String>(), "default_vec",
|
||||
missed_tx: Vec<String> = default_vec::<String>(), "default_vec",
|
||||
txs: Vec<TxEntry> = default_vec::<TxEntry>(), "default_vec",
|
||||
txs_as_json: Vec<String>,
|
||||
missed_tx: Vec<Hex<32>>,
|
||||
txs: Vec<TxEntry>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +67,7 @@ define_request_and_response! {
|
|||
Request {},
|
||||
|
||||
AccessResponseBase {
|
||||
blks_hashes: Vec<String>,
|
||||
blks_hashes: Vec<Hex<32>>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,11 +79,11 @@ define_request_and_response! {
|
|||
IsKeyImageSpent,
|
||||
|
||||
Request {
|
||||
key_images: Vec<String>,
|
||||
key_images: Vec<Hex<32>>,
|
||||
},
|
||||
|
||||
AccessResponseBase {
|
||||
/// FIXME: These are [`KeyImageSpentStatus`](crate::misc::KeyImageSpentStatus) in [`u8`] form.
|
||||
/// These [`u8`]s are [`crate::misc::KeyImageSpentStatus`].
|
||||
spent_status: Vec<u8>,
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +97,7 @@ define_request_and_response! {
|
|||
|
||||
Request {
|
||||
tx_as_hex: String,
|
||||
do_not_relay: bool = default_false(), "default_false",
|
||||
do_not_relay: bool = default::<bool>(), "default",
|
||||
do_sanity_checks: bool = default_true(), "default_true",
|
||||
},
|
||||
|
||||
|
@ -106,7 +107,7 @@ define_request_and_response! {
|
|||
invalid_input: bool,
|
||||
invalid_output: bool,
|
||||
low_mixin: bool,
|
||||
nonzero_unlock_time: bool = default_false(), "default_false",
|
||||
nonzero_unlock_time: bool,
|
||||
not_relayed: bool,
|
||||
overspend: bool,
|
||||
reason: String,
|
||||
|
@ -189,7 +190,7 @@ define_request_and_response! {
|
|||
|
||||
Request {
|
||||
public_only: bool = default_true(), "default_true",
|
||||
include_blocked: bool = default_false(), "default_false",
|
||||
include_blocked: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
ResponseBase {
|
||||
|
@ -207,7 +208,7 @@ define_request_and_response! {
|
|||
|
||||
#[derive(Copy)]
|
||||
Request {
|
||||
visible: bool = default_false(), "default_false",
|
||||
visible: bool,
|
||||
},
|
||||
|
||||
ResponseBase {}
|
||||
|
@ -236,7 +237,7 @@ define_request_and_response! {
|
|||
SetLogCategories (restricted),
|
||||
|
||||
Request {
|
||||
categories: String = default_string(), "default_string",
|
||||
categories: String = default::<String>(), "default",
|
||||
},
|
||||
|
||||
ResponseBase {
|
||||
|
@ -253,9 +254,9 @@ define_request_and_response! {
|
|||
|
||||
Request {
|
||||
address: String,
|
||||
username: String = default_string(), "default_string",
|
||||
password: String = default_string(), "default_string",
|
||||
proxy: String = default_string(), "default_string",
|
||||
username: String = default::<String>(), "default",
|
||||
password: String = default::<String>(), "default",
|
||||
proxy: String = default::<String>(), "default",
|
||||
},
|
||||
|
||||
Response {
|
||||
|
@ -325,9 +326,8 @@ define_request_and_response! {
|
|||
SetLimit (restricted),
|
||||
|
||||
Request {
|
||||
// FIXME: These may need to be `Option<i64>`.
|
||||
limit_down: i64 = default_zero::<i64>(), "default_zero",
|
||||
limit_up: i64 = default_zero::<i64>(), "default_zero",
|
||||
limit_down: i64 = default::<i64>(), "default",
|
||||
limit_up: i64 = default::<i64>(), "default",
|
||||
},
|
||||
|
||||
ResponseBase {
|
||||
|
@ -409,7 +409,7 @@ define_request_and_response! {
|
|||
|
||||
Request {
|
||||
command: String,
|
||||
path: String = default_string(), "default_string",
|
||||
path: String = default::<String>(), "default",
|
||||
},
|
||||
ResponseBase {
|
||||
auto_uri: String,
|
||||
|
@ -447,7 +447,7 @@ define_request_and_response! {
|
|||
Request {},
|
||||
|
||||
ResponseBase {
|
||||
tx_hashes: Vec<String>,
|
||||
tx_hashes: Vec<Hex<32>>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,14 +459,14 @@ define_request_and_response! {
|
|||
GetPublicNodes (restricted),
|
||||
|
||||
Request {
|
||||
gray: bool = default_false(), "default_false",
|
||||
gray: bool = default::<bool>(), "default",
|
||||
white: bool = default_true(), "default_true",
|
||||
include_blocked: bool = default_false(), "default_false",
|
||||
include_blocked: bool = default::<bool>(), "default",
|
||||
},
|
||||
|
||||
ResponseBase {
|
||||
gray: Vec<PublicNode> = default_vec::<PublicNode>(), "default_vec",
|
||||
white: Vec<PublicNode> = default_vec::<PublicNode>(), "default_vec",
|
||||
gray: Vec<PublicNode>,
|
||||
white: Vec<PublicNode>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -674,7 +674,9 @@ mod test {
|
|||
other::GET_HEIGHT_RESPONSE,
|
||||
Some(GetHeightResponse {
|
||||
base: ResponseBase::OK,
|
||||
hash: "68bb1a1cff8e2a44c3221e8e1aff80bc6ca45d06fa8eff4d2a3a7ac31d4efe3f".into(),
|
||||
hash: Hex(hex!(
|
||||
"68bb1a1cff8e2a44c3221e8e1aff80bc6ca45d06fa8eff4d2a3a7ac31d4efe3f"
|
||||
)),
|
||||
height: 3195160,
|
||||
}),
|
||||
);
|
||||
|
@ -685,9 +687,9 @@ mod test {
|
|||
test_json(
|
||||
other::GET_TRANSACTIONS_REQUEST,
|
||||
Some(GetTransactionsRequest {
|
||||
txs_hashes: vec![
|
||||
"d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408".into(),
|
||||
],
|
||||
txs_hashes: vec![Hex(hex!(
|
||||
"d6e48158472848e6687173a91ae6eebfa3e1d778e65252ee99d7515d63090408"
|
||||
))],
|
||||
decode_as_json: false,
|
||||
prune: false,
|
||||
split: false,
|
||||
|
@ -697,7 +699,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn get_transactions_response() {
|
||||
test_json::<GetTransactionsRequest>(other::GET_TRANSACTIONS_RESPONSE, None);
|
||||
test_json::<GetTransactionsResponse>(other::GET_TRANSACTIONS_RESPONSE, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -706,9 +708,9 @@ mod test {
|
|||
other::GET_ALT_BLOCKS_HASHES_RESPONSE,
|
||||
Some(GetAltBlocksHashesResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
blks_hashes: vec![
|
||||
"8ee10db35b1baf943f201b303890a29e7d45437bd76c2bd4df0d2f2ee34be109".into(),
|
||||
],
|
||||
blks_hashes: vec![Hex(hex!(
|
||||
"8ee10db35b1baf943f201b303890a29e7d45437bd76c2bd4df0d2f2ee34be109"
|
||||
))],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -719,8 +721,12 @@ mod test {
|
|||
other::IS_KEY_IMAGE_SPENT_REQUEST,
|
||||
Some(IsKeyImageSpentRequest {
|
||||
key_images: vec![
|
||||
"8d1bd8181bf7d857bdb281e0153d84cd55a3fcaa57c3e570f4a49f935850b5e3".into(),
|
||||
"7319134bfc50668251f5b899c66b005805ee255c136f0e1cecbb0f3a912e09d4".into(),
|
||||
Hex(hex!(
|
||||
"8d1bd8181bf7d857bdb281e0153d84cd55a3fcaa57c3e570f4a49f935850b5e3"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"7319134bfc50668251f5b899c66b005805ee255c136f0e1cecbb0f3a912e09d4"
|
||||
)),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
@ -1255,24 +1261,60 @@ mod test {
|
|||
Some(GetTransactionPoolHashesResponse {
|
||||
base: ResponseBase::OK,
|
||||
tx_hashes: vec![
|
||||
"aa928aed888acd6152c60194d50a4df29b0b851be6169acf11b6a8e304dd6c03".into(),
|
||||
"794345f321a98f3135151f3056c0fdf8188646a8dab27de971428acf3551dd11".into(),
|
||||
"1e9d2ae11f2168a228942077483e70940d34e8658c972bbc3e7f7693b90edf17".into(),
|
||||
"7375c928f261d00f07197775eb0bfa756e5f23319819152faa0b3c670fe54c1b".into(),
|
||||
"2e4d5f8c5a45498f37fb8b6ca4ebc1efa0c371c38c901c77e66b08c072287329".into(),
|
||||
"eee6d596cf855adfb10e1597d2018e3a61897ac467ef1d4a5406b8d20bfbd52f".into(),
|
||||
"59c574d7ba9bb4558470f74503c7518946a85ea22c60fccfbdec108ce7d8f236".into(),
|
||||
"0d57bec1e1075a9e1ac45cf3b3ced1ad95ccdf2a50ce360190111282a0178655".into(),
|
||||
"60d627b2369714a40009c07d6185ebe7fa4af324fdfa8d95a37a936eb878d062".into(),
|
||||
"661d7e728a901a8cb4cf851447d9cd5752462687ed0b776b605ba706f06bdc7d".into(),
|
||||
"b80e1f09442b00b3fffe6db5d263be6267c7586620afff8112d5a8775a6fc58e".into(),
|
||||
"974063906d1ddfa914baf85176b0f689d616d23f3d71ed4798458c8b4f9b9d8f".into(),
|
||||
"d2575ae152a180be4981a9d2fc009afcd073adaa5c6d8b022c540a62d6c905bb".into(),
|
||||
"3d78aa80ee50f506683bab9f02855eb10257a08adceda7cbfbdfc26b10f6b1bb".into(),
|
||||
"8b5bc125bdb73b708500f734501d55088c5ac381a0879e1141634eaa72b6a4da".into(),
|
||||
"11c06f4d2f00c912ca07313ed2ea5366f3cae914a762bed258731d3d9e3706df".into(),
|
||||
"b3644dc7c9a3a53465fe80ad3769e516edaaeb7835e16fdd493aac110d472ae1".into(),
|
||||
"ed2478ad793b923dbf652c8612c40799d764e5468897021234a14a37346bc6ee".into(),
|
||||
Hex(hex!(
|
||||
"aa928aed888acd6152c60194d50a4df29b0b851be6169acf11b6a8e304dd6c03"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"794345f321a98f3135151f3056c0fdf8188646a8dab27de971428acf3551dd11"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"1e9d2ae11f2168a228942077483e70940d34e8658c972bbc3e7f7693b90edf17"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"7375c928f261d00f07197775eb0bfa756e5f23319819152faa0b3c670fe54c1b"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"2e4d5f8c5a45498f37fb8b6ca4ebc1efa0c371c38c901c77e66b08c072287329"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"eee6d596cf855adfb10e1597d2018e3a61897ac467ef1d4a5406b8d20bfbd52f"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"59c574d7ba9bb4558470f74503c7518946a85ea22c60fccfbdec108ce7d8f236"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"0d57bec1e1075a9e1ac45cf3b3ced1ad95ccdf2a50ce360190111282a0178655"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"60d627b2369714a40009c07d6185ebe7fa4af324fdfa8d95a37a936eb878d062"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"661d7e728a901a8cb4cf851447d9cd5752462687ed0b776b605ba706f06bdc7d"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"b80e1f09442b00b3fffe6db5d263be6267c7586620afff8112d5a8775a6fc58e"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"974063906d1ddfa914baf85176b0f689d616d23f3d71ed4798458c8b4f9b9d8f"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"d2575ae152a180be4981a9d2fc009afcd073adaa5c6d8b022c540a62d6c905bb"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"3d78aa80ee50f506683bab9f02855eb10257a08adceda7cbfbdfc26b10f6b1bb"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"8b5bc125bdb73b708500f734501d55088c5ac381a0879e1141634eaa72b6a4da"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"11c06f4d2f00c912ca07313ed2ea5366f3cae914a762bed258731d3d9e3706df"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"b3644dc7c9a3a53465fe80ad3769e516edaaeb7835e16fdd493aac110d472ae1"
|
||||
)),
|
||||
Hex(hex!(
|
||||
"ed2478ad793b923dbf652c8612c40799d764e5468897021234a14a37346bc6ee"
|
||||
)),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -19,6 +19,17 @@ use serde::{Deserialize, Deserializer, Serialize};
|
|||
///
|
||||
/// let from_str = serde_json::from_str::<Hex<32>>(expected_json).unwrap();
|
||||
/// assert_eq!(hex_bytes, from_str);
|
||||
///
|
||||
/// //------
|
||||
///
|
||||
/// let vec = vec![hex_bytes; 2];
|
||||
/// let expected_json = r#"["0101010101010101010101010101010101010101010101010101010101010101","0101010101010101010101010101010101010101010101010101010101010101"]"#;
|
||||
///
|
||||
/// let to_string = serde_json::to_string(&vec).unwrap();
|
||||
/// assert_eq!(to_string, expected_json);
|
||||
///
|
||||
/// let from_str = serde_json::from_str::<Vec<Hex<32>>>(expected_json).unwrap();
|
||||
/// assert_eq!(vec, from_str);
|
||||
/// ```
|
||||
///
|
||||
/// # Deserialization
|
||||
|
@ -30,6 +41,19 @@ use serde::{Deserialize, Deserializer, Serialize};
|
|||
#[repr(transparent)]
|
||||
pub struct Hex<const N: usize>(#[serde(with = "hex::serde")] pub [u8; N]);
|
||||
|
||||
impl<const N: usize> Hex<N> {
|
||||
/// Returns `true` if the inner array is zeroed.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use cuprate_hex::Hex;
|
||||
/// assert!(Hex([0; 32]).is_zeroed());
|
||||
/// assert!(!Hex([1; 32]).is_zeroed());
|
||||
/// ```
|
||||
pub fn is_zeroed(&self) -> bool {
|
||||
*self == Self([0; N])
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, const N: usize> Deserialize<'de> for Hex<N>
|
||||
where
|
||||
[u8; N]: FromHex,
|
||||
|
|
Loading…
Reference in a new issue