Skip to content

Commit

Permalink
Update founder reward script generation and address conversion
Browse files Browse the repository at this point in the history
- Update the code to generate founder reward script for the Koto cryptocurrency.
- Update the address conversion functions to handle Koto addresses.
- Refactor the code to use the bs58check library for base58 dependency.
  • Loading branch information
Aoi Emerauda authored and Aoi Emerauda committed Nov 5, 2024
1 parent 1aec409 commit 309056f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
20 changes: 13 additions & 7 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ var pool = module.exports = function pool(options, authorizeFn) {
percent: percent / 100
};
try {
if (r.length === 40) {
if (options.coin.name === 'koto' || options.coin.name === 'koto_testnet') {
rObj.script = util.kotoAddressToScript(r);
} else if (r.length === 40) {
rObj.script = util.miningKeyToScript(r);
} else {
rObj.script = util.addressToScript(options.network, r);
Expand Down Expand Up @@ -468,11 +470,15 @@ var pool = module.exports = function pool(options, authorizeFn) {
options.network = (options.testnet ? options.coin.testnet : options.coin.mainnet);

options.poolAddressScript = (function () {
switch (options.coin.reward) {
case 'POS':
return util.pubkeyToScript(rpcResults.validateaddress.pubkey);
case 'POW':
return util.addressToScript(options.network, rpcResults.validateaddress.address);
if (options.coin.name === 'koto' || options.coin.name === 'koto_testnet') {
return util.kotoAddressToScript(rpcResults.validateaddress.address);
} else {
switch (options.coin.reward) {
case 'POS':
return util.pubkeyToScript(rpcResults.validateaddress.pubkey);
case 'POW':
return util.addressToScript(options.network, rpcResults.validateaddress.address);
}
}
})();

Expand Down Expand Up @@ -508,7 +514,7 @@ var pool = module.exports = function pool(options, authorizeFn) {

_this.stratumServer.on('started', function () {
options.initStats.stratumPorts = Object.keys(options.ports);
_this.stratumServer.broadcastMiningJobs(_this.jobManager.currentJob.getJobParams(), _this.jobManager.currentJob.getOdoKey());
_this.stratumServer.broadcastMiningJobs( _this.jobManager.currentJob.getJobParams(), _this.jobManager.currentJob.getOdoKey());
finishedCallback();

}).on('broadcastTimeout', function () {
Expand Down
20 changes: 18 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ exports.miningKeyToScript = function (key) {

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

exports.kotoAddressToScript = function (addr) {
if (typeof network !== 'undefined' && network !== null) {
return bitgoUtxoLib.address.toOutputScript(addr, network);
} else {
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), bitgoUtxoLib.address.fromBase58Check(addr).hash, Buffer.from([0x88, 0xac])]);
}
Expand Down Expand Up @@ -333,7 +341,15 @@ exports.getKotoBlockSubsidy = function (nHeight) {

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

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

0 comments on commit 309056f

Please sign in to comment.