Zen fork9 sidechainversionfork (#63)
* Add support for fork9_sidechainversionfork: * Add Horizen specific section in else if chain and remove now redundant code * Refactor fork management for Horizen (forks and required data are now defined in s-nomp/coins/zen.json) * Fix: typo * Fix: regression introduced in 'Pers Auto (#61)'
This commit is contained in:
parent
4a608380cf
commit
aa3deddc8c
|
@ -24,8 +24,8 @@ var BlockTemplate = module.exports = function BlockTemplate(
|
|||
//public members
|
||||
this.rpcData = rpcData;
|
||||
this.jobId = jobId;
|
||||
this.algoNK = coin.parameters.N+'_'+coin.parameters.K;
|
||||
this.persString = coin.parameters.personalization;
|
||||
this.algoNK = coin.parameters && coin.parameters.N && coin.parameters.K ? coin.parameters.N+'_'+coin.parameters.K : undefined;
|
||||
this.persString = coin.parameters ? coin.parameters.personalization : undefined;
|
||||
|
||||
// get target info
|
||||
this.target = bignum(rpcData.target, 16);
|
||||
|
|
|
@ -92,80 +92,56 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd
|
|||
else if ((masternodePayment === false || masternodePayment === undefined) && payZelNodeRewards === false && !rpcData.coinbase_required_outputs) {
|
||||
// txs with founders reward
|
||||
// This section is for ZEN + other coins
|
||||
if (coin.payFoundersReward === true && ((coin.maxFoundersRewardBlockHeight >= rpcData.height || coin.treasuryRewardStartBlockHeight || coin.treasuryRewardUpdateStartBlockHeight || coin.treasuryReward20pctUpdateStartBlockHeight) || coin.payAllFounders === true)) {
|
||||
// treasury reward or Super Nodes treasury update?
|
||||
if ((coin.treasuryRewardUpdateStartBlockHeight || coin.treasuryReward20pctUpdateStartBlockHeight) && rpcData.height >= (coin.treasuryRewardUpdateStartBlockHeight || coin.treasuryReward20pctUpdateStartBlockHeight)) {
|
||||
let percentTreasuryReward = coin.percentTreasuryUpdateReward
|
||||
let treasuryRewardStartBlockHeight = coin.treasuryRewardUpdateStartBlockHeight
|
||||
// Horizen treasury reward 20% update
|
||||
if (coin.treasuryReward20pctUpdateStartBlockHeight && rpcData.height >= coin.treasuryReward20pctUpdateStartBlockHeight) {
|
||||
percentTreasuryReward = coin.percentTreasury20pctUpdateReward
|
||||
treasuryRewardStartBlockHeight = coin.treasuryReward20pctUpdateStartBlockHeight
|
||||
if (coin.payFoundersReward === true && (coin.maxFoundersRewardBlockHeight >= rpcData.height || coin.symbol === 'zen' || coin.symbol === 'zent' || coin.payAllFounders === true)) {
|
||||
// This section is for Horizen
|
||||
if (coin.symbol === 'zen' || coin.symbol === 'zent') {
|
||||
|
||||
// select the correct fork for current height
|
||||
let forkIndex = coin.forks.findIndex((f) => rpcData.height < f.activationHeight);
|
||||
// set to last fork in case rpcData.height > coin.forks[coin.forks.length - 1].activationHeight
|
||||
forkIndex = forkIndex === -1 ? coin.forks.length : forkIndex;
|
||||
let fork = coin.forks[forkIndex - 1];
|
||||
|
||||
let pctTreasury = fork.treasury ? fork.treasury.pct : 0;
|
||||
let pctSecureNodes = fork.securenodes ? fork.securenodes.pct : 0;
|
||||
let pctSuperNodes = fork.supernodes ? fork.supernodes.pct : 0;
|
||||
|
||||
// pool t-addr
|
||||
txb.addOutput(
|
||||
scriptCompile(poolAddrHash),
|
||||
Math.round(blockReward.total * (1 - (pctTreasury + pctSecureNodes + pctSuperNodes + feePercent) / 100)) + feeReward
|
||||
)
|
||||
|
||||
// treasury reward
|
||||
if (pctTreasury) {
|
||||
let indexTre = fork.treasury.changeInterval ? parseInt(Math.floor(((rpcData.height - fork.activationHeight) / fork.treasury.changeInterval) % fork.treasury.addresses.length)) : 0;
|
||||
let treasuryAddrHash = bitcoin.address.fromBase58Check(fork.treasury.addresses[indexTre]).hash;
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(treasuryAddrHash),
|
||||
Math.round(blockReward.total * (pctTreasury / 100))
|
||||
)
|
||||
}
|
||||
|
||||
// treasury reward
|
||||
let indexCF = parseInt(Math.floor(((rpcData.height - treasuryRewardStartBlockHeight) / coin.treasuryRewardUpdateAddressChangeInterval) % coin.vTreasuryRewardUpdateAddress.length))
|
||||
let foundersAddrHash = bitcoin.address.fromBase58Check(coin.vTreasuryRewardUpdateAddress[indexCF]).hash
|
||||
|
||||
// Secure Nodes reward
|
||||
let indexSN = parseInt(Math.floor(((rpcData.height - coin.treasuryRewardUpdateStartBlockHeight) / coin.treasuryRewardUpdateAddressChangeInterval) % coin.vSecureNodesRewardAddress.length))
|
||||
let secureNodesAddrHash = bitcoin.address.fromBase58Check(coin.vSecureNodesRewardAddress[indexSN]).hash
|
||||
if (pctSecureNodes) {
|
||||
let indexSec = fork.securenodes.changeInterval ? parseInt(Math.floor(((rpcData.height - fork.activationHeight) / fork.securenodes.changeInterval) % fork.securenodes.addresses.length)) : 0;
|
||||
let secureNodesAddrHash = bitcoin.address.fromBase58Check(fork.securenodes.addresses[indexSec]).hash;
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(secureNodesAddrHash),
|
||||
Math.round(blockReward.total * (pctSecureNodes / 100))
|
||||
)
|
||||
}
|
||||
|
||||
// Super Nodes reward
|
||||
let indexXN = parseInt(Math.floor(((rpcData.height - coin.treasuryRewardUpdateStartBlockHeight) / coin.treasuryRewardUpdateAddressChangeInterval) % coin.vSuperNodesRewardAddress.length))
|
||||
let superNodesAddrHash = bitcoin.address.fromBase58Check(coin.vSuperNodesRewardAddress[indexXN]).hash
|
||||
if (pctSuperNodes) {
|
||||
let indexSup = fork.supernodes.changeInterval ? parseInt(Math.floor(((rpcData.height - fork.activationHeight) / fork.supernodes.changeInterval) % fork.supernodes.addresses.length)) : 0;
|
||||
let superNodesAddrHash = bitcoin.address.fromBase58Check(fork.supernodes.addresses[indexSup]).hash;
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(superNodesAddrHash),
|
||||
Math.round(blockReward.total * (pctSuperNodes / 100))
|
||||
)
|
||||
}
|
||||
|
||||
// console.log(`treasuryIndex: ${indexCF}`)
|
||||
// console.log(`treasuryAddr: ${coin.vTreasuryRewardUpdateAddress[indexCF]}`)
|
||||
// console.log(`secureNodesIndex: ${indexSN}`)
|
||||
// console.log(`secureNodesAddr: ${coin.vSecureNodesRewardAddress[indexSN]}`)
|
||||
// console.log(`superNodesIndex: ${indexXN}`)
|
||||
// console.log(`superNodesAddr: ${coin.vSuperNodesRewardAddress[indexXN]}`)
|
||||
|
||||
// pool t-addr
|
||||
txb.addOutput(
|
||||
scriptCompile(poolAddrHash),
|
||||
Math.round(blockReward.total * (1 - (percentTreasuryReward + coin.percentSecureNodesReward + coin.percentSuperNodesReward + feePercent) / 100)) + feeReward
|
||||
)
|
||||
|
||||
// treasury t-addr
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(foundersAddrHash),
|
||||
Math.round(blockReward.total * (percentTreasuryReward / 100))
|
||||
)
|
||||
|
||||
// Secure Nodes t-addr
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(secureNodesAddrHash),
|
||||
Math.round(blockReward.total * (coin.percentSecureNodesReward / 100))
|
||||
)
|
||||
|
||||
// Super Nodes t-addr
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(superNodesAddrHash),
|
||||
Math.round(blockReward.total * (coin.percentSuperNodesReward / 100))
|
||||
)
|
||||
|
||||
// founders or treasury reward?
|
||||
} else if (coin.treasuryRewardStartBlockHeight && rpcData.height >= coin.treasuryRewardStartBlockHeight) {
|
||||
// treasury reward
|
||||
let index = parseInt(Math.floor(((rpcData.height - coin.treasuryRewardStartBlockHeight) / coin.treasuryRewardAddressChangeInterval) % coin.vTreasuryRewardAddress.length))
|
||||
let foundersAddrHash = bitcoin.address.fromBase58Check(coin.vTreasuryRewardAddress[index]).hash
|
||||
|
||||
// console.log(`treasuryIndex: ${index}`)
|
||||
// console.log(`treasuryAddr: ${coin.vTreasuryRewardAddress[index]}`)
|
||||
|
||||
// pool t-addr
|
||||
txb.addOutput(
|
||||
scriptCompile(poolAddrHash),
|
||||
Math.round(blockReward.total * (1 - (coin.percentTreasuryReward + feePercent) / 100)) + feeReward
|
||||
)
|
||||
|
||||
// treasury t-addr
|
||||
txb.addOutput(
|
||||
scriptFoundersCompile(foundersAddrHash),
|
||||
Math.round(blockReward.total * (coin.percentTreasuryReward / 100))
|
||||
)
|
||||
} else if (coin.payAllFounders === true) {
|
||||
// SafeCash / Genx
|
||||
// Calculate and do the pool fee deduction
|
||||
|
|
Loading…
Reference in New Issue