diff --git a/types/Cargo.toml b/types/Cargo.toml index 6f4ed4b..0591a1d 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -20,7 +20,6 @@ json = [] cuprate-epee-encoding = { path = "../net/epee-encoding", optional = true } cuprate-fixed-bytes = { path = "../net/fixed-bytes" } -# cfg-if = { workspace = true } bytes = { workspace = true } curve25519-dalek = { workspace = true } monero-serai = { workspace = true } diff --git a/types/src/json/block.rs b/types/src/json/block.rs index ec8ba5d..322a342 100644 --- a/types/src/json/block.rs +++ b/types/src/json/block.rs @@ -12,8 +12,8 @@ use crate::json::output::Output; #[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Block { - pub major_version: u64, - pub minor_version: u64, + pub major_version: u8, + pub minor_version: u8, pub timestamp: u64, pub prev_id: String, pub nonce: u32, @@ -21,25 +21,41 @@ pub struct Block { pub tx_hashes: Vec, } -#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct MinerTransaction { +pub struct MinerTransactionPrefix { pub version: u8, pub unlock_time: u64, pub vin: Vec, pub vout: Vec, pub extra: Vec, +} - /// Should be [`None`] if [`Self::rct_signatures`] is [`Some`] - /// - /// This field always (de)serializes to/from an empty array - /// as coinbase transactions do not have signatures. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub signatures: Option<[(); 0]>, +#[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. + #[serde(flatten)] + prefix: MinerTransactionPrefix, + signatures: [(); 0], + }, + V2 { + /// This field is flattened. + #[serde(flatten)] + prefix: MinerTransactionPrefix, + rct_signatures: MinerTransactionRctSignature, + }, +} - /// Should be [`None`] if [`Self::signatures`] is [`Some`] - #[serde(default, skip_serializing_if = "Option::is_none")] - pub rct_signatures: Option, +impl Default for MinerTransaction { + fn default() -> Self { + Self::V1 { + prefix: Default::default(), + signatures: Default::default(), + } + } } #[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/types/src/json/tx.rs b/types/src/json/tx.rs index 6c93543..fdbf35e 100644 --- a/types/src/json/tx.rs +++ b/types/src/json/tx.rs @@ -1,6 +1,9 @@ //! JSON transaction types. -#![expect(non_snake_case, reason = "TODO")] +#![expect( + non_snake_case, + reason = "JSON serialization requires non snake-case casing" +)] #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -14,24 +17,31 @@ use crate::json::output::Output; /// - [`/get_transaction_pool` -> `tx_json`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_transaction_pool) #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct Transaction { +#[serde(untagged)] +pub enum Transaction { + V1 { + /// This field is flattened. + #[serde(flatten)] + prefix: TransactionPrefix, + signatures: Vec, + }, + V2 { + /// This field is flattened. + #[serde(flatten)] + prefix: TransactionPrefix, + rct_signatures: RctSignatures, + rctsig_prunable: RctSigPrunable, + }, +} + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct TransactionPrefix { pub version: u8, pub unlock_time: u64, pub vin: Vec, pub vout: Vec, pub extra: Vec, - - /// Should be [`None`] if [`Self::rct_signatures`] is [`Some`] - #[serde(default, skip_serializing_if = "Option::is_none")] - pub signatures: Option>, - - /// Should be [`None`] if [`Self::signatures`] is [`Some`] - #[serde(default, skip_serializing_if = "Option::is_none")] - pub rct_signatures: Option, - - /// Should be [`None`] if [`Self::signatures`] is [`Some`] - #[serde(default, skip_serializing_if = "Option::is_none")] - pub rctsig_prunable: Option, } #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]