From 2729b90249d96eb6ecd45cee0a32e1359c03474a Mon Sep 17 00:00:00 2001 From: TheTrunk Date: Sun, 21 Mar 2021 07:07:04 +0100 Subject: [PATCH 1/4] support for pupcoming flux fork (#1) * add support for flux fork --- lib/blockTemplate.js | 24 +++++++++++++++++++++++- lib/transactions.js | 31 ++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 1d714cc..3443a85 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,13 @@ var BlockTemplate = module.exports = function BlockTemplate( var zelnodeBamfAddress; var zelnodeBamfAmount; + var fluxSwapPoolAddress; + var fluxSwapPoolAmount; + var fluxFoundationPoolAddress + var fluxFoundationPoolAmount; + var fluxExchangePoolAddress; + var fluxExchangePoolAmount; + if(coin.vFundingStreams) { // Zcash has moved to fundingstreams via getblocksubsidy. // This will calculate block reward and fundingstream totals. @@ -117,6 +125,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 +133,13 @@ var BlockTemplate = module.exports = function BlockTemplate( zelnodeBamfAddress = coin.payZelNodes ? rpcData.bamf_zelnode_address : null; zelnodeBamfAmount = coin.payZelNodes ? (rpcData.bamf_zelnode_payout || 0): 0; + fluxSwapPoolAddress = coin.payZelNodes ? rpcData.swap_pool_fund_address : null; + fluxSwapPoolAmount = coin.payZelNodes ? (rpcData.swap_pool_fund_amount || 0) : 0; + fluxFoundationPoolAddress = coin.payZelNodes ? rpcData.foundation_fund_address : null; + fluxFoundationPoolAmount = coin.payZelNodes ? (rpcData.foundation_fund_amount || 0) : 0; + fluxExchangePoolAddress = coin.payZelNodes ? rpcData.exchange_fund_address : null; + fluxExchangePoolAmount = coin.payZelNodes ? (rpcData.exchange_fund_amount || 0): 0; + var fees = []; rpcData.transactions.forEach(function(value) { fees.push(value); @@ -148,7 +164,13 @@ var BlockTemplate = module.exports = function BlockTemplate( zelnodeSuperAddress, zelnodeSuperAmount, zelnodeBamfAddress, - zelnodeBamfAmount + zelnodeBamfAmount, + fluxSwapPoolAddress, + fluxSwapPoolAmount, + fluxExchangePoolAddress, + fluxExchangePoolAmount, + fluxFoundationPoolAddress, + fluxFoundationPoolAmount ).toString('hex'); this.genTxHash = transactions.txHash(); diff --git a/lib/transactions.js b/lib/transactions.js index 6ec10b2..d1b9957 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, fluxSwapPoolAddress, fluxSwapPoolAmount, fluxExchangePoolAddress, fluxExchangePoolAmount, fluxFoundationPoolAddress, fluxFoundationPoolAmount) => { let poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash let network = coin.network @@ -494,6 +494,35 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd Math.round(zelnodeBamfAmount) ) } + + // Flux fork. Adds additional funds generation for swap pools, exchanges, foundation + let fluxSwapPoolAddrHash = fluxSwapPoolAddress ? bitcoin.address.fromBase58Check(fluxSwapPoolAddress).hash : null + let fluxFoundationPoolAddrHash = fluxFoundationPoolAddress ? bitcoin.address.fromBase58Check(fluxFoundationPoolAddress).hash : null + let fluxExchangePoolAddrHash = fluxExchangePoolAddress ? bitcoin.address.fromBase58Check(fluxExchangePoolAddress).hash : null + + // swap fund + if (fluxSwapPoolAddrHash != null) { + txb.addOutput( + scriptCompile(fluxSwapPoolAddrHash), + Math.round(fluxSwapPoolAmount) + ) + } + + // foundation fund + if (fluxFoundationPoolAddrHash != null) { + txb.addOutput( + scriptCompile(fluxFoundationPoolAddrHash), + Math.round(fluxFoundationPoolAmount) + ) + } + + // exchange fund + if (fluxExchangePoolAddrHash != null) { + txb.addOutput( + scriptCompile(fluxExchangePoolAddrHash), + Math.round(fluxExchangePoolAmount) + ) + } } // Segwit support From 274bad9ce1d3e8228f7300d2a286681df9c47200 Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Wed, 24 Mar 2021 09:18:05 +0800 Subject: [PATCH 2/4] simplify flux pool creations --- lib/blockTemplate.js | 24 ++++++------------------ lib/transactions.js | 30 ++++++------------------------ 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 3443a85..8b74d5b 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -45,12 +45,8 @@ var BlockTemplate = module.exports = function BlockTemplate( var zelnodeBamfAddress; var zelnodeBamfAmount; - var fluxSwapPoolAddress; - var fluxSwapPoolAmount; - var fluxFoundationPoolAddress - var fluxFoundationPoolAmount; - var fluxExchangePoolAddress; - var fluxExchangePoolAmount; + var fluxPoolAddress; + var fluxPoolAmount; if(coin.vFundingStreams) { // Zcash has moved to fundingstreams via getblocksubsidy. @@ -133,12 +129,8 @@ var BlockTemplate = module.exports = function BlockTemplate( zelnodeBamfAddress = coin.payZelNodes ? rpcData.bamf_zelnode_address : null; zelnodeBamfAmount = coin.payZelNodes ? (rpcData.bamf_zelnode_payout || 0): 0; - fluxSwapPoolAddress = coin.payZelNodes ? rpcData.swap_pool_fund_address : null; - fluxSwapPoolAmount = coin.payZelNodes ? (rpcData.swap_pool_fund_amount || 0) : 0; - fluxFoundationPoolAddress = coin.payZelNodes ? rpcData.foundation_fund_address : null; - fluxFoundationPoolAmount = coin.payZelNodes ? (rpcData.foundation_fund_amount || 0) : 0; - fluxExchangePoolAddress = coin.payZelNodes ? rpcData.exchange_fund_address : null; - fluxExchangePoolAmount = coin.payZelNodes ? (rpcData.exchange_fund_amount || 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) { @@ -165,12 +157,8 @@ var BlockTemplate = module.exports = function BlockTemplate( zelnodeSuperAmount, zelnodeBamfAddress, zelnodeBamfAmount, - fluxSwapPoolAddress, - fluxSwapPoolAmount, - fluxExchangePoolAddress, - fluxExchangePoolAmount, - fluxFoundationPoolAddress, - fluxFoundationPoolAmount + fluxPoolAddress, + fluxPoolAmount ).toString('hex'); this.genTxHash = transactions.txHash(); diff --git a/lib/transactions.js b/lib/transactions.js index d1b9957..616a1f4 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, fluxSwapPoolAddress, fluxSwapPoolAmount, fluxExchangePoolAddress, fluxExchangePoolAmount, fluxFoundationPoolAddress, fluxFoundationPoolAmount) => { +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 @@ -496,31 +496,13 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd } // Flux fork. Adds additional funds generation for swap pools, exchanges, foundation - let fluxSwapPoolAddrHash = fluxSwapPoolAddress ? bitcoin.address.fromBase58Check(fluxSwapPoolAddress).hash : null - let fluxFoundationPoolAddrHash = fluxFoundationPoolAddress ? bitcoin.address.fromBase58Check(fluxFoundationPoolAddress).hash : null - let fluxExchangePoolAddrHash = fluxExchangePoolAddress ? bitcoin.address.fromBase58Check(fluxExchangePoolAddress).hash : null + let fluxPoolAddrHash = fluxPoolAddress ? bitcoin.address.fromBase58Check(fluxPoolAddress).hash : null - // swap fund - if (fluxSwapPoolAddrHash != null) { + // flux pool creation + if (fluxPoolAddrHash != null) { txb.addOutput( - scriptCompile(fluxSwapPoolAddrHash), - Math.round(fluxSwapPoolAmount) - ) - } - - // foundation fund - if (fluxFoundationPoolAddrHash != null) { - txb.addOutput( - scriptCompile(fluxFoundationPoolAddrHash), - Math.round(fluxFoundationPoolAmount) - ) - } - - // exchange fund - if (fluxExchangePoolAddrHash != null) { - txb.addOutput( - scriptCompile(fluxExchangePoolAddrHash), - Math.round(fluxExchangePoolAmount) + scriptCompile(fluxPoolAddrHash), + Math.round(fluxPoolAmount) ) } } From 29fc3f0843e023dae7af1d4ad4e3a51b8e5c12b5 Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Tue, 6 Apr 2021 21:51:26 +0800 Subject: [PATCH 3/4] fix flux pool addresses being multisig --- lib/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/transactions.js b/lib/transactions.js index 616a1f4..497a34a 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -501,7 +501,7 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd // flux pool creation if (fluxPoolAddrHash != null) { txb.addOutput( - scriptCompile(fluxPoolAddrHash), + scriptFoundersCompile(fluxPoolAddrHash), Math.round(fluxPoolAmount) ) } From b5e8180348215bd5d514b0a93feb2d1159e5b2bf Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Tue, 6 Apr 2021 21:59:53 +0800 Subject: [PATCH 4/4] adjust for p2sh addresses --- lib/transactions.js | 62 ++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/lib/transactions.js b/lib/transactions.js index 497a34a..b488695 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -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,47 @@ 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 @@ -500,10 +521,17 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd // flux pool creation if (fluxPoolAddrHash != null) { - txb.addOutput( - scriptFoundersCompile(fluxPoolAddrHash), - Math.round(fluxPoolAmount) - ) + if (fluxPoolAddress.startsWith('t3') || fluxPoolAddress.startsWith('t2')) { + txb.addOutput( + scriptFoundersCompile(fluxPoolAddrHash), + Math.round(fluxPoolAmount) + ) + } else { + txb.addOutput( + scriptCompile(fluxPoolAddrHash), + Math.round(fluxPoolAmount) + ) + } } }