Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Sep 26, 2024
1 parent 243d367 commit 1b29b7d
Show file tree
Hide file tree
Showing 8 changed files with 549 additions and 243 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ json = []
cuprate-epee-encoding = { path = "../net/epee-encoding", optional = true }
cuprate-fixed-bytes = { path = "../net/fixed-bytes" }

cfg-if = { workspace = true }
# cfg-if = { workspace = true }
bytes = { workspace = true }
curve25519-dalek = { workspace = true }
monero-serai = { workspace = true }
Expand Down
75 changes: 16 additions & 59 deletions types/src/json/block.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cfg_if::cfg_if! {
if #[cfg(feature = "serde")] {
use serde::{Serialize, Deserialize};
// use monero_serai::{block::Block, transaction::Transaction};
}
}
//! JSON block types.

/// TODO
///
/// `/get_block`
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crate::json::output::Output;

/// JSON representation of a block.
///
/// Used in:
/// - [`/get_block` -> `json`](https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_block)
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Block {
Expand All @@ -21,88 +21,45 @@ pub struct Block {
pub tx_hashes: Vec<String>,
}

/// TODO
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MinerTransaction {
pub version: u64,
pub version: u8,
pub unlock_time: u64,
pub vin: Vec<Input>,
pub vout: Vec<Output>,
pub extra: Vec<u8>,

/// Should be [`None`] if [`Self::rct_signatures`] is [`Some`]
#[serde(skip_serializing_if = "Option::is_none")]
pub signatures: Option<MinerTransactionSignature>,
///
/// 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]>,

/// Should be [`None`] if [`Self::signatures`] is [`Some`]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rct_signatures: Option<MinerTransactionRctSignature>,
}

/// TODO
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[serde(transparent)]
#[repr(transparent)]
pub struct MinerTransactionSignature(Vec<()>);

impl MinerTransactionSignature {
pub const fn new() -> Self {
Self(Vec::new())
}
}

/// TODO
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MinerTransactionRctSignature {
pub r#type: u8,
}

/// TODO
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Input {
pub r#gen: Gen,
}

/// TODO
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Gen {
pub height: u64,
}

/// TODO
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Output {
pub amount: u64,
pub target: Target,
}

/// TODO
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Target {
/// Should be [`None`] if [`Self::tagged_key`] is [`Some`]
#[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<String>,

/// Should be [`None`] if [`Self::key`] is [`Some`]
#[serde(skip_serializing_if = "Option::is_none")]
pub tagged_key: Option<TaggedKey>,
}

/// TODO
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TaggedKey {
pub key: String,
pub view_tag: String,
}

#[cfg(test)]
mod test {
use pretty_assertions::assert_eq;
Expand Down
19 changes: 14 additions & 5 deletions types/src/json/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pub mod block;
mod tx;
pub mod tx_in_pool;
//! This module contains types mappings for other common types
//! to allow for easier JSON (de)serialization.
//!
//! The main types are:
//! - [`block::Block`]
//! - [`tx::Transaction`]
//!
//! Modules exist within this module as the JSON representation
//! of types sometimes differs, thus, the modules hold the types
//! that match the specific schema, for example [`block::Input`]
//! is different than [`tx::Input`].

pub use block::Block;
pub use tx::Transaction;
pub mod block;
pub mod output;
pub mod tx;
34 changes: 34 additions & 0 deletions types/src/json/output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! JSON output types.
//!
//! The same [`Output`] is used in both
//! [`crate::json::block::MinerTransaction::vout`] and [`crate::json::tx::Transaction::vout`].

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// JSON representation of an output.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Output {
pub amount: u64,
pub target: Target,
}

#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Target {
/// Should be [`None`] if [`Self::tagged_key`] is [`Some`]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub key: Option<String>,

/// Should be [`None`] if [`Self::key`] is [`Some`]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tagged_key: Option<TaggedKey>,
}

#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TaggedKey {
pub key: String,
pub view_tag: String,
}
32 changes: 0 additions & 32 deletions types/src/json/signature.rs

This file was deleted.

Loading

0 comments on commit 1b29b7d

Please sign in to comment.