Bitcoin ABC  0.26.3
P2P Digital Currency
minerfund.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <minerfund.h>
6 
7 #include <blockindex.h>
8 #include <chainparams.h>
9 #include <consensus/activation.h>
10 #include <consensus/amount.h>
11 #include <currencyunit.h>
12 #include <key_io.h> // For DecodeDestination
13 #include <primitives/transaction.h>
14 #include <util/system.h>
15 
19 static constexpr int LEGACY_MINER_FUND_RATIO = 8;
20 static constexpr int MINER_FUND_RATIO = 32;
21 
23  const Amount &coinbaseValue,
24  const CBlockIndex *pprev) {
25  const int minerFundRatio = IsCowperthwaiteEnabled(params, pprev)
28  return minerFundRatio * coinbaseValue / 100;
29 }
30 
31 static CTxDestination BuildDestination(const std::string &dest) {
32  const auto mainNetParams = CreateChainParams(CBaseChainParams::MAIN);
33  return DecodeDestination(dest, *mainNetParams);
34 }
35 
37  static const std::string ecashMinerFund =
38  "ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07";
39  static const std::string bitcoinCashMinerFund =
40  "bitcoincash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvq5zsvycff";
41  static CTxDestination dest = BuildDestination(
42  gArgs.GetBoolArg("-ecash", DEFAULT_ECASH) ? ecashMinerFund
43  : bitcoinCashMinerFund);
44 
45  return dest;
46 }
47 
48 std::unordered_set<CTxDestination, TxDestinationHasher>
50  if (!gArgs.GetBoolArg("-enableminerfund", params.enableMinerFund)) {
51  return {};
52  }
53 
54  return {GetMinerFundDestination()};
55 }
56 
57 bool CheckMinerFund(const Consensus::Params &params,
58  const std::vector<CTxOut> &coinbaseTxOut,
59  const Amount &blockReward, const CBlockIndex *pprev) {
60  const auto whitelist = GetMinerFundWhitelist(params);
61  if (whitelist.empty()) {
62  return true;
63  }
64 
65  const Amount required = GetMinerFundAmount(params, blockReward, pprev);
66  for (auto &o : coinbaseTxOut) {
67  if (o.nValue < required) {
68  // This output doesn't qualify because its amount is too low.
69  continue;
70  }
71 
72  CTxDestination address;
73  if (!ExtractDestination(o.scriptPubKey, address)) {
74  // Cannot decode address.
75  continue;
76  }
77 
78  if (std::find(whitelist.begin(), whitelist.end(), address) !=
79  whitelist.end()) {
80  return true;
81  }
82  }
83 
84  // We did not find an output that match the miner fund requirements.
85  return false;
86 }
bool IsCowperthwaiteEnabled(const Consensus::Params &params, int32_t nHeight)
Check if Nov 15th, 2023 protocol upgrade has activated.
Definition: activation.cpp:104
std::unique_ptr< CChainParams > CreateChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:664
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:27
constexpr bool DEFAULT_ECASH
Definition: currencyunit.h:10
CTxDestination DecodeDestination(const std::string &addr, const CChainParams &params)
Definition: key_io.cpp:174
static CTxDestination BuildDestination(const std::string &dest)
Definition: minerfund.cpp:31
static constexpr int MINER_FUND_RATIO
Definition: minerfund.cpp:20
static const CTxDestination & GetMinerFundDestination()
Definition: minerfund.cpp:36
static constexpr int LEGACY_MINER_FUND_RATIO
Percentage of the block reward to be sent to the fund.
Definition: minerfund.cpp:19
bool CheckMinerFund(const Consensus::Params &params, const std::vector< CTxOut > &coinbaseTxOut, const Amount &blockReward, const CBlockIndex *pprev)
Returns false if there is an invalid miner fund.
Definition: minerfund.cpp:57
Amount GetMinerFundAmount(const Consensus::Params &params, const Amount &coinbaseValue, const CBlockIndex *pprev)
Definition: minerfund.cpp:22
std::unordered_set< CTxDestination, TxDestinationHasher > GetMinerFundWhitelist(const Consensus::Params &params)
Definition: minerfund.cpp:49
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:161
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:92
Definition: amount.h:19
Parameters that influence chain consensus.
Definition: params.h:34
bool enableMinerFund
Enable or disable the miner fund by default.
Definition: params.h:68
ArgsManager gArgs
Definition: system.cpp:79