Compare commits

..

No commits in common. "d86156f429bf5df57f05459805a868350ab591a3" and "ea80e666b25d81df1f1edb8fd871a27d7ffc43ac" have entirely different histories.

7 changed files with 38 additions and 59 deletions

View file

@ -16,7 +16,7 @@ epee = ["dep:cuprate-epee-encoding"]
[dependencies]
cuprate-epee-encoding = { path = "../../net/epee-encoding", optional = true }
cuprate-fixed-bytes = { path = "../../net/fixed-bytes" }
cuprate-types = { path = "../../types", default-features = false, features = ["epee", "serde"] }
cuprate-types = { path = "../../types" }
paste = { workspace = true }
serde = { workspace = true, optional = true }

View file

@ -635,9 +635,7 @@ define_request_and_response! {
AccessResponseBase {
blob: String,
block_header: BlockHeader,
/// `cuprate_rpc_types::json::block::Block` should be used
/// to create this JSON string in a type-safe manner.
json: String,
json: String, // FIXME: this should be defined in a struct, it has many fields.
miner_tx_hash: String,
tx_hashes: Vec<String> = default_vec::<String>(), "default_vec",
}

View file

@ -71,24 +71,32 @@ use cuprate_epee_encoding::{
pub enum TxEntry {
/// This entry exists in the transaction pool.
InPool {
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[cfg_attr(feature = "serde", serde(flatten))]
prefix: TxEntryPrefix,
as_hex: String,
as_json: String,
block_height: u64,
block_timestamp: u64,
confirmations: u64,
double_spend_seen: bool,
output_indices: Vec<u64>,
prunable_as_hex: String,
prunable_hash: String,
pruned_as_hex: String,
tx_hash: String,
#[cfg_attr(feature = "serde", serde(serialize_with = "serde_true"))]
/// Will always be serialized as `true`.
in_pool: bool,
},
/// This entry _does not_ exist in the transaction pool.
NotInPool {
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[cfg_attr(feature = "serde", serde(flatten))]
prefix: TxEntryPrefix,
as_hex: String,
as_json: String,
double_spend_seen: bool,
prunable_as_hex: String,
prunable_hash: String,
pruned_as_hex: String,
received_timestamp: u64,
relayed: bool,
tx_hash: String,
#[cfg_attr(feature = "serde", serde(serialize_with = "serde_false"))]
/// Will always be serialized as `false`.
in_pool: bool,
@ -98,29 +106,20 @@ pub enum TxEntry {
impl Default for TxEntry {
fn default() -> Self {
Self::NotInPool {
prefix: Default::default(),
as_hex: String::default(),
as_json: String::default(),
double_spend_seen: bool::default(),
prunable_as_hex: String::default(),
prunable_hash: String::default(),
pruned_as_hex: String::default(),
received_timestamp: u64::default(),
relayed: bool::default(),
tx_hash: String::default(),
in_pool: false,
}
}
}
/// Common fields in all [`TxEntry`] variants.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TxEntryPrefix {
as_hex: String,
/// `cuprate_rpc_types::json::tx::Transaction` should be used
/// to create this JSON string in a type-safe manner.
as_json: String,
double_spend_seen: bool,
tx_hash: String,
prunable_as_hex: String,
prunable_hash: String,
pruned_as_hex: String,
}
//---------------------------------------------------------------------------------------------------- Epee
#[cfg(feature = "epee")]
impl EpeeObjectBuilder<TxEntry> for () {

View file

@ -140,8 +140,6 @@ define_request_and_response! {
#[doc = serde_doc_test!(GET_TRANSACTIONS_RESPONSE)]
AccessResponseBase {
txs_as_hex: Vec<String> = default_vec::<String>(), "default_vec",
/// `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",

View file

@ -21,19 +21,28 @@ pub struct Block {
pub tx_hashes: Vec<String>,
}
/// [`Block::miner_tx`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MinerTransactionPrefix {
pub version: u8,
pub unlock_time: u64,
pub vin: Vec<Input>,
pub vout: Vec<Output>,
pub extra: Vec<u8>,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[serde(untagged)]
pub enum MinerTransaction {
V1 {
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
/// This field is flattened.
#[serde(flatten)]
prefix: MinerTransactionPrefix,
signatures: [(); 0],
},
V2 {
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
/// This field is flattened.
#[serde(flatten)]
prefix: MinerTransactionPrefix,
rct_signatures: MinerTransactionRctSignatures,
@ -49,32 +58,18 @@ impl Default for MinerTransaction {
}
}
/// [`MinerTransaction::V1::prefix`] & [`MinerTransaction::V2::prefix`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MinerTransactionPrefix {
pub version: u8,
pub unlock_time: u64,
pub vin: Vec<Input>,
pub vout: Vec<Output>,
pub extra: Vec<u8>,
}
/// [`MinerTransaction::V2::rct_signatures`].
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MinerTransactionRctSignatures {
pub r#type: u8,
}
/// [`MinerTransactionPrefix::vin`].
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Input {
pub r#gen: Gen,
}
/// [`Input::gen`].
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Gen {

View file

@ -1,8 +1,7 @@
//! JSON output types.
//!
//! The same [`Output`] is used in both
//! [`crate::json::block::MinerTransactionPrefix::vout`]
//! and [`crate::json::tx::TransactionPrefix::vout`].
//! [`crate::json::block::MinerTransaction::vout`] and [`crate::json::tx::Transaction::vout`].
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -15,7 +14,6 @@ pub struct Output {
pub target: Target,
}
/// [`Output::target`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[serde(untagged)]
@ -32,7 +30,6 @@ impl Default for Target {
}
}
/// [`Target::TaggedKey::tagged_key`].
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TaggedKey {

View file

@ -20,13 +20,13 @@ use crate::json::output::Output;
#[serde(untagged)]
pub enum Transaction {
V1 {
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
/// This field is flattened.
#[serde(flatten)]
prefix: TransactionPrefix,
signatures: Vec<String>,
},
V2 {
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
/// This field is flattened.
#[serde(flatten)]
prefix: TransactionPrefix,
rct_signatures: RctSignatures,
@ -34,7 +34,6 @@ pub enum Transaction {
},
}
/// [`Transaction::V1::prefix`] & [`Transaction::V2::prefix`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TransactionPrefix {
@ -45,7 +44,6 @@ pub struct TransactionPrefix {
pub extra: Vec<u8>,
}
/// [`Transaction::V2::rct_signatures`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RctSignatures {
@ -55,7 +53,6 @@ pub struct RctSignatures {
pub outPk: Vec<String>,
}
/// [`Transaction::V2::rctsig_prunable`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RctSigPrunable {
@ -65,7 +62,6 @@ pub struct RctSigPrunable {
pub pseudoOuts: Vec<String>,
}
/// [`RctSigPrunable::bpp`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Bpp {
@ -79,7 +75,6 @@ pub struct Bpp {
pub R: Vec<String>,
}
/// [`RctSigPrunable::CLSAGs`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Clsag {
@ -88,7 +83,6 @@ pub struct Clsag {
pub D: String,
}
/// [`RctSignatures::ecdhInfo`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EcdhInfo {
@ -97,14 +91,12 @@ pub struct EcdhInfo {
pub mask: Option<String>,
}
/// [`TransactionPrefix::vin`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Input {
pub key: Key,
}
/// [`Input::key`].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Key {