An old btc miner project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mining-process.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var cryptutil = require("../cryptutil");
  2. var {
  3. coinb1, coinb2, merkleBranch,
  4. difficulty, exnounce1, exnounce2, iters
  5. } = JSON.parse(process.argv[2]);
  6. var start = exnounce2.toString("hex");
  7. coinb1 = Buffer.from(coinb1, "hex");
  8. coinb2 = Buffer.from(coinb2, "hex");
  9. exnounce1 = Buffer.from(exnounce1, "hex");
  10. exnounce2 = Buffer.from(exnounce2, "hex");
  11. difficulty = 5;
  12. var hashes = 0;
  13. var sd = new Date().getTime();
  14. for (var i = 0; i < iters; ++i) {
  15. var coinbase =
  16. cryptutil.createCoinbase(exnounce1, exnounce2, coinb1, coinb2);
  17. var cbHash = cryptutil.createCbHash(coinbase);
  18. var success = true;
  19. for (var i = 0; i < difficulty; ++i) {
  20. if (cbHash[i] !== 0) {
  21. success = false;
  22. break;
  23. }
  24. }
  25. hashes += 1;
  26. var d = new Date().getTime();
  27. if (d - 2000 >= sd) {
  28. console.log("h"+Math.floor(hashes / 2));
  29. sd = d;
  30. hashes = 0;
  31. }
  32. if (success) {
  33. console.log("o"+cbHash.toString("hex"));
  34. process.exit(0);
  35. }
  36. cryptutil.incbufBE(exnounce2);
  37. if (exnounce2[0] == 255) {
  38. console.error("exnounce2[0] reached 255");
  39. process.exit(1);
  40. }
  41. }
  42. console.error("iterated through "+iters);
  43. process.exit(1);