From ad166d2cd1b5f7d59d53e170878b85e6ea9c6ed7 Mon Sep 17 00:00:00 2001 From: sennevb Date: Sun, 1 Apr 2018 15:10:12 +0200 Subject: [PATCH] Add MasterNode support for Snowgem, courtesy of @sennevb --- lib/blockTemplate.js | 10 ++- lib/transactions.js | 163 ++++++++++++++++++++++++++++++++----------- 2 files changed, 131 insertions(+), 42 deletions(-) diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 7c1f8db..0578234 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -24,6 +24,11 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, extr // generate the fees and coinbase tx var blockReward = (this.rpcData.miner) * 100000000; + + var masternodeReward; + var masternodePayee; + var masternodePayment; + if (payFoundersReward === true) { if (!this.rpcData.founders || this.rpcData.founders.length <= 0) { console.log('Error, founders reward missing for block template!'); @@ -31,6 +36,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, extr blockReward = (this.rpcData.miner + this.rpcData.founders) * 100000000; } } + masternodeReward = rpcData.payee_amount; + masternodePayee = rpcData.payee; + masternodePayment = rpcData.masternode_payments; var fees = []; rpcData.transactions.forEach(function(value) { @@ -40,7 +48,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, extr rpcData.rewardFees = this.rewardFees; if (typeof this.genTx === 'undefined') { - this.genTx = transactions.createGeneration(rpcData.height, blockReward, this.rewardFees, recipients, poolAddress, payFoundersReward, percentFoundersReward, maxFoundersRewardBlockHeight, foundersRewardAddressChangeInterval, vFoundersRewardAddress, percentTreasuryReward, treasuryRewardStartBlockHeight, treasuryRewardAddressChangeInterval, vTreasuryRewardAddress).toString('hex'); + this.genTx = transactions.createGeneration(rpcData.height, blockReward, this.rewardFees, recipients, poolAddress, payFoundersReward, percentFoundersReward, maxFoundersRewardBlockHeight, foundersRewardAddressChangeInterval, vFoundersRewardAddress, percentTreasuryReward, treasuryRewardStartBlockHeight, treasuryRewardAddressChangeInterval, vTreasuryRewardAddress, masternodeReward, masternodePayee, masternodePayment).toString('hex'); this.genTxHash = transactions.txHash(); /* diff --git a/lib/transactions.js b/lib/transactions.js index 61bf176..70c0fe4 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -33,6 +33,12 @@ function scriptFoundersCompile(address){ exports.createGeneration = function(blockHeight, blockReward, feeReward, recipients, poolAddress, payFoundersReward, percentFoundersReward, maxFoundersRewardBlockHeight, foundersRewardAddressChangeInterval, vFoundersRewardAddress, percentTreasuryReward, treasuryRewardStartBlockHeight, treasuryRewardAddressChangeInterval, vTreasuryRewardAddress){ var poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash; + if (masternodePayee !== undefined) { + var masternodeAddrHash = bitcoin.address.fromBase58Check(masternodePayee).hash; + } + if (masternodePayment === undefined ) { + masternodePayment = 'false'; + } var tx = new bitcoin.Transaction(); // input for coinbase tx @@ -66,59 +72,134 @@ exports.createGeneration = function(blockHeight, blockReward, feeReward, recipie feePercent = feePercent + recipients[i].percent; } - // txs with founders reward - if (payFoundersReward === true && (maxFoundersRewardBlockHeight >= blockHeight || treasuryRewardStartBlockHeight)) { + if(masternodePayment === 'false') { + // txs with founders reward + if (payFoundersReward === true && (maxFoundersRewardBlockHeight >= blockHeight || treasuryRewardStartBlockHeight)) { - // founders or treasury reward? - if (treasuryRewardStartBlockHeight && blockHeight >= treasuryRewardStartBlockHeight) { + // founders or treasury reward? + if (treasuryRewardStartBlockHeight && blockHeight >= treasuryRewardStartBlockHeight) { - // treasury reward - var index = parseInt(Math.floor(((blockHeight - treasuryRewardStartBlockHeight) / treasuryRewardAddressChangeInterval) % vTreasuryRewardAddress.length)); - var foundersAddrHash = bitcoin.address.fromBase58Check(vTreasuryRewardAddress[index]).hash; + // treasury reward + var index = parseInt(Math.floor(((blockHeight - treasuryRewardStartBlockHeight) / treasuryRewardAddressChangeInterval) % vTreasuryRewardAddress.length)); + var foundersAddrHash = bitcoin.address.fromBase58Check(vTreasuryRewardAddress[index]).hash; - //console.log("treasuryIndex: "+index); - //console.log("treasuryAddr: "+vTreasuryRewardAddress[index]); + //console.log("treasuryIndex: "+index); + //console.log("treasuryAddr: "+vTreasuryRewardAddress[index]); + // pool t-addr + tx.addOutput( + scriptCompile(poolAddrHash), + Math.round(blockReward * (1 - (percentTreasuryReward + feePercent) / 100)) + feeReward + ); + // treasury t-addr + tx.addOutput( + scriptFoundersCompile(foundersAddrHash), + Math.round(blockReward * (percentTreasuryReward / 100)) + ); + + } else { + + // founders reward + var index = parseInt(Math.floor(blockHeight / foundersRewardAddressChangeInterval)); + var foundersAddrHash = bitcoin.address.fromBase58Check(vFoundersRewardAddress[index]).hash; + + //console.log("foundersIndex: "+index); + //console.log("foundersAddr: "+vFoundersRewardAddress[index]); + + // pool t-addr + tx.addOutput( + scriptCompile(poolAddrHash), + Math.round(blockReward * (1 - (percentFoundersReward + feePercent) / 100)) + feeReward + ); + // founders t-addr + tx.addOutput( + scriptFoundersCompile(foundersAddrHash), + Math.round(blockReward * (percentFoundersReward / 100)) + ); + } + } + // no founders rewards :) + else + { // pool t-addr tx.addOutput( scriptCompile(poolAddrHash), - Math.round(blockReward * (1 - (percentTreasuryReward + feePercent) / 100)) + feeReward - ); - // treasury t-addr - tx.addOutput( - scriptFoundersCompile(foundersAddrHash), - Math.round(blockReward * (percentTreasuryReward / 100)) - ); - - } else { - - // founders reward - var index = parseInt(Math.floor(blockHeight / foundersRewardAddressChangeInterval)); - var foundersAddrHash = bitcoin.address.fromBase58Check(vFoundersRewardAddress[index]).hash; - - //console.log("foundersIndex: "+index); - //console.log("foundersAddr: "+vFoundersRewardAddress[index]); - - // pool t-addr - tx.addOutput( - scriptCompile(poolAddrHash), - Math.round(blockReward * (1 - (percentFoundersReward + feePercent) / 100)) + feeReward - ); - // founders t-addr - tx.addOutput( - scriptFoundersCompile(foundersAddrHash), - Math.round(blockReward * (percentFoundersReward / 100)) + Math.round(blockReward * (1 - (feePercent / 100))) + feeReward ); } } - // no founders rewards :) else { - // pool t-addr - tx.addOutput( - scriptCompile(poolAddrHash), - Math.round(blockReward * (1 - (feePercent / 100))) + feeReward - ); + // txs with founders reward + if (payFoundersReward === true && (maxFoundersRewardBlockHeight >= blockHeight || treasuryRewardStartBlockHeight)) { + + // founders or treasury reward? + if (treasuryRewardStartBlockHeight && blockHeight >= treasuryRewardStartBlockHeight) { + + // treasury reward + var index = parseInt(Math.floor(((blockHeight - treasuryRewardStartBlockHeight) / treasuryRewardAddressChangeInterval) % vTreasuryRewardAddress.length)); + var foundersAddrHash = bitcoin.address.fromBase58Check(vTreasuryRewardAddress[index]).hash; + + //console.log("treasuryIndex: "+index); + //console.log("treasuryAddr: "+vTreasuryRewardAddress[index]); + + // pool t-addr + tx.addOutput( + scriptCompile(poolAddrHash), + Math.round(blockReward * (1 - (percentTreasuryReward + feePercent) / 100)) + feeReward - masternodeReward + ); + // treasury t-addr + tx.addOutput( + scriptFoundersCompile(foundersAddrHash), + Math.round(blockReward * (percentTreasuryReward / 100)) + ); + //masternode reward + tx.addOutput( + scriptCompile(masternodeAddrHash), + Math.round(masternodeReward) + ); + + } else { + + // founders reward + var index = parseInt(Math.floor(blockHeight / foundersRewardAddressChangeInterval)); + var foundersAddrHash = bitcoin.address.fromBase58Check(vFoundersRewardAddress[index]).hash; + + //console.log("foundersIndex: "+index); + //console.log("foundersAddr: "+vFoundersRewardAddress[index]); + + // pool t-addr + tx.addOutput( + scriptCompile(poolAddrHash), + Math.round(blockReward * (1 - (percentFoundersReward + feePercent) / 100)) + feeReward - masternodeReward + ); + // founders t-addr + tx.addOutput( + scriptFoundersCompile(foundersAddrHash), + Math.round(blockReward * (percentFoundersReward / 100)) + ); + //masternode reward + tx.addOutput( + scriptCompile(masternodeAddrHash), + Math.round(masternodeReward) + ); + + } + } + // no founders rewards :) + else + { + // pool t-addr + tx.addOutput( + scriptCompile(poolAddrHash), + Math.round(blockReward * (1 - (feePercent / 100))) + feeReward - masternodeReward + ); + //masternode reward + tx.addOutput( + scriptCompile(masternodeAddrHash), + Math.round(masternodeReward) + ); + } } // pool fee recipients t-addr