Skip to content
This repository was archived by the owner on May 23, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c371039
Darkcoin masternode payments have been changed from 10% to 20%
darkcoinproject Jun 7, 2014
a28752a
Merge pull request #79 from darkcoinproject/patch-1
zone117x Jun 9, 2014
18c2212
fix auth parameters
bolkin Jun 15, 2014
66d4038
Added NIST5 hashing
zone117x Jun 16, 2014
f08b105
Merge pull request #86 from bolkin/master
zone117x Jun 16, 2014
d235406
Allow reward type to be configured in coin definition instead of auto…
zone117x Jun 21, 2014
d7802bc
Updated to add Scypt-og
chrisfranko Jun 21, 2014
3586ec0
Initial x15 support
zone117x Jun 27, 2014
8713a64
Support sha1coin
May 10, 2014
f822008
Merge pull request #92 from altcoins-tools/pr-add-sha1-argorithm
zone117x Aug 4, 2014
d3e2e00
Merge pull request #87 from chrisfranko/patch-1
zone117x Aug 4, 2014
af52fe3
patch-2 scrypt-og
chrisfranko Nov 14, 2014
02e78da
Merge pull request #102 from chrisfranko/patch-2
zone117x Jul 16, 2015
25f6535
Variable length integer IntBuffer fix
romanornr Nov 30, 2016
13653a3
version
romanornr Nov 30, 2016
7830585
Lyra2RE diff by 128
romanornr Dec 1, 2016
786a19b
Merge pull request #113 from romanornr/Romano
zone117x Dec 1, 2016
0cd4fcb
revert Lyra2RE
romanornr Dec 10, 2016
1b8c708
Update util.js
zone117x Dec 23, 2016
7894c47
segwit support
jonnybravo0311 Dec 11, 2016
ff92d28
segwit support
jonnybravo0311 Dec 11, 2016
f2c90d4
segwit support
jonnybravo0311 Dec 11, 2016
74b7e1f
updated buffers to Node API 8.1.3
krisklosterman Jul 8, 2017
3c4542f
pushing to test on different platoform
krisklosterman Jul 10, 2017
2ef76aa
added some loggin for debuging
krisklosterman Jul 10, 2017
3053926
testing
krisklosterman Jul 10, 2017
85fed70
testing
krisklosterman Jul 10, 2017
f5f8422
adding logging for testing
krisklosterman Jul 11, 2017
ebc30bb
removed all the testing comments
krisklosterman Jul 12, 2017
239db54
More error testing...
krisklosterman Jul 12, 2017
b3b4cd1
logging in the wrong place
krisklosterman Jul 12, 2017
4ff88f7
testing updates
krisklosterman Jul 17, 2017
8484c5a
Added debuging for failed block submits
krisklosterman Jul 19, 2017
ac43b48
Removed Logging
krisklosterman Aug 7, 2017
a01db6e
Added some more information around mining.extranounce.subscribe, test…
krisklosterman Aug 15, 2017
dcd68b3
Removed some buggy code, from last commit
krisklosterman Aug 15, 2017
bef7181
Added Scrypt Jane back in
krisklosterman Aug 16, 2017
4e60b06
Merge remote-tracking branch 'krisklosterman/master'
vagabondan Oct 2, 2017
fe48843
Update package.json
vagabondan Nov 21, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.idea/
.idea/
.vscode/
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Features
* ✓ __Quark__ (Quarkcoin [QRK])
* ✓ __X11__ (Darkcoin [DRK], Hirocoin, Limecoin)
* ✓ __X13__ (MaruCoin, BoostCoin)
* ✓ __NIST5__ (Talkcoin)
* ✓ __Keccak__ (Maxcoin [MAX], HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin)
* ✓ __Skein__ (Skeincoin [SKC])
* ✓ __Groestl__ (Groestlcoin [GRS])
Expand All @@ -53,13 +54,13 @@ May be working (needs additional testing):
* ? *Blake* (Blakecoin [BLC])
* ? *Fugue* (Fuguecoin [FC])
* ? *Qubit* (Qubitcoin [Q2C], Myriadcoin [MYR])
* ? *Hefty1* (Heavycoin [HVC])
* ? *SHAvite-3* (INKcoin [INK])
* ? *Sha1* (Sha1coin [SHA], Yaycoin [YAY])

Not working currently:
* *Groestl* - for Myriadcoin
* *Keccak* - for eCoin & Copperlark

* *Hefty1* (Heavycoin [HVC])


Requirements
Expand All @@ -83,7 +84,7 @@ npm update
Create the configuration for your coin:

Possible options for `algorithm`: *sha256, scrypt, scrypt-jane, scrypt-n, quark, x11, keccak, blake,
skein, groestl, fugue, shavite3, hefty1, or qubit*.
skein, groestl, fugue, shavite3, hefty1, qubit, or sha1*.

```javascript
var myCoin = {
Expand Down Expand Up @@ -276,7 +277,7 @@ var pool = Stratum.createPool({

}

}, function(ip, workerName, password, callback){ //stratum authorization function
}, function(ip, port , workerName, password, callback){ //stratum authorization function
console.log("Authorize " + workerName + ":" + password + "@" + ip);
callback({
error: null,
Expand Down
34 changes: 34 additions & 0 deletions lib/algoProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ var algos = module.exports = global.algos = {
}
}
},
'scrypt-og': {
//Aiden settings
//Uncomment diff if you want to use hardcoded truncated diff
//diff: '0000ffff00000000000000000000000000000000000000000000000000000000',
multiplier: Math.pow(2, 16),
hash: function(coinConfig){
var nValue = coinConfig.nValue || 64;
var rValue = coinConfig.rValue || 1;
return function(data){
return multiHashing.scrypt(data,nValue,rValue);
}
}
},
'scrypt-jane': {
multiplier: Math.pow(2, 16),
hash: function(coinConfig){
Expand Down Expand Up @@ -60,6 +73,13 @@ var algos = module.exports = global.algos = {
}
}
},
sha1: {
hash: function(){
return function(){
return multiHashing.sha1.apply(this, arguments);
}
}
},
x11: {
hash: function(){
return function(){
Expand All @@ -74,6 +94,20 @@ var algos = module.exports = global.algos = {
}
}
},
x15: {
hash: function(){
return function(){
return multiHashing.x15.apply(this, arguments);
}
}
},
nist5: {
hash: function(){
return function(){
return multiHashing.nist5.apply(this, arguments);
}
}
},
quark: {
hash: function(){
return function(){
Expand Down
17 changes: 10 additions & 7 deletions lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool

function getTransactionBuffers(txs){
var txHashes = txs.map(function(tx){
if (tx.txid !== undefined) {
return util.uint256BufferFromHash(tx.txid);
}
return util.uint256BufferFromHash(tx.hash);
});
return [null].concat(txHashes);
}

function getVoteData(){
if (!rpcData.masternode_payments) return new Buffer([]);
if (!rpcData.masternode_payments) return Buffer.from([]);

return Buffer.concat(
[util.varIntBuffer(rpcData.votes.length)].concat(
rpcData.votes.map(function (vt) {
return new Buffer(vt, 'hex');
return Buffer.from(vt, 'hex');
})
)
);
Expand All @@ -56,9 +59,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool



this.prevHashReversed = util.reverseByteOrder(new Buffer(rpcData.previousblockhash, 'hex')).toString('hex');
this.prevHashReversed = util.reverseByteOrder(Buffer.from(rpcData.previousblockhash, 'hex')).toString('hex');
this.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){
return new Buffer(tx.data, 'hex');
return Buffer.from(tx.data, 'hex');
}));
this.merkleTree = new merkleTree(getTransactionBuffers(rpcData.transactions));
this.merkleBranch = getMerkleHashes(this.merkleTree.steps);
Expand All @@ -84,7 +87,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
//https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers
this.serializeHeader = function(merkleRoot, nTime, nonce){

var header = new Buffer(80);
var header = Buffer.alloc(80);
var position = 0;
header.write(nonce, position, 4, 'hex');
header.write(rpcData.bits, position += 4, 4, 'hex');
Expand All @@ -107,7 +110,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
getVoteData(),

//POS coins require a zero byte appended to block which the daemon replaces with the signature
new Buffer(reward === 'POS' ? [0] : [])
Buffer.from(reward === 'POS' ? [0] : [])
]);
};

Expand Down Expand Up @@ -136,4 +139,4 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
}
return this.jobParams;
};
};
};
47 changes: 43 additions & 4 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var JobManager = module.exports = function JobManager(options){
//public members

this.extraNonceCounter = new ExtraNonceCounter(options.instanceId);
this.extraNoncePlaceholder = new Buffer('f000000ff111111f', 'hex');
this.extraNoncePlaceholder = Buffer.from('f000000ff111111f', 'hex');
this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size;

this.currentJob;
Expand Down Expand Up @@ -90,13 +90,20 @@ var JobManager = module.exports = function JobManager(options){
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
case 'scrypt-og':
if (options.coin.reward === 'POS') {
return function (d) {
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
case 'scrypt-jane':
if (options.coin.reward === 'POS') {
return function (d) {
return util.reverseBuffer(hashDigest.apply(this, arguments));
};
}
case 'scrypt-n':
case 'sha1':
return function (d) {
return util.reverseBuffer(util.sha256d(d));
};
Expand Down Expand Up @@ -176,6 +183,18 @@ var JobManager = module.exports = function JobManager(options){
});
return {error: error, result: null};
};
/*console.log("processShare - Stuff passed in", {
"jobId": jobId,
"previousDifficulty": previousDifficulty,
"difficulty": difficulty,
"extraNonce1": extraNonce1,
"extraNonce2": extraNonce2,
"nTime": nTime,
"nonce": nonce,
"ipAddress": ipAddress,
"port": port,
"workerName": workerName
});*/

var submitTime = Date.now() / 1000 | 0;

Expand Down Expand Up @@ -205,9 +224,8 @@ var JobManager = module.exports = function JobManager(options){
return shareError([22, 'duplicate share']);
}


var extraNonce1Buffer = new Buffer(extraNonce1, 'hex');
var extraNonce2Buffer = new Buffer(extraNonce2, 'hex');
var extraNonce1Buffer = Buffer.from(extraNonce1, 'hex');
var extraNonce2Buffer = Buffer.from(extraNonce2, 'hex');

var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
var coinbaseHash = coinbaseHasher(coinbaseBuffer);
Expand All @@ -226,10 +244,31 @@ var JobManager = module.exports = function JobManager(options){

var blockDiffAdjusted = job.difficulty * shareMultiplier;

/*console.log("processShare - Stuff calculated", {
"extraNonce1Buffer": extraNonce1Buffer,
"extraNonce2Buffer": extraNonce2Buffer,
"coinbaseBuffer": coinbaseBuffer,
"coinbaseHash": coinbaseHash,
"merkleRoot": merkleRoot,
"headerBuffer": headerBuffer,
"headerHash": headerHash,
"headerBigNum": headerBigNum,
"shareDiff": shareDiff,
"blockDiffAdjusted": blockDiffAdjusted
});*/

/*console.log("processShare - Globals", {
"job.target": job.target
});*/

//Check if share is a block candidate (matched network difficulty)
if (job.target.ge(headerBigNum)){
blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
blockHash = blockHasher(headerBuffer, nTime).toString('hex');
/*console.log("processShare - Block Candidate", {
"blockHex": blockHex,
"blockHash": blockHash
});*/
}
else {
if (options.emitInvalidBlockHashes)
Expand Down
18 changes: 9 additions & 9 deletions lib/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var util = require('./util.js');


var fixedLenStringBuffer = function(s, len) {
var buff = new Buffer(len);
var buff = Buffer.alloc(len);
buff.fill(0);
buff.write(s);
return buff;
Expand All @@ -26,7 +26,7 @@ var commandStringBuffer = function (s) {
- callback returns 1) data buffer and 2) lopped/over-read data */
var readFlowingBytes = function (stream, amount, preRead, callback) {

var buff = preRead ? preRead : new Buffer([]);
var buff = preRead ? preRead : Buffer.from([]);

var readData = function (data) {
buff = Buffer.concat([buff, data]);
Expand All @@ -39,14 +39,14 @@ var readFlowingBytes = function (stream, amount, preRead, callback) {
stream.once('data', readData);
};

readData(new Buffer([]));
readData(Buffer.from([]));
};

var Peer = module.exports = function (options) {

var _this = this;
var client;
var magic = new Buffer(options.testnet ? options.coin.peerMagicTestnet : options.coin.peerMagic, 'hex');
var magic = Buffer.from(options.testnet ? options.coin.peerMagicTestnet : options.coin.peerMagic, 'hex');
var magicInt = magic.readUInt32LE(0);
var verack = false;
var validConnectionConfig = true;
Expand All @@ -58,14 +58,14 @@ var Peer = module.exports = function (options) {
block: 2
};

var networkServices = new Buffer('0100000000000000', 'hex'); //NODE_NETWORK services (value 1 packed as uint64)
var emptyNetAddress = new Buffer('010000000000000000000000000000000000ffff000000000000', 'hex');
var networkServices = Buffer.from('0100000000000000', 'hex'); //NODE_NETWORK services (value 1 packed as uint64)
var emptyNetAddress = Buffer.from('010000000000000000000000000000000000ffff000000000000', 'hex');
var userAgent = util.varStringBuffer('/node-stratum/');
var blockStartHeight = new Buffer('00000000', 'hex'); //block start_height, can be empty
var blockStartHeight = Buffer.from('00000000', 'hex'); //block start_height, can be empty

//If protocol version is new enough, add do not relay transactions flag byte, outlined in BIP37
//https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki#extensions-to-existing-messages
var relayTransactions = options.p2p.disableTransactions === true ? new Buffer([false]) : new Buffer([]);
var relayTransactions = options.p2p.disableTransactions === true ? Buffer.from([false]) : Buffer.from([]);

var commands = {
version: commandStringBuffer('version'),
Expand Down Expand Up @@ -127,7 +127,7 @@ var Peer = module.exports = function (options) {
if (header.readUInt32LE(0) === magicInt) {
beginReadingMessage(header);
} else {
beginReadingMessage(new Buffer([]));
beginReadingMessage(Buffer.from([]));
}
return;
}
Expand Down
21 changes: 13 additions & 8 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var pool = module.exports = function pool(options, authorizeFn){
function OnBlockchainSynced(syncedCallback){

var checkSynced = function(displayNotSynced){
_this.daemon.cmd('getblocktemplate', [], function(results){
_this.daemon.cmd('getblocktemplate', [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(results){
var synced = results.every(function(r){
return !r.error || r.error.code !== -10;
});
Expand Down Expand Up @@ -231,7 +231,7 @@ var pool = module.exports = function pool(options, authorizeFn){
}
else{
rpcCommand = 'getblocktemplate';
rpcArgs = [{'mode': 'submit', 'data': blockHex}];
rpcArgs = [{'mode': 'submit', 'data': blockHex}]; // TODO: is mode submit even correct?
}


Expand Down Expand Up @@ -398,10 +398,12 @@ var pool = module.exports = function pool(options, authorizeFn){
return;
}

if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty)
options.coin.reward = 'POS';
else
options.coin.reward = 'POW';
if (!options.coin.reward) {
if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty)
options.coin.reward = 'POS';
else
options.coin.reward = 'POW';
}


/* POS coins must use the pubkey in coinbase transaction, and pubkey is
Expand Down Expand Up @@ -564,9 +566,10 @@ var pool = module.exports = function pool(options, authorizeFn){

function GetBlockTemplate(callback){
_this.daemon.cmd('getblocktemplate',
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}],
function(result){
if (result.error){
console.log("GetBlockTemplate()", result);
emitErrorLog('getblocktemplate call failed for daemon instance ' +
result.instance.index + ' with error ' + JSON.stringify(result.error));
callback(result.error);
Expand Down Expand Up @@ -625,6 +628,7 @@ var pool = module.exports = function pool(options, authorizeFn){
Object.keys(origStratumClients).forEach(function (subId) {
stratumClients.push({subId: subId, client: origStratumClients[subId]});
});
//TODO: Think of a way to use API 8's async/await and promises to replace async lib
async.filter(
stratumClients,
filterFn,
Expand All @@ -644,7 +648,8 @@ var pool = module.exports = function pool(options, authorizeFn){
);
});
}
)
);

};


Expand Down
Loading