2022-05-11 15:47:12 -07:00
|
|
|
// Copyright (c) 2020-2022 The Zcash developers
|
2020-06-05 14:46:45 -07:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
|
|
|
|
|
|
|
#include <consensus/funding.h>
|
|
|
|
|
|
|
|
namespace Consensus
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* General information about each funding stream.
|
|
|
|
* Ordered by Consensus::FundingStreamIndex.
|
|
|
|
*/
|
2020-08-20 06:48:01 -07:00
|
|
|
constexpr struct FSInfo FundingStreamInfo[Consensus::MAX_FUNDING_STREAMS] = {
|
2020-06-05 14:46:45 -07:00
|
|
|
{
|
2020-07-02 12:32:23 -07:00
|
|
|
.recipient = "Electric Coin Company",
|
|
|
|
.specification = "https://zips.z.cash/zip-0214",
|
|
|
|
.valueNumerator = 7,
|
|
|
|
.valueDenominator = 100,
|
2020-06-05 14:46:45 -07:00
|
|
|
},
|
|
|
|
{
|
2020-07-02 12:32:23 -07:00
|
|
|
.recipient = "Zcash Foundation",
|
|
|
|
.specification = "https://zips.z.cash/zip-0214",
|
|
|
|
.valueNumerator = 5,
|
|
|
|
.valueDenominator = 100,
|
2020-06-05 14:46:45 -07:00
|
|
|
},
|
|
|
|
{
|
2020-07-02 12:32:23 -07:00
|
|
|
.recipient = "Major Grants",
|
|
|
|
.specification = "https://zips.z.cash/zip-0214",
|
|
|
|
.valueNumerator = 8,
|
|
|
|
.valueDenominator = 100,
|
2020-06-05 14:46:45 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-20 06:48:01 -07:00
|
|
|
static constexpr bool validateFundingStreamInfo(uint32_t idx) {
|
|
|
|
return (idx >= Consensus::MAX_FUNDING_STREAMS || (
|
|
|
|
FundingStreamInfo[idx].valueNumerator < FundingStreamInfo[idx].valueDenominator &&
|
|
|
|
FundingStreamInfo[idx].valueNumerator < (INT64_MAX / MAX_MONEY) &&
|
|
|
|
validateFundingStreamInfo(idx + 1)));
|
|
|
|
}
|
|
|
|
static_assert(
|
|
|
|
validateFundingStreamInfo(Consensus::FIRST_FUNDING_STREAM),
|
|
|
|
"Invalid FundingStreamInfo");
|
|
|
|
|
2020-06-05 14:46:45 -07:00
|
|
|
CAmount FSInfo::Value(CAmount blockSubsidy) const
|
|
|
|
{
|
|
|
|
// Integer division is floor division for nonnegative integers in C++
|
|
|
|
return CAmount((blockSubsidy * valueNumerator) / valueDenominator);
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:15:26 -07:00
|
|
|
std::set<FundingStreamElement> GetActiveFundingStreamElements(
|
2020-06-05 14:46:45 -07:00
|
|
|
int nHeight,
|
|
|
|
CAmount blockSubsidy,
|
|
|
|
const Consensus::Params& params)
|
|
|
|
{
|
2020-07-02 11:15:26 -07:00
|
|
|
std::set<std::pair<FundingStreamAddress, CAmount>> requiredElements;
|
2020-08-20 09:46:57 -07:00
|
|
|
|
2020-08-21 08:47:12 -07:00
|
|
|
// Funding streams are disabled if Canopy is not active.
|
2020-08-20 09:46:57 -07:00
|
|
|
if (params.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
|
|
|
|
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
|
|
|
|
// The following indexed access is safe as Consensus::MAX_FUNDING_STREAMS is used
|
|
|
|
// in the definition of vFundingStreams.
|
|
|
|
auto fs = params.vFundingStreams[idx];
|
|
|
|
// Funding period is [startHeight, endHeight)
|
2020-10-20 16:39:23 -07:00
|
|
|
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
|
2020-08-20 09:46:57 -07:00
|
|
|
requiredElements.insert(std::make_pair(
|
2020-10-20 16:39:23 -07:00
|
|
|
fs.value().RecipientAddress(params, nHeight),
|
2020-08-20 09:46:57 -07:00
|
|
|
FundingStreamInfo[idx].Value(blockSubsidy)));
|
|
|
|
}
|
2020-06-05 14:46:45 -07:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 09:46:57 -07:00
|
|
|
|
2020-07-02 11:15:26 -07:00
|
|
|
return requiredElements;
|
2020-06-05 14:46:45 -07:00
|
|
|
};
|
|
|
|
|
2020-07-09 10:25:27 -07:00
|
|
|
std::vector<FSInfo> GetActiveFundingStreams(
|
|
|
|
int nHeight,
|
|
|
|
const Consensus::Params& params)
|
|
|
|
{
|
|
|
|
std::vector<FSInfo> activeStreams;
|
2020-08-20 09:46:57 -07:00
|
|
|
|
2020-08-21 08:47:12 -07:00
|
|
|
// Funding streams are disabled if Canopy is not active.
|
2020-08-20 09:46:57 -07:00
|
|
|
if (params.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
|
|
|
|
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
|
|
|
|
auto fs = params.vFundingStreams[idx];
|
2020-10-20 16:39:23 -07:00
|
|
|
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
|
2020-08-20 09:46:57 -07:00
|
|
|
activeStreams.push_back(FundingStreamInfo[idx]);
|
|
|
|
}
|
2020-07-09 10:25:27 -07:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 09:46:57 -07:00
|
|
|
|
2020-07-09 10:25:27 -07:00
|
|
|
return activeStreams;
|
|
|
|
};
|
|
|
|
|
2020-06-05 14:46:45 -07:00
|
|
|
} // namespace Consensus
|