cuprate_types/json/
output.rs

1//! JSON output types.
2//!
3//! The same [`Output`] is used in both
4//! [`crate::json::block::MinerTransactionPrefix::vout`]
5//! and [`crate::json::tx::TransactionPrefix::vout`].
6
7#[cfg(feature = "serde")]
8use serde::{Deserialize, Serialize};
9
10use crate::hex::HexBytes;
11
12/// JSON representation of an output.
13#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct Output {
16    pub amount: u64,
17    pub target: Target,
18}
19
20/// [`Output::target`].
21#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
22#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
23#[cfg_attr(feature = "serde", serde(untagged))]
24pub enum Target {
25    Key { key: HexBytes<32> },
26    TaggedKey { tagged_key: TaggedKey },
27}
28
29impl Default for Target {
30    fn default() -> Self {
31        Self::Key {
32            key: Default::default(),
33        }
34    }
35}
36
37/// [`Target::TaggedKey::tagged_key`].
38#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
39#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
40pub struct TaggedKey {
41    pub key: HexBytes<32>,
42    pub view_tag: HexBytes<1>,
43}