bufferutils: add Buffer reverse

This commit is contained in:
Daniel Cousens 2014-08-17 17:24:48 +10:00
parent 33955a7fb5
commit 71d4c78b88
4 changed files with 25 additions and 13 deletions

View file

@ -37,10 +37,8 @@ Transaction.prototype.addInput = function(tx, index, sequence) {
var hash
if (typeof tx === 'string') {
hash = new Buffer(tx, 'hex')
// TxId hex is big-endian, we need little-endian
Array.prototype.reverse.call(hash)
hash = bufferutils.reverse(new Buffer(tx, 'hex'))
} else if (tx instanceof Transaction) {
hash = tx.getHash()
@ -211,12 +209,8 @@ Transaction.prototype.getHash = function () {
}
Transaction.prototype.getId = function () {
var buffer = this.getHash()
// Big-endian is used for TxHash
Array.prototype.reverse.call(buffer)
return buffer.toString('hex')
// TxHash is little-endian, we need big-endian
return bufferutils.reverse(this.getHash()).toString('hex')
}
Transaction.prototype.clone = function () {