use buffer-reverse
This commit is contained in:
parent
28372f0cd7
commit
731a31ecba
9 changed files with 17 additions and 30 deletions
|
@ -63,6 +63,7 @@
|
||||||
"bip66": "^1.1.0",
|
"bip66": "^1.1.0",
|
||||||
"bs58check": "^1.0.5",
|
"bs58check": "^1.0.5",
|
||||||
"buffer-equals": "^1.0.3",
|
"buffer-equals": "^1.0.3",
|
||||||
|
"buffer-reverse": "^1.0.0",
|
||||||
"create-hash": "^1.1.0",
|
"create-hash": "^1.1.0",
|
||||||
"create-hmac": "^1.1.3",
|
"create-hmac": "^1.1.3",
|
||||||
"ecurve": "^1.0.0",
|
"ecurve": "^1.0.0",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
var bufferutils = require('./bufferutils')
|
var bufferutils = require('./bufferutils')
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
|
|
||||||
var Transaction = require('./transaction')
|
var Transaction = require('./transaction')
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ Block.prototype.getHash = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.getId = function () {
|
Block.prototype.getId = function () {
|
||||||
return bufferutils.reverse(this.getHash()).toString('hex')
|
return bufferReverse(this.getHash()).toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.getUTCDate = function () {
|
Block.prototype.getUTCDate = function () {
|
||||||
|
|
|
@ -167,19 +167,13 @@ function varIntBuffer (i) {
|
||||||
return buffer
|
return buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
function reverse (buffer) {
|
|
||||||
var buffer2 = new Buffer(buffer)
|
|
||||||
Array.prototype.reverse.call(buffer2)
|
|
||||||
return buffer2
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
equal: require('buffer-equals'),
|
equal: require('buffer-equals'),
|
||||||
pushDataSize: pushDataSize,
|
pushDataSize: pushDataSize,
|
||||||
readPushDataInt: readPushDataInt,
|
readPushDataInt: readPushDataInt,
|
||||||
readUInt64LE: readUInt64LE,
|
readUInt64LE: readUInt64LE,
|
||||||
readVarInt: readVarInt,
|
readVarInt: readVarInt,
|
||||||
reverse: reverse,
|
reverse: require('buffer-reverse'),
|
||||||
varIntBuffer: varIntBuffer,
|
varIntBuffer: varIntBuffer,
|
||||||
varIntSize: varIntSize,
|
varIntSize: varIntSize,
|
||||||
writePushDataInt: writePushDataInt,
|
writePushDataInt: writePushDataInt,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
var bufferutils = require('./bufferutils')
|
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
var opcodes = require('./opcodes')
|
|
||||||
var bscript = require('./script')
|
var bscript = require('./script')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
|
var bufferutils = require('./bufferutils')
|
||||||
|
var opcodes = require('./opcodes')
|
||||||
var typeforce = require('typeforce')
|
var typeforce = require('typeforce')
|
||||||
var types = require('./types')
|
var types = require('./types')
|
||||||
|
|
||||||
|
@ -247,7 +248,7 @@ Transaction.prototype.getHash = function () {
|
||||||
|
|
||||||
Transaction.prototype.getId = function () {
|
Transaction.prototype.getId = function () {
|
||||||
// transaction hash's are displayed in reverse order
|
// transaction hash's are displayed in reverse order
|
||||||
return bufferutils.reverse(this.getHash()).toString('hex')
|
return bufferReverse(this.getHash()).toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.toBuffer = function () {
|
Transaction.prototype.toBuffer = function () {
|
||||||
|
|
|
@ -2,6 +2,7 @@ var baddress = require('./address')
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
var bscript = require('./script')
|
var bscript = require('./script')
|
||||||
var bufferEquals = require('buffer-equals')
|
var bufferEquals = require('buffer-equals')
|
||||||
|
var bufferReverse = require('buffer-reverse/inplace')
|
||||||
var networks = require('./networks')
|
var networks = require('./networks')
|
||||||
var ops = require('./opcodes')
|
var ops = require('./opcodes')
|
||||||
|
|
||||||
|
@ -173,7 +174,7 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
|
||||||
if (typeof txHash === 'string') {
|
if (typeof txHash === 'string') {
|
||||||
// transaction hashs's are displayed in reverse order, un-reverse it
|
// transaction hashs's are displayed in reverse order, un-reverse it
|
||||||
txHash = new Buffer(txHash, 'hex')
|
txHash = new Buffer(txHash, 'hex')
|
||||||
Array.prototype.reverse.call(txHash)
|
bufferReverse(txHash)
|
||||||
|
|
||||||
// is it a Transaction object?
|
// is it a Transaction object?
|
||||||
} else if (txHash instanceof Transaction) {
|
} else if (txHash instanceof Transaction) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var base58 = require('bs58')
|
var base58 = require('bs58')
|
||||||
var bitcoin = require('../')
|
var bitcoin = require('../')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
|
|
||||||
var base58_encode_decode = require('./fixtures/core/base58_encode_decode.json')
|
var base58_encode_decode = require('./fixtures/core/base58_encode_decode.json')
|
||||||
var base58_keys_invalid = require('./fixtures/core/base58_keys_invalid.json')
|
var base58_keys_invalid = require('./fixtures/core/base58_keys_invalid.json')
|
||||||
|
@ -150,7 +151,7 @@ describe('Bitcoin-core', function () {
|
||||||
var input = inputs[i]
|
var input = inputs[i]
|
||||||
|
|
||||||
// reverse because test data is reversed
|
// reverse because test data is reversed
|
||||||
var prevOutHash = bitcoin.bufferutils.reverse(new Buffer(input[0], 'hex'))
|
var prevOutHash = bufferReverse(new Buffer(input[0], 'hex'))
|
||||||
var prevOutIndex = input[1]
|
var prevOutIndex = input[1]
|
||||||
|
|
||||||
assert.deepEqual(txIn.hash, prevOutHash)
|
assert.deepEqual(txIn.hash, prevOutHash)
|
||||||
|
@ -203,7 +204,7 @@ describe('Bitcoin-core', function () {
|
||||||
var hashType = f[3]
|
var hashType = f[3]
|
||||||
|
|
||||||
// reverse because test data is reversed
|
// reverse because test data is reversed
|
||||||
var expectedHash = bitcoin.bufferutils.reverse(new Buffer(f[4], 'hex'))
|
var expectedHash = bufferReverse(new Buffer(f[4], 'hex'))
|
||||||
|
|
||||||
var hashTypes = []
|
var hashTypes = []
|
||||||
if ((hashType & 0x1f) === bitcoin.Transaction.SIGHASH_NONE) hashTypes.push('SIGHASH_NONE')
|
if ((hashType & 0x1f) === bitcoin.Transaction.SIGHASH_NONE) hashTypes.push('SIGHASH_NONE')
|
||||||
|
|
|
@ -88,19 +88,6 @@ describe('bufferutils', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('reverse', function () {
|
|
||||||
fixtures.valid.forEach(function (f) {
|
|
||||||
it('reverses ' + f.hex64 + ' correctly', function () {
|
|
||||||
var buffer = new Buffer(f.hex64, 'hex')
|
|
||||||
var buffer2 = bufferutils.reverse(buffer)
|
|
||||||
|
|
||||||
Array.prototype.reverse.call(buffer)
|
|
||||||
|
|
||||||
assert.deepEqual(buffer, buffer2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('varIntBuffer', function () {
|
describe('varIntBuffer', function () {
|
||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
it('encodes ' + f.dec + ' correctly', function () {
|
it('encodes ' + f.dec + ' correctly', function () {
|
||||||
|
|
|
@ -5,6 +5,7 @@ var async = require('async')
|
||||||
var bigi = require('bigi')
|
var bigi = require('bigi')
|
||||||
var bitcoin = require('../../')
|
var bitcoin = require('../../')
|
||||||
var blockchain = require('./_blockchain')
|
var blockchain = require('./_blockchain')
|
||||||
|
var bufferReverse = require('buffer-reverse')
|
||||||
var crypto = require('crypto')
|
var crypto = require('crypto')
|
||||||
|
|
||||||
var ecurve = require('ecurve')
|
var ecurve = require('ecurve')
|
||||||
|
@ -134,7 +135,7 @@ describe('bitcoinjs-lib (crypto)', function () {
|
||||||
|
|
||||||
assert(bitcoin.script.isPubKeyHashInput(scriptChunks), 'Expected pubKeyHash script')
|
assert(bitcoin.script.isPubKeyHashInput(scriptChunks), 'Expected pubKeyHash script')
|
||||||
|
|
||||||
var prevOutTxId = bitcoin.bufferutils.reverse(transaction.ins[input.vout].hash).toString('hex')
|
var prevOutTxId = bufferReverse(transaction.ins[input.vout].hash).toString('hex')
|
||||||
var prevVout = transaction.ins[input.vout].index
|
var prevVout = transaction.ins[input.vout].index
|
||||||
|
|
||||||
tasks.push(function (callback) {
|
tasks.push(function (callback) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var baddress = require('../src/address')
|
var baddress = require('../src/address')
|
||||||
var bscript = require('../src/script')
|
var bscript = require('../src/script')
|
||||||
var bufferutils = require('../src/bufferutils')
|
var bufferReverse = require('buffer-reverse')
|
||||||
var ops = require('../src/opcodes')
|
var ops = require('../src/opcodes')
|
||||||
|
|
||||||
var BigInteger = require('bigi')
|
var BigInteger = require('bigi')
|
||||||
|
@ -92,7 +92,7 @@ describe('TransactionBuilder', function () {
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
|
|
||||||
f.inputs.forEach(function (input) {
|
f.inputs.forEach(function (input) {
|
||||||
var txHash = bufferutils.reverse(new Buffer(input.txId, 'hex'))
|
var txHash = bufferReverse(new Buffer(input.txId, 'hex'))
|
||||||
|
|
||||||
tx.addInput(txHash, input.vout, undefined, bscript.fromASM(input.scriptSig))
|
tx.addInput(txHash, input.vout, undefined, bscript.fromASM(input.scriptSig))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue