From 7c0e02ad488fa826cbfb69d0508aab0e427ce346 Mon Sep 17 00:00:00 2001 From: junderw Date: Wed, 12 Dec 2018 21:07:16 +0900 Subject: [PATCH] Fix Block to allow regtest target (easiest possible target) --- src/block.js | 2 +- test/fixtures/block.json | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/block.js b/src/block.js index 8c7f3a6..eb7f708 100644 --- a/src/block.js +++ b/src/block.js @@ -145,7 +145,7 @@ Block.calculateTarget = function (bits) { const exponent = ((bits & 0xff000000) >> 24) - 3 const mantissa = bits & 0x007fffff const target = Buffer.alloc(32, 0) - target.writeUInt32BE(mantissa, 28 - exponent) + target.writeUIntBE(mantissa, 29 - exponent, 3) return target } diff --git a/test/fixtures/block.json b/test/fixtures/block.json index c7aa5f7..b4a1cfe 100644 --- a/test/fixtures/block.json +++ b/test/fixtures/block.json @@ -19,6 +19,10 @@ { "bits": "cffca00", "expected": "00000000000000000000000000000000000000007fca00000000000000000000" + }, + { + "bits": "207fffff", + "expected": "7fffff0000000000000000000000000000000000000000000000000000000000" } ], "valid": [