Transaction: add hash as addInput parameter
This commit is contained in:
parent
0b17c2bc3d
commit
1b1b550bd6
2 changed files with 18 additions and 13 deletions
|
@ -39,15 +39,17 @@ Transaction.prototype.addInput = function(tx, index, sequence) {
|
|||
|
||||
if (typeof tx === 'string') {
|
||||
hash = new Buffer(tx, 'hex')
|
||||
assert.equal(hash.length, 32, 'Expected Transaction or string, got ' + tx)
|
||||
assert.equal(hash.length, 32, 'Expected Transaction, txId or txHash, got ' + tx)
|
||||
|
||||
// TxHash hex is big-endian, we need little-endian
|
||||
// TxId hex is big-endian, we need little-endian
|
||||
Array.prototype.reverse.call(hash)
|
||||
|
||||
} else {
|
||||
assert(tx instanceof Transaction, 'Expected Transaction or string, got ' + tx)
|
||||
hash = crypto.hash256(tx.toBuffer())
|
||||
} else if (tx instanceof Transaction) {
|
||||
hash = tx.getHash()
|
||||
|
||||
} else {
|
||||
assert(Buffer.isBuffer(tx), 'Expected Transaction, txId or txHash, got ' + tx)
|
||||
hash = tx
|
||||
}
|
||||
|
||||
assert.equal(typeof index, 'number', 'Expected number index, got ' + index)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue