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