Skip to content

Commit

Permalink
Renames FundingStreamRecipient and FundingStreamReceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Jul 25, 2024
1 parent 7d7f606 commit b03e6a2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 63 deletions.
50 changes: 25 additions & 25 deletions zebra-chain/src/parameters/network/subsidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub const FIRST_HALVING_TESTNET: Height = Height(1_116_000);

/// The funding stream receiver categories.
#[derive(Deserialize, Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum FundingStreamReceiver {
pub enum FundingStreamRecipient {
/// The Electric Coin Company (Bootstrap Foundation) funding stream.
#[serde(rename = "ECC")]
Ecc,
Expand All @@ -64,16 +64,16 @@ pub enum FundingStreamReceiver {
MajorGrants,
}

impl FundingStreamReceiver {
impl FundingStreamRecipient {
/// The name for each funding stream receiver, as described in [ZIP-1014] and [`zcashd`].
///
/// [ZIP-1014]: https://zips.z.cash/zip-1014#abstract
/// [`zcashd`]: https://github.com/zcash/zcash/blob/3f09cfa00a3c90336580a127e0096d99e25a38d6/src/consensus/funding.cpp#L13-L32
pub fn name(self) -> &'static str {
match self {
FundingStreamReceiver::Ecc => "Electric Coin Company",
FundingStreamReceiver::ZcashFoundation => "Zcash Foundation",
FundingStreamReceiver::MajorGrants => "Major Grants",
Self::Ecc => "Electric Coin Company",
Self::ZcashFoundation => "Zcash Foundation",
Self::MajorGrants => "Major Grants",
}
}
}
Expand All @@ -96,15 +96,15 @@ pub struct FundingStreams {
///
/// [7.10.1]: https://zips.z.cash/protocol/protocol.pdf#zip214fundingstreams
height_range: std::ops::Range<Height>,
/// Funding stream recipients by [`FundingStreamReceiver`].
recipients: HashMap<FundingStreamReceiver, FundingStreamRecipient>,
/// Funding stream recipients by [`FundingStreamRecipient`].
recipients: HashMap<FundingStreamRecipient, FundingStreamParams>,
}

impl FundingStreams {
/// Creates a new [`FundingStreams`].
pub fn new(
height_range: std::ops::Range<Height>,
recipients: HashMap<FundingStreamReceiver, FundingStreamRecipient>,
recipients: HashMap<FundingStreamRecipient, FundingStreamParams>,
) -> Self {
Self {
height_range,
Expand All @@ -118,12 +118,12 @@ impl FundingStreams {
}

/// Returns recipients of these [`FundingStreams`].
pub fn recipients(&self) -> &HashMap<FundingStreamReceiver, FundingStreamRecipient> {
pub fn recipients(&self) -> &HashMap<FundingStreamRecipient, FundingStreamParams> {
&self.recipients
}

/// Returns a recipient with the provided receiver.
pub fn recipient(&self, receiver: FundingStreamReceiver) -> Option<&FundingStreamRecipient> {
pub fn recipient(&self, receiver: FundingStreamRecipient) -> Option<&FundingStreamParams> {
self.recipients.get(&receiver)
}
}
Expand All @@ -132,7 +132,7 @@ impl FundingStreams {
///
/// [7.10.1]: https://zips.z.cash/protocol/protocol.pdf#zip214fundingstreams
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct FundingStreamRecipient {
pub struct FundingStreamParams {
/// The numerator for each funding stream receiver category
/// as described in [protocol specification §7.10.1][7.10.1].
///
Expand All @@ -142,8 +142,8 @@ pub struct FundingStreamRecipient {
addresses: Vec<transparent::Address>,
}

impl FundingStreamRecipient {
/// Creates a new [`FundingStreamRecipient`].
impl FundingStreamParams {
/// Creates a new [`FundingStreamParams`].
pub fn new<I, T>(numerator: u64, addresses: I) -> Self
where
T: ToString,
Expand Down Expand Up @@ -180,16 +180,16 @@ lazy_static! {
height_range: Height(1_046_400)..Height(2_726_400),
recipients: [
(
FundingStreamReceiver::Ecc,
FundingStreamRecipient::new(7, FUNDING_STREAM_ECC_ADDRESSES_MAINNET.iter()),
FundingStreamRecipient::Ecc,
FundingStreamParams::new(7, FUNDING_STREAM_ECC_ADDRESSES_MAINNET.iter()),
),
(
FundingStreamReceiver::ZcashFoundation,
FundingStreamRecipient::new(5, FUNDING_STREAM_ZF_ADDRESSES_MAINNET),
FundingStreamRecipient::ZcashFoundation,
FundingStreamParams::new(5, FUNDING_STREAM_ZF_ADDRESSES_MAINNET),
),
(
FundingStreamReceiver::MajorGrants,
FundingStreamRecipient::new(8, FUNDING_STREAM_MG_ADDRESSES_MAINNET),
FundingStreamRecipient::MajorGrants,
FundingStreamParams::new(8, FUNDING_STREAM_MG_ADDRESSES_MAINNET),
),
]
.into_iter()
Expand All @@ -209,16 +209,16 @@ lazy_static! {
height_range: Height(1_028_500)..Height(2_796_000),
recipients: [
(
FundingStreamReceiver::Ecc,
FundingStreamRecipient::new(7, FUNDING_STREAM_ECC_ADDRESSES_TESTNET),
FundingStreamRecipient::Ecc,
FundingStreamParams::new(7, FUNDING_STREAM_ECC_ADDRESSES_TESTNET),
),
(
FundingStreamReceiver::ZcashFoundation,
FundingStreamRecipient::new(5, FUNDING_STREAM_ZF_ADDRESSES_TESTNET),
FundingStreamRecipient::ZcashFoundation,
FundingStreamParams::new(5, FUNDING_STREAM_ZF_ADDRESSES_TESTNET),
),
(
FundingStreamReceiver::MajorGrants,
FundingStreamRecipient::new(8, FUNDING_STREAM_MG_ADDRESSES_TESTNET),
FundingStreamRecipient::MajorGrants,
FundingStreamParams::new(8, FUNDING_STREAM_MG_ADDRESSES_TESTNET),
),
]
.into_iter()
Expand Down
22 changes: 11 additions & 11 deletions zebra-chain/src/parameters/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
use super::{
magic::Magic,
subsidy::{
FundingStreamReceiver, FundingStreamRecipient, FundingStreams, ParameterSubsidy,
FundingStreamParams, FundingStreamRecipient, FundingStreams, ParameterSubsidy,
FIRST_HALVING_TESTNET, POST_NU6_FUNDING_STREAMS_MAINNET, POST_NU6_FUNDING_STREAMS_TESTNET,
PRE_NU6_FUNDING_STREAMS_MAINNET, PRE_NU6_FUNDING_STREAMS_TESTNET,
},
Expand Down Expand Up @@ -62,21 +62,21 @@ impl ParameterSubsidy for TestnetParameterSubsidyImpl {
/// Configurable funding stream recipient for configured Testnets.
#[derive(Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct ConfiguredFundingStreamRecipient {
pub struct ConfiguredFundingStreamParams {
/// Funding stream receiver, see [`FundingStreams::recipients`] for more details.
pub receiver: FundingStreamReceiver,
/// The numerator for each funding stream receiver category, see [`FundingStreamRecipient::numerator`] for more details.
pub receiver: FundingStreamRecipient,
/// The numerator for each funding stream receiver category, see [`FundingStreamParams::numerator`] for more details.
pub numerator: u64,
/// Addresses for the funding stream recipient, see [`FundingStreamRecipient::addresses`] for more details.
/// Addresses for the funding stream recipient, see [`FundingStreamParams::addresses`] for more details.
pub addresses: Vec<String>,
}

impl ConfiguredFundingStreamRecipient {
/// Converts a [`ConfiguredFundingStreamRecipient`] to a [`FundingStreamReceiver`] and [`FundingStreamRecipient`].
pub fn into_recipient(self) -> (FundingStreamReceiver, FundingStreamRecipient) {
impl ConfiguredFundingStreamParams {
/// Converts a [`ConfiguredFundingStreamParams`] to a [`FundingStreamRecipient`] and [`FundingStreamParams`].
pub fn into_recipient(self) -> (FundingStreamRecipient, FundingStreamParams) {
(
self.receiver,
FundingStreamRecipient::new(self.numerator, self.addresses),
FundingStreamParams::new(self.numerator, self.addresses),
)
}
}
Expand All @@ -88,7 +88,7 @@ pub struct ConfiguredFundingStreams {
/// Start and end height for funding streams see [`FundingStreams::height_range`] for more details.
pub height_range: Option<std::ops::Range<Height>>,
/// Funding stream recipients, see [`FundingStreams::recipients`] for more details.
pub recipients: Option<Vec<ConfiguredFundingStreamRecipient>>,
pub recipients: Option<Vec<ConfiguredFundingStreamParams>>,
}

impl ConfiguredFundingStreams {
Expand All @@ -104,7 +104,7 @@ impl ConfiguredFundingStreams {
.map(|recipients| {
recipients
.into_iter()
.map(ConfiguredFundingStreamRecipient::into_recipient)
.map(ConfiguredFundingStreamParams::into_recipient)
.collect()
})
.unwrap_or(default_funding_streams.recipients().clone());
Expand Down
26 changes: 13 additions & 13 deletions zebra-chain/src/parameters/network/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::{
block::Height,
parameters::{
subsidy::{
FundingStreamReceiver, FUNDING_STREAM_ECC_ADDRESSES_MAINNET,
FundingStreamRecipient, FUNDING_STREAM_ECC_ADDRESSES_MAINNET,
FUNDING_STREAM_ECC_ADDRESSES_TESTNET, POST_NU6_FUNDING_STREAMS_TESTNET,
PRE_NU6_FUNDING_STREAMS_TESTNET,
},
testnet::{
self, ConfiguredActivationHeights, ConfiguredFundingStreamRecipient,
self, ConfiguredActivationHeights, ConfiguredFundingStreamParams,
ConfiguredFundingStreams, MAX_NETWORK_NAME_LENGTH, RESERVED_NETWORK_NAMES,
},
Network, NetworkUpgrade, MAINNET_ACTIVATION_HEIGHTS, NETWORK_UPGRADES_IN_ORDER,
Expand Down Expand Up @@ -317,8 +317,8 @@ fn check_configured_funding_stream_constraints() {
recipients: None,
},
ConfiguredFundingStreams {
recipients: Some(vec![ConfiguredFundingStreamRecipient {
receiver: FundingStreamReceiver::Ecc,
recipients: Some(vec![ConfiguredFundingStreamParams {
receiver: FundingStreamRecipient::Ecc,
numerator: 20,
addresses: FUNDING_STREAM_ECC_ADDRESSES_TESTNET
.map(Into::into)
Expand All @@ -327,8 +327,8 @@ fn check_configured_funding_stream_constraints() {
..Default::default()
},
ConfiguredFundingStreams {
recipients: Some(vec![ConfiguredFundingStreamRecipient {
receiver: FundingStreamReceiver::Ecc,
recipients: Some(vec![ConfiguredFundingStreamParams {
receiver: FundingStreamRecipient::Ecc,
numerator: 100,
addresses: FUNDING_STREAM_ECC_ADDRESSES_TESTNET
.map(Into::into)
Expand Down Expand Up @@ -377,7 +377,7 @@ fn check_configured_funding_stream_constraints() {
.map(|recipients| {
recipients
.into_iter()
.map(ConfiguredFundingStreamRecipient::into_recipient)
.map(ConfiguredFundingStreamParams::into_recipient)
.collect()
})
.unwrap_or(default_funding_streams.recipients().clone());
Expand All @@ -395,8 +395,8 @@ fn check_configured_funding_stream_constraints() {
// should panic when there are fewer addresses than the max funding stream address index.
let expected_panic_num_addresses = std::panic::catch_unwind(|| {
testnet::Parameters::build().with_pre_nu6_funding_streams(ConfiguredFundingStreams {
recipients: Some(vec![ConfiguredFundingStreamRecipient {
receiver: FundingStreamReceiver::Ecc,
recipients: Some(vec![ConfiguredFundingStreamParams {
receiver: FundingStreamRecipient::Ecc,
numerator: 10,
addresses: vec![],
}]),
Expand All @@ -407,8 +407,8 @@ fn check_configured_funding_stream_constraints() {
// should panic when sum of numerators is greater than funding stream denominator.
let expected_panic_numerator = std::panic::catch_unwind(|| {
testnet::Parameters::build().with_pre_nu6_funding_streams(ConfiguredFundingStreams {
recipients: Some(vec![ConfiguredFundingStreamRecipient {
receiver: FundingStreamReceiver::Ecc,
recipients: Some(vec![ConfiguredFundingStreamParams {
receiver: FundingStreamRecipient::Ecc,
numerator: 101,
addresses: FUNDING_STREAM_ECC_ADDRESSES_TESTNET
.map(Into::into)
Expand All @@ -421,8 +421,8 @@ fn check_configured_funding_stream_constraints() {
// should panic when recipient addresses are for Mainnet.
let expected_panic_wrong_addr_network = std::panic::catch_unwind(|| {
testnet::Parameters::build().with_pre_nu6_funding_streams(ConfiguredFundingStreams {
recipients: Some(vec![ConfiguredFundingStreamRecipient {
receiver: FundingStreamReceiver::Ecc,
recipients: Some(vec![ConfiguredFundingStreamParams {
receiver: FundingStreamRecipient::Ecc,
numerator: 10,
addresses: FUNDING_STREAM_ECC_ADDRESSES_MAINNET
.map(Into::into)
Expand Down
6 changes: 3 additions & 3 deletions zebra-consensus/src/block/subsidy/funding_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod tests;
pub fn funding_stream_values(
height: Height,
network: &Network,
) -> Result<HashMap<FundingStreamReceiver, Amount<NonNegative>>, Error> {
) -> Result<HashMap<FundingStreamRecipient, Amount<NonNegative>>, Error> {
let canopy_height = Canopy.activation_height(network).unwrap();
let mut results = HashMap::new();

Expand Down Expand Up @@ -89,7 +89,7 @@ fn funding_stream_address_index(height: Height, network: &Network) -> usize {
pub fn funding_stream_address(
height: Height,
network: &Network,
receiver: FundingStreamReceiver,
receiver: FundingStreamRecipient,
) -> &transparent::Address {
let index = funding_stream_address_index(height, network);
let funding_streams = network.funding_streams(height);
Expand All @@ -105,7 +105,7 @@ pub fn funding_stream_address(

/// Return a human-readable name and a specification URL for the funding stream `receiver`.
pub fn funding_stream_recipient_info(
receiver: FundingStreamReceiver,
receiver: FundingStreamRecipient,
) -> (&'static str, &'static str) {
(receiver.name(), FUNDING_STREAM_SPECIFICATION)
}
Expand Down
8 changes: 4 additions & 4 deletions zebra-consensus/src/block/subsidy/funding_streams/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tests for funding streams.
use color_eyre::Report;
use zebra_chain::parameters::{subsidy::FundingStreamReceiver, NetworkKind};
use zebra_chain::parameters::{subsidy::FundingStreamRecipient, NetworkKind};

use super::*;

Expand All @@ -21,13 +21,13 @@ fn test_funding_stream_values() -> Result<(), Report> {
let canopy_height_plus2 = Canopy.activation_height(network).unwrap() + 2;

let mut hash_map = HashMap::new();
hash_map.insert(FundingStreamReceiver::Ecc, Amount::try_from(21_875_000)?);
hash_map.insert(FundingStreamRecipient::Ecc, Amount::try_from(21_875_000)?);
hash_map.insert(
FundingStreamReceiver::ZcashFoundation,
FundingStreamRecipient::ZcashFoundation,
Amount::try_from(15_625_000)?,
);
hash_map.insert(
FundingStreamReceiver::MajorGrants,
FundingStreamRecipient::MajorGrants,
Amount::try_from(25_000_000)?,
);

Expand Down
4 changes: 2 additions & 2 deletions zebra-rpc/src/methods/get_block_template_rpcs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use jsonrpc_core::ErrorCode;

use zebra_chain::{
block,
parameters::subsidy::FundingStreamReceiver::{self, *},
parameters::subsidy::FundingStreamRecipient::{self, *},
};

/// When long polling, the amount of time we wait between mempool queries.
Expand Down Expand Up @@ -61,5 +61,5 @@ pub const DEFAULT_SOLUTION_RATE_WINDOW_SIZE: i32 = 120;
/// The funding stream order in `zcashd` RPC responses.
///
/// [`zcashd`]: https://github.com/zcash/zcash/blob/3f09cfa00a3c90336580a127e0096d99e25a38d6/src/consensus/funding.cpp#L13-L32
pub const ZCASHD_FUNDING_STREAM_ORDER: &[FundingStreamReceiver] =
pub const ZCASHD_FUNDING_STREAM_ORDER: &[FundingStreamRecipient] =
&[Ecc, ZcashFoundation, MajorGrants];
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use zebra_chain::{
},
chain_sync_status::ChainSyncStatus,
chain_tip::ChainTip,
parameters::{subsidy::FundingStreamReceiver, Network, NetworkUpgrade},
parameters::{subsidy::FundingStreamRecipient, Network, NetworkUpgrade},
serialization::ZcashDeserializeInto,
transaction::{Transaction, UnminedTx, VerifiedUnminedTx},
transparent,
Expand Down Expand Up @@ -372,7 +372,7 @@ pub fn standard_coinbase_outputs(

// Optional TODO: move this into a zebra_consensus function?
let funding_streams: HashMap<
FundingStreamReceiver,
FundingStreamRecipient,
(Amount<NonNegative>, &transparent::Address),
> = funding_streams
.into_iter()
Expand All @@ -398,7 +398,7 @@ pub fn standard_coinbase_outputs(
/// If `like_zcashd` is true, try to match the coinbase transactions generated by `zcashd`
/// in the `getblocktemplate` RPC.
fn combine_coinbase_outputs(
funding_streams: HashMap<FundingStreamReceiver, (Amount<NonNegative>, &transparent::Address)>,
funding_streams: HashMap<FundingStreamRecipient, (Amount<NonNegative>, &transparent::Address)>,
miner_address: &transparent::Address,
miner_reward: Amount<NonNegative>,
like_zcashd: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use zebra_chain::{
amount::{Amount, NonNegative},
parameters::subsidy::FundingStreamReceiver,
parameters::subsidy::FundingStreamRecipient,
transparent,
};
use zebra_consensus::funding_stream_recipient_info;
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct FundingStream {
impl FundingStream {
/// Convert a `receiver`, `value`, and `address` into a `FundingStream` response.
pub fn new(
receiver: FundingStreamReceiver,
receiver: FundingStreamRecipient,
value: Amount<NonNegative>,
address: &transparent::Address,
) -> FundingStream {
Expand Down

0 comments on commit b03e6a2

Please sign in to comment.