Skip to main content

zebra_rpc/methods/types/
subsidy.rs

1//! Types for the `getblocksubsidy` RPC.
2
3use derive_getters::Getters;
4use derive_new::new;
5use zebra_chain::{
6    amount::{Amount, NonNegative},
7    parameters::subsidy::FundingStreamReceiver,
8    transparent,
9};
10
11use super::zec::Zec;
12
13/// A response to a `getblocksubsidy` RPC request
14#[derive(
15    Clone, Debug, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize, Getters, new,
16)]
17pub struct GetBlockSubsidyResponse {
18    /// An array of funding stream descriptions.
19    /// Empty arrays are omitted on the wire and deserialize as empty.
20    #[serde(
21        default,
22        rename = "fundingstreams",
23        skip_serializing_if = "Vec::is_empty"
24    )]
25    pub(crate) funding_streams: Vec<FundingStream>,
26
27    /// An array of lockbox stream descriptions.
28    /// Empty arrays are omitted on the wire and deserialize as empty.
29    #[serde(
30        default,
31        rename = "lockboxstreams",
32        skip_serializing_if = "Vec::is_empty"
33    )]
34    pub(crate) lockbox_streams: Vec<FundingStream>,
35
36    /// The mining reward amount in ZEC.
37    ///
38    /// This does not include the miner fee.
39    #[getter(copy)]
40    pub(crate) miner: Zec<NonNegative>,
41
42    /// The founders' reward amount in ZEC.
43    ///
44    /// Zebra returns an error when asked for founders reward heights,
45    /// because it checkpoints those blocks instead.
46    #[getter(copy)]
47    pub(crate) founders: Zec<NonNegative>,
48
49    /// The total funding stream amount in ZEC.
50    #[serde(rename = "fundingstreamstotal")]
51    #[getter(copy)]
52    pub(crate) funding_streams_total: Zec<NonNegative>,
53
54    /// The total lockbox stream amount in ZEC.
55    #[serde(rename = "lockboxtotal")]
56    #[getter(copy)]
57    pub(crate) lockbox_total: Zec<NonNegative>,
58
59    /// The total block subsidy amount in ZEC.
60    ///
61    /// This does not include the miner fee.
62    #[serde(rename = "totalblocksubsidy")]
63    #[getter(copy)]
64    pub(crate) total_block_subsidy: Zec<NonNegative>,
65}
66
67#[deprecated(note = "Use `GetBlockSubsidyResponse` instead")]
68pub use self::GetBlockSubsidyResponse as BlockSubsidy;
69
70/// A single funding stream's information in a  `getblocksubsidy` RPC request
71#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, Getters, new)]
72pub struct FundingStream {
73    /// A description of the funding stream recipient.
74    pub recipient: String,
75
76    /// A URL for the specification of this funding stream.
77    pub specification: String,
78
79    /// The funding stream amount in ZEC.
80    #[getter(copy)]
81    pub value: Zec<NonNegative>,
82
83    /// The funding stream amount in zatoshis.
84    #[serde(rename = "valueZat")]
85    #[getter(copy)]
86    pub value_zat: Amount<NonNegative>,
87
88    /// The transparent or Sapling address of the funding stream recipient.
89    ///
90    /// The current Zcash funding streams only use transparent addresses,
91    /// so Zebra doesn't support Sapling addresses in this RPC.
92    ///
93    /// This is optional so we can support funding streams with no addresses (lockbox streams).
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub address: Option<transparent::Address>,
96}
97
98impl FundingStream {
99    /// Convert a `receiver`, `value`, and `address` into a `FundingStream` response.
100    pub(crate) fn new_internal(
101        is_post_nu6: bool,
102        receiver: FundingStreamReceiver,
103        value: Amount<NonNegative>,
104        address: Option<&transparent::Address>,
105    ) -> FundingStream {
106        let (name, specification) = receiver.info(is_post_nu6);
107
108        FundingStream {
109            recipient: name.to_string(),
110            specification: specification.to_string(),
111            value: value.into(),
112            value_zat: value,
113            address: address.cloned(),
114        }
115    }
116}