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