Skip to content

Commit 8939326

Browse files
authored
Merge pull request bitcoinjs#956 from bitcoinjs/bip34
add example for BIP34 block height decoding
2 parents 84aefc3 + d5a2a68 commit 8939326

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/integration/blocks.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* global describe, it */
2+
3+
var assert = require('assert')
4+
var bitcoin = require('../../')
5+
6+
describe('bitcoinjs-lib (blocks)', function () {
7+
it('can extract a height from a CoinBase transaction', function () {
8+
// from 00000000000000000097669cdca131f24d40c4cc7d80eaa65967a2d09acf6ce6
9+
let txHex = '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff50037f9a07174d696e656420627920416e74506f6f6c685b205a2b1f7bfabe6d6d36afe1910eca9405b66f97750940a656e38e2c0312958190ff8e98fd16761d220400000000000000aa340000d49f0000ffffffff02b07fc366000000001976a9148349212dc27ce3ab4c5b29b85c4dec643d764b1788ac0000000000000000266a24aa21a9ed72d9432948505e3d3062f1307a3f027a5dea846ff85e47159680919c12bf1e400120000000000000000000000000000000000000000000000000000000000000000000000000'
10+
let tx = bitcoin.Transaction.fromHex(txHex)
11+
12+
assert.strictEqual(tx.ins.length, 1)
13+
let script = tx.ins[0].script
14+
// bitcoin.script.decompile(script) // returns [] :(
15+
16+
assert.strictEqual(script[0], 0x03)
17+
let heightBuffer = script.slice(1, 4)
18+
let height = bitcoin.script.number.decode(heightBuffer)
19+
assert.strictEqual(height, 498303)
20+
})
21+
})

0 commit comments

Comments
 (0)