Genesis Masternode Adjustments (#36)

Adjusted the block formulation to allow for masternode blocks
This commit is contained in:
Loki Taljaard 2019-03-17 23:17:57 -05:00 committed by Beshoy Girgis
parent c472159498
commit e80116c298
3 changed files with 167 additions and 61 deletions

View File

@ -47,16 +47,32 @@ var BlockTemplate = module.exports = function BlockTemplate(
if (coin.payFoundersReward === true) {
if (!this.rpcData.founders || this.rpcData.founders.length <= 0) {
console.log('Error, founders reward missing for block template!');
} else if (this.rpcData.infrastructure && this.rpcData.infrastructure > 0){
// SafeCash
blockReward = {
"miner": (this.rpcData.miner),
"infrastructure": (this.rpcData.infrastructure),
"giveaways": (this.rpcData.giveaways),
"founderSplit": (this.rpcData.loki),
"total": (this.rpcData.miner + this.rpcData.founders + this.rpcData.infrastructure + this.rpcData.giveaways)
};
//console.log(`SafeCash: ${this.rpcData.miner}`);
} else if (coin.payAllFounders){
// SafeCash / Genx
if (!rpcData.masternode_payments_started)
{
// Pre masternodes
blockReward = {
"miner": (this.rpcData.miner),
"infrastructure": (this.rpcData.infrastructure),
"giveaways": (this.rpcData.giveaways),
"founderSplit": (this.rpcData.loki),
"total": (this.rpcData.miner + this.rpcData.founders + this.rpcData.infrastructure + this.rpcData.giveaways)
};
//console.log(`SafeCash: ${this.rpcData.miner}`);
}
else
{
// console.log(this.rpcData);
// Masternodes active
blockReward = {
"miner": (this.rpcData.miner),
"infrastructure": (this.rpcData.infrastructure),
"giveaways": (this.rpcData.giveaways),
"founderamount": (this.rpcData.founderamount),
"total": (this.rpcData.coinbasevalue)
};
}
} else {
blockReward = {
"total": (this.rpcData.miner + this.rpcData.founders + this.rpcData.securenodes + this.rpcData.supernodes) * 100000000

View File

@ -616,7 +616,15 @@ var pool = module.exports = function pool(options, authorizeFn) {
callback(result.error);
} else {
result.response.miner = subsidy.miner;
result.response.founders = (subsidy.founders || subsidy.community || (subsidy['founders-chris'] + subsidy['founders-jimmy'] + subsidy['founders-scott'] + subsidy['founders-shelby'] + subsidy['founders-loki'] ));
if (!result.response.founders)
{
result.response.founders = (subsidy.founders || subsidy.community || (subsidy['founders-chris'] + subsidy['founders-jimmy'] + subsidy['founders-scott'] + subsidy['founders-shelby'] + subsidy['founders-loki'] ));
}
else
{
// founders already set in block template
// console.log(result.response.founders);
}
// I hate to do this but vision coin doesn't send the
// correct response for getblocksubsidy so this allows
@ -632,14 +640,28 @@ var pool = module.exports = function pool(options, authorizeFn) {
result.response.securenodes = (subsidy.securenodes || 0);
result.response.supernodes = (subsidy.supernodes || 0);
// SafeCash
result.response.infrastructure = (subsidy.infrastructure || 0);
result.response.giveaways = (subsidy.giveaways || 0);
result.response.chris = (subsidy['founders-chris'] || 0);
result.response.jimmy = (subsidy['founders-jimmy'] || 0);
result.response.scott = (subsidy['founders-scott'] || 0);
result.response.shelby = (subsidy['founders-shelby'] || 0);
result.response.loki = (subsidy['founders-loki'] || 0);
// SafeCash / Genx
if (!result.response.masternode_payments_started)
{
// Before masternodes
result.response.infrastructure = (subsidy.infrastructure || 0);
result.response.giveaways = (subsidy.giveaways || 0);
result.response.chris = (subsidy['founders-chris'] || 0);
result.response.jimmy = (subsidy['founders-jimmy'] || 0);
result.response.scott = (subsidy['founders-scott'] || 0);
result.response.shelby = (subsidy['founders-shelby'] || 0);
result.response.loki = (subsidy['founders-loki'] || 0);
}
else
{
// Masternodes active
result.response.infrastructure = (subsidy.infrastructure || 0);
result.response.giveaways = (subsidy.giveaways || 0);
result.response.masternodestotal = (subsidy.masternodestotal || 0);
result.response.governancetotal = (subsidy.governancetotal || 0);
result.response.founderstotal = (subsidy.founderstotal || 0);
result.response.founderamount = (subsidy.founderamount || 0);
}
var processedNewBlock = _this.jobManager.processTemplate(result.response);
callback(null, result.response, processedNewBlock);

View File

@ -148,51 +148,119 @@ exports.createGeneration = (rpcData, blockReward, feeReward, recipients, poolAdd
Math.round(blockReward.total * (coin.percentTreasuryReward / 100))
)
} else if (coin.payAllFounders === true) {
// SafeCash Addresses
// Founders
// Chris
let chrisAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[0]).hash
// Jimmy
let jimmyAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[1]).hash
// Scott
let scottAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[2]).hash
// Shelby
let shelbyAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[3]).hash
// Loki
let lokiAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[4]).hash
// Infrastructure
let infrastructureAddrHash = bitcoin.address.fromBase58Check(coin.infrastructureAddresses[0]).hash
// Giveaways
let giveawaysAddrHash = bitcoin.address.fromBase58Check(coin.giveawayAddresses[0]).hash
// Add Pool (miner coinbase) transaction
//console.log(`PoolReward: ${blockReward.miner}`)
// SafeCash / Genx
if (!rpcData.masternode_payments_started)
{
// Pre masternodes
// SafeCash Addresses
// Founders
// Chris
let chrisAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[0]).hash
// Jimmy
let jimmyAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[1]).hash
// Scott
let scottAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[2]).hash
// Shelby
let shelbyAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[3]).hash
// Loki
let lokiAddrHash = bitcoin.address.fromBase58Check(coin.foundersRewardAddresses[4]).hash
// Infrastructure
let infrastructureAddrHash = bitcoin.address.fromBase58Check(coin.infrastructureAddresses[0]).hash
// Giveaways
let giveawaysAddrHash = bitcoin.address.fromBase58Check(coin.giveawayAddresses[0]).hash
// Add Pool (miner coinbase) transaction
//console.log(`PoolReward: ${blockReward.miner}`)
// Calculate and do the pool fee deduction
var poolFeeDeductionTotalPercent = 0;
// Calculate the total pool fee deduction
recipients.forEach(function (recipient) {
poolFeeDeductionTotalPercent += recipient.percent;
});
var poolDeductionAmount = Math.round(blockReward.total * (poolFeeDeductionTotalPercent / 100));
console.log('Block Value: ' + blockReward.total);
console.log('Pool Fee Deduction Total Percent: ' + poolFeeDeductionTotalPercent);
console.log('Pool Fee Deduction Total Amount: ' + poolDeductionAmount);
txb.addOutput(
scriptCompile(poolAddrHash),
blockReward.miner - poolDeductionAmount + feeReward
);
// Add founders txs
txb.addOutput(scriptFoundersCompile(chrisAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(jimmyAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(scottAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(shelbyAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(lokiAddrHash), blockReward.founderSplit);
// Infrastructure
txb.addOutput(scriptFoundersCompile(infrastructureAddrHash), blockReward.infrastructure);
// Giveaways
txb.addOutput(scriptFoundersCompile(giveawaysAddrHash), blockReward.giveaways);
}
else
{
// Masternodes active
// Calculate and do the pool fee deduction
var poolFeeDeductionTotalPercent = 0;
// Calculate the total pool fee deduction
recipients.forEach(function (recipient) {
poolFeeDeductionTotalPercent += recipient.percent;
});
// Calculate and do the pool fee deduction
var poolFeeDeductionTotalPercent = 0;
// Calculate the total pool fee deduction
recipients.forEach(function (recipient) {
poolFeeDeductionTotalPercent += recipient.percent;
});
var poolDeductionAmount = Math.round(blockReward.total * (poolFeeDeductionTotalPercent / 100));
// console.log('Block Value: ' + blockReward.total);
// console.log('Pool Fee Deduction Total Percent: ' + poolFeeDeductionTotalPercent);
// console.log('Pool Fee Deduction Total Amount: ' + poolDeductionAmount);
var poolDeductionAmount = Math.round(blockReward.total * (poolFeeDeductionTotalPercent / 100));
txb.addOutput(
scriptCompile(poolAddrHash),
blockReward.miner - poolDeductionAmount + feeReward
);
txb.addOutput(
scriptCompile(poolAddrHash),
blockReward.miner - poolDeductionAmount + feeReward
);
// Add founders txs
txb.addOutput(scriptFoundersCompile(chrisAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(jimmyAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(scottAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(shelbyAddrHash), blockReward.founderSplit);
txb.addOutput(scriptFoundersCompile(lokiAddrHash), blockReward.founderSplit);
// Infrastructure
txb.addOutput(scriptFoundersCompile(infrastructureAddrHash), blockReward.infrastructure);
// Giveaways
txb.addOutput(scriptFoundersCompile(giveawaysAddrHash), blockReward.giveaways);
// Infrastructure
if (rpcData.infrastructure && rpcData.infrastructure > 0)
{
let infrastructureAddrHash = bitcoin.address.fromBase58Check(coin.infrastructureAddresses[0]).hash
txb.addOutput(scriptFoundersCompile(infrastructureAddrHash), blockReward.infrastructure);
}
// Giveaways
if (rpcData.giveaways && rpcData.giveaways > 0)
{
let giveawaysAddrHash = bitcoin.address.fromBase58Check(coin.giveawayAddresses[0]).hash
txb.addOutput(scriptFoundersCompile(giveawaysAddrHash), blockReward.giveaways);
}
// Add founders
if (rpcData.founders && rpcData.founders.length > 0)
{
// loop through founders and add them to our coinbase transaction
rpcData.founders.map((founderItem) => {
txb.addOutput(
new Buffer(founderItem.script, 'hex'),
founderItem.amount
);
});
}
// Add masternode payments
if (rpcData.masternodes && rpcData.masternodes.length > 0)
{
// loop through masternodes and add them to our coinbase transaction
rpcData.founders.map((masternodeItem) => {
txb.addOutput(
new Buffer(masternodeItem.script, 'hex'),
masternodeItem.amount
);
});
}
// Add governance payments
if (rpcData.governanceblock && rpcData.governanceblock.length > 0)
{
// loop through governance items and add them to our coinbase transaction
rpcData.founders.map((governanceItem) => {
txb.addOutput(
new Buffer(governanceItem.script, 'hex'),
governanceItem.amount
);
});
}
}
} else {
// founders reward
let index = parseInt(Math.floor(rpcData.height / coin.foundersRewardAddressChangeInterval))