Skip to content

Commit

Permalink
bugfix for Koto
Browse files Browse the repository at this point in the history
  • Loading branch information
ROZ-MOFUMOFU-ME committed Sep 22, 2024
1 parent 3e5b58a commit 51303bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
49 changes: 20 additions & 29 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var crypto = require('crypto');
var base58 = require('bs58check');
var base58 = require('bs58');
var bitcoin = require('bitcoinjs-lib');


Expand Down Expand Up @@ -408,60 +408,51 @@ exports.setupKotoConsensusParams = function (options) {
}

exports.getKotoBlockSubsidy = function (nHeight) {
var COIN = bignum(100000000);
var nSubsidy = COIN.mul(100);
const COIN = BigInt(100000000);
let nSubsidy = COIN * BigInt(100);

if (nHeight == 1) {
nSubsidy = COIN.mul(3920000);
return nSubsidy.toNumber();
if (nHeight === 1) {
nSubsidy = COIN * BigInt(3920000);
return Number(nSubsidy);
}

// Mining slow start
// The subsidy is ramped up linearly, skipping the middle payout of
// MAX_SUBSIDY/2 to keep the monetary curve consistent with no slow start.
if (nHeight < consensusParams.nSubsidySlowStartInterval / 2) {
nSubsidy = nSubsidy.div(consensusParams.nSubsidySlowStartInterval);
return nSubsidy.mul(nHeight).toNumber();
nSubsidy = nSubsidy / BigInt(consensusParams.nSubsidySlowStartInterval);
return Number(nSubsidy * BigInt(nHeight));
} else if (nHeight < consensusParams.nSubsidySlowStartInterval) {
nSubsidy = nSubsidy.div(consensusParams.nSubsidySlowStartInterval);
return nSubsidy.mul(nHeight + 1).toNumber();
nSubsidy = nSubsidy / BigInt(consensusParams.nSubsidySlowStartInterval);
return Number(nSubsidy * BigInt(nHeight + 1));
}

var halvings = Math.floor((nHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nSubsidyHalvingInterval);
const halvings = Math.floor((nHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nSubsidyHalvingInterval);
// Force block reward to zero when right shift is undefined.
if (halvings >= 64)
return 0;
if (halvings >= 64) return 0;

// Subsidy is cut in half every 840,000 blocks which will occur approximately every 4 years.
nSubsidy = nSubsidy.shiftRight(halvings);
return nSubsidy.toNumber();
nSubsidy = nSubsidy >> BigInt(halvings);
return Number(nSubsidy);
};

exports.getFounderRewardScript = function (network, addr) {

if (typeof network !== 'undefined' && network !== null) {
return bitcoin.address.toOutputScript(addr, network);
} else {
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), bitcoin.address.fromBase58Check(addr).hash, Buffer.from([0x88, 0xac])]);
}

};

exports.getKotoFounderRewardScript = function (addr) {
const decoded = base58.decode(addr);

var decoded = base58.decode(addr);

if (decoded.length != 25 && decoded.length != 26) {
console.error('invalid address length for ' + addr);
throw new Error();
if (decoded.length !== 25 && decoded.length !== 26) {
console.error('Invalid address length for ' + addr);
throw new Error('Invalid address length');
}

if (!decoded) {
console.error('base58 decode failed for ' + addr);
throw new Error();
}

var pubkey = decoded.slice(decoded.length - 24, -4);
const pubkey = decoded.slice(decoded.length - 24, -4);

return Buffer.concat([Buffer.from([0xa9, 0x14]), pubkey, Buffer.from([0x87])]);
}
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stratum-pool",
"version": "0.2.2",
"version": "0.2.3",
"description": "High performance Stratum poolserver in Node.js",
"keywords": [
"stratum",
Expand Down Expand Up @@ -30,13 +30,13 @@
"url": "https://github.com/ROZ-MOFUMOFU-ME/node-stratum-pool.git"
},
"dependencies": {
"async": "^3.2.5",
"async": "^3.2.6",
"bchaddrjs": "^0.5.2",
"bs58check": "^3.0.1",
"bitcoinjs-lib": "^5.2.0",
"bitcoinjs-lib": "^7.0.0-rc.0",
"multi-hashing": "git+https://github.com/ROZ-MOFUMOFU-ME/node-multi-hashing.git"
},
"engines": {
"node": ">=16"
"node": ">=16",
"npm": ">=7"
}
}

0 comments on commit 51303bc

Please sign in to comment.