Compare commits

..

6 commits

Author SHA1 Message Date
hinto.janai
d86156f429
docs
Some checks are pending
Audit / audit (push) Waiting to run
Deny / audit (push) Waiting to run
2024-09-26 17:11:02 -04:00
hinto.janai
45b5a241ab
remove epee 2024-09-26 16:55:03 -04:00
hinto.janai
c06d0a47a2
cuprate-rpc-types: common TxEntry fields into prefix struct 2024-09-26 16:52:41 -04:00
hinto.janai
7dbd514a2d
cuprate-rpc-types: add comments 2024-09-26 16:47:42 -04:00
hinto.janai
33c31871e1
todo!() epee impl 2024-09-26 16:42:20 -04:00
hinto.janai
aa94d93f4d
docs 2024-09-26 16:32:03 -04:00
7 changed files with 59 additions and 38 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" }
cuprate-types = { path = "../../types", default-features = false, features = ["epee", "serde"] }
paste = { workspace = true }
serde = { workspace = true, optional = true }

View file

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

View file

@ -71,32 +71,24 @@ use cuprate_epee_encoding::{
pub enum TxEntry {
/// This entry exists in the transaction pool.
InPool {
as_hex: String,
as_json: String,
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[cfg_attr(feature = "serde", serde(flatten))]
prefix: TxEntryPrefix,
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 {
as_hex: String,
as_json: String,
double_spend_seen: bool,
prunable_as_hex: String,
prunable_hash: String,
pruned_as_hex: String,
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[cfg_attr(feature = "serde", serde(flatten))]
prefix: TxEntryPrefix,
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,
@ -106,20 +98,29 @@ pub enum TxEntry {
impl Default for TxEntry {
fn default() -> Self {
Self::NotInPool {
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(),
prefix: Default::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,6 +140,8 @@ 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,28 +21,19 @@ pub struct Block {
pub tx_hashes: Vec<String>,
}
#[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>,
}
/// [`Block::miner_tx`].
#[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.
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[serde(flatten)]
prefix: MinerTransactionPrefix,
signatures: [(); 0],
},
V2 {
/// This field is flattened.
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[serde(flatten)]
prefix: MinerTransactionPrefix,
rct_signatures: MinerTransactionRctSignatures,
@ -58,18 +49,32 @@ 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,7 +1,8 @@
//! JSON output types.
//!
//! The same [`Output`] is used in both
//! [`crate::json::block::MinerTransaction::vout`] and [`crate::json::tx::Transaction::vout`].
//! [`crate::json::block::MinerTransactionPrefix::vout`]
//! and [`crate::json::tx::TransactionPrefix::vout`].
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -14,6 +15,7 @@ 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)]
@ -30,6 +32,7 @@ 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.
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[serde(flatten)]
prefix: TransactionPrefix,
signatures: Vec<String>,
},
V2 {
/// This field is flattened.
/// This field is [flattened](https://serde.rs/field-attrs.html#flatten).
#[serde(flatten)]
prefix: TransactionPrefix,
rct_signatures: RctSignatures,
@ -34,6 +34,7 @@ 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 {
@ -44,6 +45,7 @@ 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 {
@ -53,6 +55,7 @@ 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 {
@ -62,6 +65,7 @@ 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 {
@ -75,6 +79,7 @@ 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 {
@ -83,6 +88,7 @@ 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 {
@ -91,12 +97,14 @@ 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 {