Transaction: re-adds getHash as a pure hash
This commit is contained in:
parent
6c9f95c253
commit
0b17c2bc3d
2 changed files with 17 additions and 4 deletions
|
@ -193,8 +193,12 @@ Transaction.prototype.hashForSignature = function(prevOutScript, inIndex, hashTy
|
||||||
return crypto.hash256(buffer)
|
return crypto.hash256(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transaction.prototype.getHash = function () {
|
||||||
|
return crypto.hash256(this.toBuffer())
|
||||||
|
}
|
||||||
|
|
||||||
Transaction.prototype.getId = function () {
|
Transaction.prototype.getId = function () {
|
||||||
var buffer = crypto.hash256(this.toBuffer())
|
var buffer = this.getHash()
|
||||||
|
|
||||||
// Big-endian is used for TxHash
|
// Big-endian is used for TxHash
|
||||||
Array.prototype.reverse.call(buffer)
|
Array.prototype.reverse.call(buffer)
|
||||||
|
|
|
@ -56,12 +56,10 @@ describe('Transaction', function() {
|
||||||
// Probably a bit representative of the API
|
// Probably a bit representative of the API
|
||||||
var prevTxHash, prevTxId, prevTx
|
var prevTxHash, prevTxId, prevTx
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
var crypto = require('../src/crypto')
|
|
||||||
|
|
||||||
var f = fixtures.valid[0]
|
var f = fixtures.valid[0]
|
||||||
prevTx = Transaction.fromHex(f.hex)
|
prevTx = Transaction.fromHex(f.hex)
|
||||||
|
prevTxHash = prevTx.getHash()
|
||||||
prevTxId = prevTx.getId()
|
prevTxId = prevTx.getId()
|
||||||
prevTxHash = crypto.hash256(prevTx.toBuffer())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('accepts a transaction id', function() {
|
it('accepts a transaction id', function() {
|
||||||
|
@ -195,6 +193,17 @@ describe('Transaction', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('getHash', function() {
|
||||||
|
fixtures.valid.forEach(function(f) {
|
||||||
|
it('should return the hash for ' + f.txid, function() {
|
||||||
|
var tx = Transaction.fromHex(f.hex)
|
||||||
|
var actual = tx.getHash().toString('hex')
|
||||||
|
|
||||||
|
assert.equal(actual, f.hash)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// hashForSignature: [Function],
|
// hashForSignature: [Function],
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue