diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 1d714cc..8b74d5b 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -37,6 +37,7 @@ var BlockTemplate = module.exports = function BlockTemplate( var masternodeReward; var masternodePayee; var masternodePayment; + var zelnodeBasicAddress; var zelnodeBasicAmount; var zelnodeSuperAddress; @@ -44,6 +45,9 @@ var BlockTemplate = module.exports = function BlockTemplate( var zelnodeBamfAddress; var zelnodeBamfAmount; + var fluxPoolAddress; + var fluxPoolAmount; + if(coin.vFundingStreams) { // Zcash has moved to fundingstreams via getblocksubsidy. // This will calculate block reward and fundingstream totals. @@ -117,6 +121,7 @@ var BlockTemplate = module.exports = function BlockTemplate( masternodeReward = rpcData.payee_amount; masternodePayee = rpcData.payee; masternodePayment = rpcData.masternode_payments; + zelnodeBasicAddress = coin.payZelNodes ? rpcData.basic_zelnode_address : null; zelnodeBasicAmount = coin.payZelNodes ? (rpcData.basic_zelnode_payout || 0) : 0; zelnodeSuperAddress = coin.payZelNodes ? rpcData.super_zelnode_address : null; @@ -124,6 +129,9 @@ var BlockTemplate = module.exports = function BlockTemplate( zelnodeBamfAddress = coin.payZelNodes ? rpcData.bamf_zelnode_address : null; zelnodeBamfAmount = coin.payZelNodes ? (rpcData.bamf_zelnode_payout || 0): 0; + fluxPoolAddress = coin.payZelNodes ? rpcData.flux_creation_address : null; + fluxPoolAmount = coin.payZelNodes ? (rpcData.flux_creation_amount || 0) : 0; + var fees = []; rpcData.transactions.forEach(function(value) { fees.push(value); @@ -148,7 +156,9 @@ var BlockTemplate = module.exports = function BlockTemplate( zelnodeSuperAddress, zelnodeSuperAmount, zelnodeBamfAddress, - zelnodeBamfAmount + zelnodeBamfAmount, + fluxPoolAddress, + fluxPoolAmount ).toString('hex'); this.genTxHash = transactions.txHash(); diff --git a/lib/transactions.js b/lib/transactions.js index 6ec10b2..b488695 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -19,7 +19,7 @@ const scriptFoundersCompile = address => bitcoin.script.compile([ let txHash exports.txHash = () => txHash -exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAddress, poolHex, coin, masternodeReward, masternodePayee, masternodePayment, zelnodeBasicAddress, zelnodeBasicAmount, zelnodeSuperAddress, zelnodeSuperAmount, zelnodeBamfAddress, zelnodeBamfAmount) => { +exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAddress, poolHex, coin, masternodeReward, masternodePayee, masternodePayment, zelnodeBasicAddress, zelnodeBasicAmount, zelnodeSuperAddress, zelnodeSuperAmount, zelnodeBamfAddress, zelnodeBamfAmount, fluxPoolAddress, fluxPoolAmount) => { let poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash let network = coin.network @@ -465,7 +465,7 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd let zelnodeSuperAddrHash = zelnodeSuperAddress ? bitcoin.address.fromBase58Check(zelnodeSuperAddress).hash : null let zelnodeBamfAddrHash = zelnodeBamfAddress ? bitcoin.address.fromBase58Check(zelnodeBamfAddress).hash : null - // pool t-addr + // pool t-addr, assume p2pkh txb.addOutput( scriptCompile(poolAddrHash), Math.round(blockReward.total * (1 - (feePercent / 100))) + feeReward - zelnodeBasicAmount - zelnodeSuperAmount - zelnodeBamfAmount @@ -473,26 +473,65 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd // zelnode basic reward if (zelnodeBasicAddrHash != null) { - txb.addOutput( - scriptCompile(zelnodeBasicAddrHash), - Math.round(zelnodeBasicAmount) - ) + if (zelnodeBasicAddress.startsWith('t3') || zelnodeBasicAddress.startsWith('t2')) { + txb.addOutput( + scriptFoundersCompile(zelnodeBasicAddrHash), + Math.round(zelnodeBasicAmount) + ) + } else { + txb.addOutput( + scriptCompile(zelnodeBasicAddrHash), + Math.round(zelnodeBasicAmount) + ) + } } // zelnode super reward if (zelnodeSuperAddrHash != null) { - txb.addOutput( - scriptCompile(zelnodeSuperAddrHash), - Math.round(zelnodeSuperAmount) - ) + if (zelnodeSuperAddress.startsWith('t3') || zelnodeSuperAddress.startsWith('t2')) { + txb.addOutput( + scriptFoundersCompile(zelnodeSuperAddrHash), + Math.round(zelnodeSuperAmount) + ) + } else { + txb.addOutput( + scriptCompile(zelnodeSuperAddrHash), + Math.round(zelnodeSuperAmount) + ) + } } // zelnode bamf reward if (zelnodeBamfAddrHash != null) { - txb.addOutput( - scriptCompile(zelnodeBamfAddrHash), - Math.round(zelnodeBamfAmount) - ) + if (zelnodeBamfAddress.startsWith('t3') || zelnodeBamfAddress.startsWith('t2')) { + txb.addOutput( + scriptFoundersCompile(zelnodeBamfAddrHash), + Math.round(zelnodeBamfAmount) + ) + } else { + txb.addOutput( + scriptCompile(zelnodeBamfAddrHash), + Math.round(zelnodeBamfAmount) + ) + } + } + + // Flux fork. Adds additional funds generation for swap pools, exchanges, foundation + let fluxPoolAddrHash = fluxPoolAddress ? bitcoin.address.fromBase58Check(fluxPoolAddress).hash : null + + // flux pool creation + if (fluxPoolAddrHash != null) { + if (fluxPoolAddress.startsWith('t3') || fluxPoolAddress.startsWith('t2')) { + txb.addOutput( + scriptFoundersCompile(fluxPoolAddrHash), + Math.round(fluxPoolAmount) + ) + } else { + txb.addOutput( + scriptCompile(fluxPoolAddrHash), + Math.round(fluxPoolAmount) + ) + } } }