void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake, bool fZXAPStake) { CBlockIndex* pindexPrev = chainActive.Tip(); if (!pindexPrev) return; bool hasPayment = true; CScript payee; //spork if (!masternodePayments.GetBlockPayee(pindexPrev->nHeight + 1, payee)) { //no masternode detected CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1); if (winningNode) { payee = GetScriptForDestination(winningNode->pubKeyCollateralAddress.GetID()); } else { LogPrint("masternode","CreateNewBlock: Failed to detect masternode to pay\n"); hasPayment = false; } } CAmount blockValue = GetBlockValue(pindexPrev->nHeight); CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight, blockValue, 0, fZXAPStake); if (hasPayment) { if (fProofOfStake) { /**For Proof Of Stake vout[0] must be null * Stake reward can be split into many different outputs, so we must * use vout.size() to align with several different cases. * An additional output is appended as the masternode payment */ unsigned int i = txNew.vout.size(); txNew.vout.resize(i + 1); txNew.vout[i].scriptPubKey = payee; txNew.vout[i].nValue = masternodePayment; //subtract mn payment from the stake reward if (!txNew.vout[1].IsZerocoinMint()) txNew.vout[i - 1].nValue -= masternodePayment; } else { txNew.vout.resize(2); txNew.vout[1].scriptPubKey = payee; txNew.vout[1].nValue = masternodePayment; txNew.vout[0].nValue = blockValue - masternodePayment; } CTxDestination address1; ExtractDestination(payee, address1); CBitcoinAddress address2(address1); LogPrint("masternode","Masternode payment of %s to %s\n", FormatMoney(masternodePayment).c_str(), address2.ToString().c_str()); } else { if (!fProofOfStake) txNew.vout[0].nValue = blockValue; } }
//TODO (Amir): Use CMutableTransaction. void CStormnodePayments::FillBlockPayee(CTransaction& txNew, CAmount nFees) { CBlockIndex* pindexPrev = pindexBest; if(!pindexPrev) return; bool hasPayment = true; CScript payee; //spork if(!stormnodePayments.GetBlockPayee(pindexPrev->nHeight+1, payee)){ //no stormnode detected CStormnode* winningNode = snodeman.GetCurrentStormNode(); if(winningNode){ payee = GetScriptForDestination(winningNode->pubkey.GetID()); } else { LogPrintf("CreateNewBlock: Failed to detect stormnode to pay\n"); hasPayment = false; } } if(hasPayment){ //txNew.vout.resize(2); txNew.vout[1].scriptPubKey = payee; //txNew.vout[1].nValue = stormnodePayment; //txNew.vout[0].nValue -= stormnodePayment; // Stormnode Payments CAmount blockValue = GetBlockValue(pindexPrev->nBits, pindexPrev->nHeight, nFees); CAmount stormnodePayment = GetStormnodePayment(pindexPrev->nHeight+1, blockValue); if(txNew.vout.size() == 4) // 2 stake outputs, stake was split, plus a stormnode payment { txNew.vout[1].nValue = stormnodePayment; blockValue -= stormnodePayment; txNew.vout[2].nValue = (blockValue / 2 / CENT) * CENT; txNew.vout[3].nValue = blockValue - txNew.vout[1].nValue; } else if(txNew.vout.size() == 3) // only 1 stake output, was not split, plus a stormnode payment { txNew.vout[1].nValue = stormnodePayment; blockValue -= stormnodePayment; txNew.vout[2].nValue = blockValue; } CTxDestination address1; ExtractDestination(payee, address1); CDarkSilkAddress address2(address1); LogPrintf("Stormnode payment to %s\n", address2.ToString().c_str()); } }
void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool fProofOfStake) { CBlockIndex* pindexPrev = chainActive.Tip(); if(!pindexPrev) return; bool hasPayment = true; CScript payee; //spork if(!masternodePayments.GetBlockPayee(pindexPrev->nHeight+1, payee)){ //no masternode detected CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1); if(winningNode){ payee = GetScriptForDestination(winningNode->pubKeyCollateralAddress.GetID()); } else { LogPrintf("CreateNewBlock: Failed to detect masternode to pay\n"); hasPayment = false; } } CAmount blockValue = GetBlockValue(pindexPrev->nHeight); CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight, blockValue); if(hasPayment) { if(fProofOfStake) { unsigned int i = txNew.vout.size(); txNew.vout.resize(i + 1); txNew.vout[i].scriptPubKey = payee; txNew.vout[i].nValue = masternodePayment; txNew.vout[i - 1].nValue -= masternodePayment; } else { txNew.vout.resize(2); txNew.vout[1].scriptPubKey = payee; txNew.vout[1].nValue = masternodePayment; txNew.vout[0].nValue = blockValue - masternodePayment; } CTxDestination address1; ExtractDestination(payee, address1); CBitcoinAddress address2(address1); LogPrintf("Masternode payment to %s\n", address2.ToString().c_str()); } }
std::string BlockToString(CBlockIndex* pBlock) { if (!pBlock) return ""; CBlock block; ReadBlockFromDisk(block, pBlock); CAmount Fees = 0; CAmount OutVolume = 0; CAmount Reward = 0; std::string TxLabels[] = {_("Hash"), _("From"), _("Amount"), _("To"), _("Amount")}; std::string TxContent = table + makeHTMLTableRow(TxLabels, sizeof(TxLabels) / sizeof(std::string)); for (unsigned int i = 0; i < block.vtx.size(); i++) { const CTransaction& tx = block.vtx[i]; TxContent += TxToRow(tx); CAmount In = getTxIn(tx); CAmount Out = tx.GetValueOut(); if (tx.IsCoinBase()) Reward += Out; else if (In < 0) Fees = -Params().MaxMoneyOut(); else { Fees += In - Out; OutVolume += Out; } } TxContent += "</table>"; CAmount Generated; if (pBlock->nHeight == 0) Generated = OutVolume; else Generated = GetBlockValue(pBlock->nHeight - 1); std::string BlockContentCells[] = { _("Height"), itostr(pBlock->nHeight), _("Size"), itostr(GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)), _("Number of Transactions"), itostr(block.vtx.size()), _("Value Out"), ValueToString(OutVolume), _("Fees"), ValueToString(Fees), _("Generated"), ValueToString(Generated), _("Timestamp"), TimeToString(block.nTime), _("Difficulty"), strprintf("%.4f", GetDifficulty(pBlock)), _("Bits"), utostr(block.nBits), _("Nonce"), utostr(block.nNonce), _("Version"), itostr(block.nVersion), _("Hash"), "<pre>" + block.GetHash().GetHex() + "</pre>", _("Merkle Root"), "<pre>" + block.hashMerkleRoot.GetHex() + "</pre>", // _("Hash Whole Block"), "<pre>" + block.hashWholeBlock.GetHex() + "</pre>" // _("Miner Signature"), "<pre>" + block.MinerSignature.ToString() + "</pre>" }; std::string BlockContent = makeHTMLTable(BlockContentCells, sizeof(BlockContentCells) / (2 * sizeof(std::string)), 2); std::string Content; Content += "<h2><a class=\"nav\" href="; Content += itostr(pBlock->nHeight - 1); Content += ">◄ </a>"; Content += _("Block"); Content += " "; Content += itostr(pBlock->nHeight); Content += "<a class=\"nav\" href="; Content += itostr(pBlock->nHeight + 1); Content += "> ►</a></h2>"; Content += BlockContent; Content += "</br>"; /* if (block.nHeight > getThirdHardforkBlock()) { std::vector<std::string> votes[2]; for (int i = 0; i < 2; i++) { for (unsigned int j = 0; j < block.vvotes[i].size(); j++) { votes[i].push_back(block.vvotes[i][j].hash.ToString() + ':' + itostr(block.vvotes[i][j].n)); } } Content += "<h3>" + _("Votes +") + "</h3>"; Content += makeHTMLTable(&votes[1][0], votes[1].size(), 1); Content += "</br>"; Content += "<h3>" + _("Votes -") + "</h3>"; Content += makeHTMLTable(&votes[0][0], votes[0].size(), 1); Content += "</br>"; } */ Content += "<h2>" + _("Transactions") + "</h2>"; Content += TxContent; return Content; }