Bitcoin ABC 0.30.7
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 <common/args.h>
11#include <consensus/amount.h>
12#include <currencyunit.h>
13#include <key_io.h> // For DecodeDestination
15
19static constexpr int LEGACY_MINER_FUND_RATIO = 8;
20static 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
31static CTxDestination BuildDestination(const std::string &dest) {
32 const ArgsManager unused_argsman{};
33 const auto mainNetParams =
35 return DecodeDestination(dest, *mainNetParams);
36}
37
39 static const std::string ecashMinerFund =
40 "ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07";
41 static const std::string bitcoinCashMinerFund =
42 "bitcoincash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvq5zsvycff";
43 static CTxDestination dest = BuildDestination(
44 gArgs.GetBoolArg("-ecash", DEFAULT_ECASH) ? ecashMinerFund
45 : bitcoinCashMinerFund);
46
47 return dest;
48}
49
50std::unordered_set<CTxDestination, TxDestinationHasher>
52 if (!gArgs.GetBoolArg("-enableminerfund", params.enableMinerFund)) {
53 return {};
54 }
55
56 return {GetMinerFundDestination()};
57}
58
60 const std::vector<CTxOut> &coinbaseTxOut,
61 const Amount &blockReward, const CBlockIndex *pprev) {
62 const auto whitelist = GetMinerFundWhitelist(params);
63 if (whitelist.empty()) {
64 return true;
65 }
66
67 const Amount required = GetMinerFundAmount(params, blockReward, pprev);
68 for (auto &o : coinbaseTxOut) {
69 if (o.nValue < required) {
70 // This output doesn't qualify because its amount is too low.
71 continue;
72 }
73
74 CTxDestination address;
75 if (!ExtractDestination(o.scriptPubKey, address)) {
76 // Cannot decode address.
77 continue;
78 }
79
80 if (std::find(whitelist.begin(), whitelist.end(), address) !=
81 whitelist.end()) {
82 return true;
83 }
84 }
85
86 // We did not find an output that match the miner fund requirements.
87 return false;
88}
bool IsCowperthwaiteEnabled(const Consensus::Params &params, int32_t nHeight)
Check if Nov 15th, 2023 protocol upgrade has activated.
Definition: activation.cpp:104
ArgsManager gArgs
Definition: args.cpp:38
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
Definition: chainparams.cpp:32
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:556
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:25
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:38
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:59
std::unordered_set< CTxDestination, TxDestinationHasher > GetMinerFundWhitelist(const Consensus::Params &params)
Definition: minerfund.cpp:51
Amount GetMinerFundAmount(const Consensus::Params &params, const Amount &coinbaseValue, const CBlockIndex *pprev)
Definition: minerfund.cpp:22
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:158
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
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:70