Skip to content

Commit 2823cd6

Browse files
authored
Merge pull request bitcoinjs#1285 from bitcoinjs/fixBlock
Fix Block to allow regtest target (easiest possible target)
2 parents f57a734 + 7c0e02a commit 2823cd6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Block.calculateTarget = function (bits) {
145145
const exponent = ((bits & 0xff000000) >> 24) - 3
146146
const mantissa = bits & 0x007fffff
147147
const target = Buffer.alloc(32, 0)
148-
target.writeUInt32BE(mantissa, 28 - exponent)
148+
target.writeUIntBE(mantissa, 29 - exponent, 3)
149149
return target
150150
}
151151

test/fixtures/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
{
2020
"bits": "cffca00",
2121
"expected": "00000000000000000000000000000000000000007fca00000000000000000000"
22+
},
23+
{
24+
"bits": "207fffff",
25+
"expected": "7fffff0000000000000000000000000000000000000000000000000000000000"
2226
}
2327
],
2428
"valid": [

0 commit comments

Comments
 (0)