Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bufferutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,18 @@ function writeVarInt(buffer, number, offset) {
return size
}

function reverse(buffer) {
var buffer2 = new Buffer(buffer)
Array.prototype.reverse.call(buffer2)
return buffer2
}

module.exports = {
pushDataSize: pushDataSize,
readPushDataInt: readPushDataInt,
readUInt64LE: readUInt64LE,
readVarInt: readVarInt,
reverse: reverse,
varIntSize: varIntSize,
writePushDataInt: writePushDataInt,
writeUInt64LE: writeUInt64LE,
Expand Down
12 changes: 3 additions & 9 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 () {
Expand Down
Loading