Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit cb79b8d

Browse files
author
Mark Erhardt
authored
Merge pull request #73 from BitGo/BG-16466.remove-deprecated-bufferutils
Remove outdated and unused bufferutils
2 parents 6ec29e5 + 84851f0 commit cb79b8d

File tree

5 files changed

+17
-199
lines changed

5 files changed

+17
-199
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"coverage-report": "nyc report --reporter=lcov",
2121
"coverage-html": "nyc report --reporter=html",
22-
"coverage": "BITGO_UTXO_LIB_TEST_EXPECTED_COUNT=3535 nyc --check-coverage --branches 90 --functions 90 mocha --recursive",
22+
"coverage": "BITGO_UTXO_LIB_TEST_EXPECTED_COUNT=3436 nyc --check-coverage --branches 90 --functions 90 mocha --recursive",
2323
"integration": "mocha test/integration/",
2424
"standard": "standard",
2525
"test": "npm run standard && npm run coverage",

src/bufferutils.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
var pushdata = require('pushdata-bitcoin')
2-
var varuint = require('varuint-bitcoin')
3-
41
// https://github.com/feross/buffer/blob/master/index.js#L1127
52
function verifuint (value, max) {
63
if (typeof value !== 'number') throw new Error('cannot write a non-number as a number')
@@ -35,31 +32,8 @@ function writeUInt64LE (buffer, value, offset) {
3532
return offset + 8
3633
}
3734

38-
// TODO: remove in 4.0.0?
39-
function readVarInt (buffer, offset) {
40-
var result = varuint.decode(buffer, offset)
41-
42-
return {
43-
number: result,
44-
size: varuint.decode.bytes
45-
}
46-
}
47-
48-
// TODO: remove in 4.0.0?
49-
function writeVarInt (buffer, number, offset) {
50-
varuint.encode(number, buffer, offset)
51-
return varuint.encode.bytes
52-
}
53-
5435
module.exports = {
55-
pushDataSize: pushdata.encodingLength,
56-
readPushDataInt: pushdata.decode,
5736
readUInt64LE: readUInt64LE,
5837
readInt64LE: readInt64LE,
59-
readVarInt: readVarInt,
60-
varIntBuffer: varuint.encode,
61-
varIntSize: varuint.encodingLength,
62-
writePushDataInt: pushdata.encode,
63-
writeUInt64LE: writeUInt64LE,
64-
writeVarInt: writeVarInt
38+
writeUInt64LE: writeUInt64LE
6539
}

src/transaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ Transaction.prototype.getJoinSplitByteLength = function () {
486486
}
487487
var joinSplitsLen = this.joinsplits.length
488488
var byteLength = 0
489-
byteLength += bufferutils.varIntSize(joinSplitsLen) // vJoinSplit
489+
byteLength += varuint.encodingLength(joinSplitsLen) // vJoinSplit
490490

491491
if (joinSplitsLen > 0) {
492492
// Both pre and post Sapling JoinSplits are encoded with the following data:

test/bufferutils.js

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,6 @@ var bufferutils = require('../src/bufferutils')
66
var fixtures = require('./fixtures/bufferutils.json')
77

88
describe('bufferutils', function () {
9-
describe('pushDataSize', function () {
10-
fixtures.valid.forEach(function (f) {
11-
it('determines the pushDataSize of ' + f.dec + ' correctly', function () {
12-
if (!f.hexPD) return
13-
14-
var size = bufferutils.pushDataSize(f.dec)
15-
16-
assert.strictEqual(size, f.hexPD.length / 2)
17-
})
18-
})
19-
})
20-
21-
describe('readPushDataInt', function () {
22-
fixtures.valid.forEach(function (f) {
23-
if (!f.hexPD) return
24-
25-
it('decodes ' + f.hexPD + ' correctly', function () {
26-
var buffer = Buffer.from(f.hexPD, 'hex')
27-
var d = bufferutils.readPushDataInt(buffer, 0)
28-
var fopcode = parseInt(f.hexPD.substr(0, 2), 16)
29-
30-
assert.strictEqual(d.opcode, fopcode)
31-
assert.strictEqual(d.number, f.dec)
32-
assert.strictEqual(d.size, buffer.length)
33-
})
34-
})
35-
36-
fixtures.invalid.readPushDataInt.forEach(function (f) {
37-
if (!f.hexPD) return
38-
39-
it('decodes ' + f.hexPD + ' as null', function () {
40-
var buffer = Buffer.from(f.hexPD, 'hex')
41-
42-
var n = bufferutils.readPushDataInt(buffer, 0)
43-
assert.strictEqual(n, null)
44-
})
45-
})
46-
})
47-
489
describe('readInt64LE', function () {
4910
fixtures.negative.forEach(function (f) {
5011
it('decodes ' + f.hex64 + ' correctly', function () {
@@ -77,61 +38,6 @@ describe('bufferutils', function () {
7738
})
7839
})
7940

80-
describe('readVarInt', function () {
81-
fixtures.valid.forEach(function (f) {
82-
it('decodes ' + f.hexVI + ' correctly', function () {
83-
var buffer = Buffer.from(f.hexVI, 'hex')
84-
var d = bufferutils.readVarInt(buffer, 0)
85-
86-
assert.strictEqual(d.number, f.dec)
87-
assert.strictEqual(d.size, buffer.length)
88-
})
89-
})
90-
91-
fixtures.invalid.readUInt64LE.forEach(function (f) {
92-
it('throws on ' + f.description, function () {
93-
var buffer = Buffer.from(f.hexVI, 'hex')
94-
95-
assert.throws(function () {
96-
bufferutils.readVarInt(buffer, 0)
97-
}, new RegExp(f.exception))
98-
})
99-
})
100-
})
101-
102-
describe('varIntBuffer', function () {
103-
fixtures.valid.forEach(function (f) {
104-
it('encodes ' + f.dec + ' correctly', function () {
105-
var buffer = bufferutils.varIntBuffer(f.dec)
106-
107-
assert.strictEqual(buffer.toString('hex'), f.hexVI)
108-
})
109-
})
110-
})
111-
112-
describe('varIntSize', function () {
113-
fixtures.valid.forEach(function (f) {
114-
it('determines the varIntSize of ' + f.dec + ' correctly', function () {
115-
var size = bufferutils.varIntSize(f.dec)
116-
117-
assert.strictEqual(size, f.hexVI.length / 2)
118-
})
119-
})
120-
})
121-
122-
describe('writePushDataInt', function () {
123-
fixtures.valid.forEach(function (f) {
124-
if (!f.hexPD) return
125-
126-
it('encodes ' + f.dec + ' correctly', function () {
127-
var buffer = Buffer.alloc(5, 0)
128-
129-
var n = bufferutils.writePushDataInt(buffer, f.dec, 0)
130-
assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexPD)
131-
})
132-
})
133-
})
134-
13541
describe('writeUInt64LE', function () {
13642
fixtures.valid.forEach(function (f) {
13743
it('encodes ' + f.dec + ' correctly', function () {
@@ -152,25 +58,4 @@ describe('bufferutils', function () {
15258
})
15359
})
15460
})
155-
156-
describe('writeVarInt', function () {
157-
fixtures.valid.forEach(function (f) {
158-
it('encodes ' + f.dec + ' correctly', function () {
159-
var buffer = Buffer.alloc(9, 0)
160-
161-
var n = bufferutils.writeVarInt(buffer, f.dec, 0)
162-
assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexVI)
163-
})
164-
})
165-
166-
fixtures.invalid.readUInt64LE.forEach(function (f) {
167-
it('throws on ' + f.description, function () {
168-
var buffer = Buffer.alloc(9, 0)
169-
170-
assert.throws(function () {
171-
bufferutils.writeVarInt(buffer, f.dec, 0)
172-
}, new RegExp(f.exception))
173-
})
174-
})
175-
})
17661
})

test/fixtures/bufferutils.json

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,59 @@
22
"valid": [
33
{
44
"dec": 0,
5-
"hex64": "0000000000000000",
6-
"hexVI": "00",
7-
"hexPD": "00"
5+
"hex64": "0000000000000000"
86
},
97
{
108
"dec": 1,
11-
"hex64": "0100000000000000",
12-
"hexVI": "01",
13-
"hexPD": "01"
9+
"hex64": "0100000000000000"
1410
},
1511
{
1612
"dec": 252,
17-
"hex64": "fc00000000000000",
18-
"hexVI": "fc",
19-
"hexPD": "4cfc"
13+
"hex64": "fc00000000000000"
2014
},
2115
{
2216
"dec": 253,
23-
"hex64": "fd00000000000000",
24-
"hexVI": "fdfd00",
25-
"hexPD": "4cfd"
17+
"hex64": "fd00000000000000"
2618
},
2719
{
2820
"dec": 254,
29-
"hex64": "fe00000000000000",
30-
"hexVI": "fdfe00",
31-
"hexPD": "4cfe"
21+
"hex64": "fe00000000000000"
3222
},
3323
{
3424
"dec": 255,
35-
"hex64": "ff00000000000000",
36-
"hexVI": "fdff00",
37-
"hexPD": "4cff"
25+
"hex64": "ff00000000000000"
3826
},
3927
{
4028
"dec": 65534,
41-
"hex64": "feff000000000000",
42-
"hexVI": "fdfeff",
43-
"hexPD": "4dfeff"
29+
"hex64": "feff000000000000"
4430
},
4531
{
4632
"dec": 65535,
47-
"hex64": "ffff000000000000",
48-
"hexVI": "fdffff",
49-
"hexPD": "4dffff"
33+
"hex64": "ffff000000000000"
5034
},
5135
{
5236
"dec": 65536,
53-
"hex64": "0000010000000000",
54-
"hexVI": "fe00000100",
55-
"hexPD": "4e00000100"
37+
"hex64": "0000010000000000"
5638
},
5739
{
5840
"dec": 65537,
59-
"hex64": "0100010000000000",
60-
"hexVI": "fe01000100",
61-
"hexPD": "4e01000100"
41+
"hex64": "0100010000000000"
6242
},
6343
{
6444
"dec": 4294967295,
65-
"hex64": "ffffffff00000000",
66-
"hexVI": "feffffffff",
67-
"hexPD": "4effffffff"
45+
"hex64": "ffffffff00000000"
6846
},
6947
{
7048
"dec": 4294967296,
71-
"hex64": "0000000001000000",
72-
"hexVI": "ff0000000001000000"
49+
"hex64": "0000000001000000"
7350
},
7451
{
7552
"dec": 4294967297,
76-
"hex64": "0100000001000000",
77-
"hexVI": "ff0100000001000000"
53+
"hex64": "0100000001000000"
7854
},
7955
{
8056
"dec": 9007199254740991,
81-
"hex64": "ffffffffffff1f00",
82-
"hexVI": "ffffffffffffff1f00"
57+
"hex64": "ffffffffffff1f00"
8358
}
8459
],
8560
"invalid": {
@@ -88,30 +63,14 @@
8863
"description": "n === 2^53",
8964
"exception": "RangeError: value out of range",
9065
"hex64": "0000000000002000",
91-
"hexVI": "ff0000000000000020",
9266
"dec": 9007199254740992
9367
},
9468
{
9569
"description": "n > 2^53",
9670
"exception": "RangeError: value out of range",
9771
"hex64": "0100000000002000",
98-
"hexVI": "ff0100000000000020",
9972
"dec": 9007199254740993
10073
}
101-
],
102-
"readPushDataInt": [
103-
{
104-
"description": "OP_PUSHDATA1, no size",
105-
"hexPD": "4c"
106-
},
107-
{
108-
"description": "OP_PUSHDATA2, no size",
109-
"hexPD": "4d"
110-
},
111-
{
112-
"description": "OP_PUSHDATA4, no size",
113-
"hexPD": "4e"
114-
}
11574
]
11675
},
11776
"negative": [

0 commit comments

Comments
 (0)