1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- var cryptutil = require("../cryptutil");
-
- var {
- coinb1, coinb2, merkleBranch,
- difficulty, exnounce1, exnounce2, iters
- } = JSON.parse(process.argv[2]);
-
- var start = exnounce2.toString("hex");
-
- coinb1 = Buffer.from(coinb1, "hex");
- coinb2 = Buffer.from(coinb2, "hex");
- exnounce1 = Buffer.from(exnounce1, "hex");
- exnounce2 = Buffer.from(exnounce2, "hex");
-
-
- //stratnum difficulty = nbits "encoded current network difficulty"
- difficulty = 5;
-
- var hashes = 0;
- var sd = new Date().getTime();
- for (var i = 0; i < iters; ++i) {
- var coinbase =
- cryptutil.createCoinbase(exnounce1, exnounce2, coinb1, coinb2);
- var cbHash = cryptutil.createCbHash(coinbase);
-
- //build merkle root
- //create block header
-
-
- //check block header starts with 0000
- var success = true;
- for (var i = 0; i < difficulty; ++i) {
- if (cbHash[i] !== 0) {
- success = false;
- break;
- }
- }
-
- hashes += 1;
- var d = new Date().getTime();
- if (d - 2000 >= sd) {
- console.log("h"+Math.floor(hashes / 2));
-
- sd = d;
- hashes = 0;
- }
-
- if (success) {
- console.log("o"+cbHash.toString("hex"));
- //send hash back to server
- process.exit(0);
- }
-
- cryptutil.incbufBE(exnounce2);
- if (exnounce2[0] == 255) {
- console.error("exnounce2[0] reached 255");
- process.exit(1);
- }
- }
-
- console.error("iterated through "+iters);
- process.exit(1);
|