Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new multisig #200

Open
wants to merge 4 commits into
base: 4.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ class CMainParams : public CChainParams {

// Founder reward
vector<FounderRewardStructure> rewardStructures = {
{INT_MAX, 5} // 5% founder/dev fee forever
{"rPC7kPCNPAVnUvQs4fWEvnFwJ4yfKvArXM",1121001,1641000, 5}, // 5% legacy founder/dev fee until block 1641000
{"rKkJVJKgSPfS7oYmLZWoAHLyRzmFMuxiSU",1641000,INT_MAX, 5} // 5% founder/dev fee forever
};
consensus.nFounderPayment = FounderPayment(rewardStructures, 1121000); // Block 1121000
consensus.nFounderPayment = FounderPayment(rewardStructures);

fDefaultConsistencyChecks = false;
fRequireStandard = true;
Expand Down Expand Up @@ -340,9 +341,12 @@ class CTestNetParams : public CChainParams {

// Founder reward
vector<FounderRewardStructure> rewardStructures = {
{INT_MAX, 5} // 5% founder/dev fee forever
{"n1BurnXXXXXXXXXXXXXXXXXXXXXXU1qejP",11,30, 5}, // 5% legacy founder/dev fee until block 50
{"2MvpouPdDEujBZg5eZnLNv5bCn78EE2bi65",30,100, 5}, // 5% legacy founder/dev fee until block 50
{"2MzJPqGahWsi42LAw2fxz5gjssMhMinTpWG",100,INT_MAX, 5} // 5% founder/dev fee forever
};
consensus.nFounderPayment = FounderPayment(rewardStructures, 10, "2MvpouPdDEujBZg5eZnLNv5bCn78EE2bi65"); // Block 10 (testnet P2SH)

consensus.nFounderPayment = FounderPayment(rewardStructures);

fDefaultConsistencyChecks = false;
fRequireStandard = false;
Expand Down Expand Up @@ -524,9 +528,10 @@ class CRegTestParams : public CChainParams {

// Founder reward
vector<FounderRewardStructure> rewardStructures = {
{INT_MAX, 5} // 5% founder/dev fee forever
{"2MzJPqGahWsi42LAw2fxz5gjssMhMinTpWG",1,INT_MAX, 5} // 5% founder/dev fee forever
};
consensus.nFounderPayment = FounderPayment(rewardStructures, 1, "2MwTWhsKXQTpMPEGsWZCdYy7UZRECPPapM1"); // Block 1 (burn coins)

consensus.nFounderPayment = FounderPayment(rewardStructures);

vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
Expand Down
4 changes: 1 addition & 3 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, int nHeig

FounderPayment founderPayment = Params().GetConsensus().nFounderPayment;
CAmount founderReward = founderPayment.getFounderPaymentAmount(nHeight, blockReward);
int founderStartHeight = founderPayment.getStartBlock();

if(nHeight > founderStartHeight && founderReward && !founderPayment.IsBlockPayeeValid(tx, nHeight, blockReward)) {
if(founderPayment.IsFounderPaymentsStarted(nHeight) && founderReward && !founderPayment.IsBlockPayeeValid(tx, nHeight, blockReward)) {
return state.DoS(100, false, REJECT_INVALID, "bad-cb-founder-payment-not-found");
}
}
Expand Down
37 changes: 33 additions & 4 deletions src/founder_payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,52 @@

CAmount FounderPayment::getFounderPaymentAmount(int blockHeight, CAmount blockReward)
{
if (blockHeight <= startBlock) {
return 0;
}

for (int i = 0; i < rewardStructures.size(); i++) {
FounderRewardStructure rewardStructure = rewardStructures[i];
if (rewardStructure.blockHeight == INT_MAX || blockHeight <= rewardStructure.blockHeight) {
if(blockHeight < rewardStructure.startBlock)
return 0;
if (rewardStructure.blockHeight == INT_MAX || blockHeight < rewardStructure.blockHeight) {
return blockReward * rewardStructure.rewardPercentage / 100;
}
}
return 0;
}

string FounderPayment::getFounderPaymentAddress(int blockHeight)
{

for (int i = 0; i < rewardStructures.size(); i++) {
FounderRewardStructure rewardStructure = rewardStructures[i];
if(blockHeight < rewardStructure.startBlock)
return rewardStructure.founderAddress;
if (rewardStructure.blockHeight == INT_MAX || blockHeight < rewardStructure.blockHeight) {
return rewardStructure.founderAddress;
}
}
return DEFAULT_FOUNDER_ADDRESS;
}

bool FounderPayment::IsFounderPaymentsStarted(int blockHeight)
{
for (int i = 0; i < rewardStructures.size(); i++) {
FounderRewardStructure rewardStructure = rewardStructures[i];
if(blockHeight < rewardStructure.startBlock)
return false;
if (rewardStructure.blockHeight == INT_MAX || blockHeight < rewardStructure.blockHeight) {
return true;
}
}
return false;
}

void FounderPayment::FillFounderPayment(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, CTxOut& txoutFounderRet)
{
// Make sure it's not filled yet
CAmount founderPayment = getFounderPaymentAmount(nBlockHeight, blockReward);
txoutFounderRet = CTxOut();
CScript payee;
string founderAddress = getFounderPaymentAddress(nBlockHeight);

// Fill payee with the founder address
CAvianAddress cbAddress(founderAddress);
Expand All @@ -41,6 +68,8 @@ bool FounderPayment::IsBlockPayeeValid(const CTransaction& txNew, const int heig
{
CScript payee;
// Fill payee with the founder address
string founderAddress = getFounderPaymentAddress(height);

payee = GetScriptForDestination(CAvianAddress(founderAddress).Get());
const CAmount founderReward = getFounderPaymentAmount(height, blockReward);
BOOST_FOREACH (const CTxOut& out, txNew.vout) {
Expand Down
11 changes: 5 additions & 6 deletions src/founder_payment.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ using namespace std;
static const string DEFAULT_FOUNDER_ADDRESS = "rPC7kPCNPAVnUvQs4fWEvnFwJ4yfKvArXM";

struct FounderRewardStructure {
string founderAddress;
int startBlock;
int blockHeight;
int rewardPercentage;
};

class FounderPayment
{
public:
FounderPayment(vector<FounderRewardStructure> rewardStructures = {}, int startBlock = 0, const string& address = DEFAULT_FOUNDER_ADDRESS)
FounderPayment(vector<FounderRewardStructure> rewardStructures = {})
{
this->founderAddress = address;
this->startBlock = startBlock;
this->rewardStructures = rewardStructures;
}
~FounderPayment(){};
CAmount getFounderPaymentAmount(int blockHeight, CAmount blockReward);
string getFounderPaymentAddress(int blockHeight);
void FillFounderPayment(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, CTxOut& txoutFounderRet);
bool IsBlockPayeeValid(const CTransaction& txNew, const int height, const CAmount blockReward);
int getStartBlock() { return this->startBlock; }
bool IsFounderPaymentsStarted(int blockHeight);

private:
string founderAddress;
int startBlock;
vector<FounderRewardStructure> rewardStructures;
};

Expand Down
5 changes: 4 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc

// Fill founder payment
FounderPayment founderPayment = chainparams.GetConsensus().nFounderPayment;
founderPayment.FillFounderPayment(coinbaseTx, nHeight, blockReward, pblock->txoutFounder);
CAmount nSubsidy = GetBlockSubsidy(nHeight, chainparams.GetConsensus());
if(founderPayment.IsFounderPaymentsStarted(nHeight)) {
founderPayment.FillFounderPayment(coinbaseTx, nHeight, nSubsidy, pblock->txoutFounder);
}

pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
Expand Down
35 changes: 21 additions & 14 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
" \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
" \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n"
" \"height\" : n (numeric) The height of the next block\n"
" \"height\" : n, (numeric) The height of the next block\n"
" \"founder\" : { (array) required founder payee that must be included in the next block\n"
" \"payee\" : \"xxxx\", (string) payee address\n"
" \"script\" : \"xxxx\", (string) payee scriptPubKey\n"
" \"amount\": n (numeric) required amount to pay\n"
" },\n"
" \"founder_payments_started\" : true|false (boolean) true, if founder payments started\n"
"}\n"

"\nExamples:\n"
Expand Down Expand Up @@ -697,19 +704,6 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
UniValue result(UniValue::VOBJ);
result.push_back(Pair("capabilities", aCaps));

UniValue founderObj(UniValue::VOBJ);
FounderPayment founderPayment = Params().GetConsensus().nFounderPayment;
if(pblock->txoutFounder!= CTxOut()) {
CTxDestination address;
ExtractDestination(pblock->txoutFounder.scriptPubKey, address);
CAvianAddress address2(address);
founderObj.push_back(Pair("payee", address2.ToString().c_str()));
founderObj.push_back(Pair("script", HexStr(pblock->txoutFounder.scriptPubKey.begin(), pblock->txoutFounder.scriptPubKey.end())));
founderObj.push_back(Pair("amount", pblock->txoutFounder.nValue));
}
result.push_back(Pair("founder", founderObj));
result.push_back(Pair("founder_payments_started", pindexPrev->nHeight + 1 > founderPayment.getStartBlock()));

UniValue aRules(UniValue::VARR);
UniValue vbavailable(UniValue::VOBJ);
for (int j = 0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
Expand Down Expand Up @@ -768,7 +762,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("transactions", transactions));
result.push_back(Pair("coinbaseaux", aux));
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue));
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->GetValueOut()));
result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
result.push_back(Pair("target", hashTarget.GetHex()));
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
Expand All @@ -790,6 +784,19 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
result.push_back(Pair("curtime", pblock->GetBlockTime()));
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));

UniValue founderObj(UniValue::VOBJ);
FounderPayment founderPayment = Params().GetConsensus().nFounderPayment;
if(pblock->txoutFounder!= CTxOut()) {
CTxDestination address;
ExtractDestination(pblock->txoutFounder.scriptPubKey, address);
CAvianAddress address2(address);
founderObj.push_back(Pair("payee", address2.ToString().c_str()));
founderObj.push_back(Pair("script", HexStr(pblock->txoutFounder.scriptPubKey.begin(), pblock->txoutFounder.scriptPubKey.end())));
founderObj.push_back(Pair("amount", pblock->txoutFounder.nValue));
}
result.push_back(Pair("founder", founderObj));
result.push_back(Pair("founder_payments_started", founderPayment.IsFounderPaymentsStarted(pindexPrev->nHeight + 1)));

if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) {
result.push_back(Pair("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())));
Expand Down
4 changes: 1 addition & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2812,9 +2812,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd

FounderPayment founderPayment = Params().GetConsensus().nFounderPayment;
CAmount founderReward = founderPayment.getFounderPaymentAmount(pindex->nHeight, blockReward);
int founderStartHeight = founderPayment.getStartBlock();

if (pindex->nHeight > founderStartHeight && founderReward && !founderPayment.IsBlockPayeeValid(*block.vtx[0], pindex->nHeight, blockReward))
if (founderPayment.IsFounderPaymentsStarted(pindex->nHeight) && founderReward && !founderPayment.IsBlockPayeeValid(*block.vtx[0], pindex->nHeight, blockReward))
return state.DoS(0, error("ConnectBlock(): couldn't find founders fee payments"),
REJECT_INVALID, "bad-cb-payee");

Expand Down