Browse Source

some changes

master
mortie 5 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

@@ -111,6 +111,7 @@ class CPUMiner {
}

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

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

@@ -12,7 +12,7 @@ coinb2 = Buffer.from(coinb2, "hex");
exnounce1 = Buffer.from(exnounce1, "hex");
exnounce2 = Buffer.from(exnounce2, "hex");

difficulty = 3;
difficulty = 5;

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

+ 14
- 5
js/rpcconn.js View File

@@ -17,7 +17,13 @@ class RPCConn {
});

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) {
var listeners = this._listeners[obj.method];
@@ -37,14 +43,17 @@ class RPCConn {
cb(obj.error, obj.result);
}

//Digest JSON lines as they come, but only if they're a whole line
var currdata = "";
this.sock.on("data", d => {
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

@@ -15,7 +15,7 @@ class StratumClient {
}

async startWork() {
this.log("Starting work");
this.log("Starting work", this.work.id);
var res;
try {
res = await this.miner.startWork(this.work);
@@ -51,6 +51,7 @@ class StratumClient {
});

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

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

writePayload() {

+ 0
- 1
package-lock.json View File

@@ -2,7 +2,6 @@
"name": "stratum-test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"bindings": {
"version": "1.3.0",

Loading…
Cancel
Save