Browse Source

some changes

master
mortie 6 years ago
parent
commit
c776df39c7
5 changed files with 19 additions and 9 deletions
  1. 1
    0
      js/miner-cpu/index.js
  2. 1
    1
      js/miner-cpu/mining-process.js
  3. 14
    5
      js/rpcconn.js
  4. 3
    2
      js/stratum-client.js
  5. 0
    1
      package-lock.json

+ 1
- 0
js/miner-cpu/index.js View File

} }


async startWork(work) { async startWork(work) {
console.log("Starting work", work.id);
if (this.exnounce1 == null) { if (this.exnounce1 == null) {
console.log("Ignoring work because extranounce is null."); console.log("Ignoring work because extranounce is null.");
return false; return false;

+ 1
- 1
js/miner-cpu/mining-process.js View File

exnounce1 = Buffer.from(exnounce1, "hex"); exnounce1 = Buffer.from(exnounce1, "hex");
exnounce2 = Buffer.from(exnounce2, "hex"); exnounce2 = Buffer.from(exnounce2, "hex");


difficulty = 3;
difficulty = 5;


var hashes = 0; var hashes = 0;
var sd = new Date().getTime(); var sd = new Date().getTime();

+ 14
- 5
js/rpcconn.js View File

}); });


var onjson = json => { var onjson = json => {
var obj = JSON.parse(json);
var obj;
try {
obj = JSON.parse(json);
} catch (err) {
console.log("Failed to parse JSON: '"+json+"'");
throw err;
}


if (obj.id == null) { if (obj.id == null) {
var listeners = this._listeners[obj.method]; var listeners = this._listeners[obj.method];
cb(obj.error, obj.result); cb(obj.error, obj.result);
} }


//Digest JSON lines as they come, but only if they're a whole line
var currdata = ""; var currdata = "";
this.sock.on("data", d => { this.sock.on("data", d => {
var s = d.toString(); var s = d.toString();
currdata += d;
if (s.indexOf("\n") !== -1) {
currdata.split("\n").filter(l => l !== "").forEach(onjson);
currdata = "";
currdata += s;
var arr = s.split("\n");
while (arr[1] != null) {
onjson(arr.shift());
arr.shift();
} }
currdata = arr[0] || "";
}); });
} }



+ 3
- 2
js/stratum-client.js View File

} }


async startWork() { async startWork() {
this.log("Starting work");
this.log("Starting work", this.work.id);
var res; var res;
try { try {
res = await this.miner.startWork(this.work); res = await this.miner.startWork(this.work);
}); });


var sub = await this.rpc.call("mining.subscribe"); var sub = await this.rpc.call("mining.subscribe");
this.log("Got nounce", sub[1]);
this.miner.setNounce(sub[1], sub[2]); this.miner.setNounce(sub[1], sub[2]);
if (--this.waitFor == 0) if (--this.waitFor == 0)
this.startWork(); this.startWork();
if (!success) if (!success)
throw new Error("Incorrect username/password."); throw new Error("Incorrect username/password.");


console.log("Authenticated "+user+".");
this.log("Authenticated "+user+".");
} }


writePayload() { writePayload() {

+ 0
- 1
package-lock.json View File

"name": "stratum-test", "name": "stratum-test",
"version": "1.0.0", "version": "1.0.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true,
"dependencies": { "dependencies": {
"bindings": { "bindings": {
"version": "1.3.0", "version": "1.3.0",

Loading…
Cancel
Save