1//! Types for the `getblocksubsidy` RPC.
23use derive_getters::Getters;
4use derive_new::new;
5use zebra_chain::{
6 amount::{Amount, NonNegative},
7 parameters::subsidy::FundingStreamReceiver,
8 transparent,
9};
1011use super::zec::Zec;
1213/// 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")]
21pub(crate) funding_streams: Vec<FundingStream>,
2223/// An array of lockbox stream descriptions.
24 /// Always present after NU6.
25#[serde(rename = "lockboxstreams", skip_serializing_if = "Vec::is_empty")]
26pub(crate) lockbox_streams: Vec<FundingStream>,
2728/// The mining reward amount in ZEC.
29 ///
30 /// This does not include the miner fee.
31#[getter(copy)]
32pub(crate) miner: Zec<NonNegative>,
3334/// 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)]
39pub(crate) founders: Zec<NonNegative>,
4041/// The total funding stream amount in ZEC.
42#[serde(rename = "fundingstreamstotal")]
43 #[getter(copy)]
44pub(crate) funding_streams_total: Zec<NonNegative>,
4546/// The total lockbox stream amount in ZEC.
47#[serde(rename = "lockboxtotal")]
48 #[getter(copy)]
49pub(crate) lockbox_total: Zec<NonNegative>,
5051/// The total block subsidy amount in ZEC.
52 ///
53 /// This does not include the miner fee.
54#[serde(rename = "totalblocksubsidy")]
55 #[getter(copy)]
56pub(crate) total_block_subsidy: Zec<NonNegative>,
57}
5859#[deprecated(note = "Use `GetBlockSubsidyResponse` instead")]
60pub use self::GetBlockSubsidyResponse as BlockSubsidy;
6162/// 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.
66pub recipient: String,
6768/// A URL for the specification of this funding stream.
69pub specification: String,
7071/// The funding stream amount in ZEC.
72#[getter(copy)]
73pub value: Zec<NonNegative>,
7475/// The funding stream amount in zatoshis.
76#[serde(rename = "valueZat")]
77 #[getter(copy)]
78pub value_zat: Amount<NonNegative>,
7980/// 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")]
87pub address: Option<transparent::Address>,
88}
8990impl FundingStream {
91/// Convert a `receiver`, `value`, and `address` into a `FundingStream` response.
92pub(crate) fn new_internal(
93 is_post_nu6: bool,
94 receiver: FundingStreamReceiver,
95 value: Amount<NonNegative>,
96 address: Option<&transparent::Address>,
97 ) -> FundingStream {
98let (name, specification) = receiver.info(is_post_nu6);
99100 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}