TxBuilder: simplify addInput
This commit is contained in:
parent
7f3b4c93ba
commit
4668cb1f95
1 changed files with 12 additions and 19 deletions
|
@ -121,24 +121,17 @@ TransactionBuilder.fromTransaction = function (transaction) {
|
||||||
return txb
|
return txb
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionBuilder.prototype.addInput = function (prevTx, index, sequence, prevOutScript) {
|
TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOutScript) {
|
||||||
var prevOutHash
|
// is it a txId?
|
||||||
|
if (typeof txHash === 'string') {
|
||||||
|
// a txId is big-endian hex, we want a little-endian Buffer
|
||||||
|
txHash = new Buffer(txHash, 'hex')
|
||||||
|
Array.prototype.reverse.call(txHash)
|
||||||
|
|
||||||
// txId
|
// is it a Transaction?
|
||||||
if (typeof prevTx === 'string') {
|
} else if (txHash instanceof Transaction) {
|
||||||
prevOutHash = new Buffer(prevTx, 'hex')
|
prevOutScript = txHash.outs[vout].script
|
||||||
|
txHash = txHash.getHash()
|
||||||
// TxId hex is big-endian, we want little-endian hash
|
|
||||||
Array.prototype.reverse.call(prevOutHash)
|
|
||||||
|
|
||||||
// Transaction
|
|
||||||
} else if (prevTx instanceof Transaction) {
|
|
||||||
prevOutHash = prevTx.getHash()
|
|
||||||
prevOutScript = prevTx.outs[index].script
|
|
||||||
|
|
||||||
// txHash
|
|
||||||
} else {
|
|
||||||
prevOutHash = prevTx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var input = {}
|
var input = {}
|
||||||
|
@ -172,10 +165,10 @@ TransactionBuilder.prototype.addInput = function (prevTx, index, sequence, prevO
|
||||||
return input2.hashType & Transaction.SIGHASH_ANYONECANPAY
|
return input2.hashType & Transaction.SIGHASH_ANYONECANPAY
|
||||||
}), 'No, this would invalidate signatures')
|
}), 'No, this would invalidate signatures')
|
||||||
|
|
||||||
var prevOut = prevOutHash.toString('hex') + ':' + index
|
var prevOut = txHash.toString('hex') + ':' + vout
|
||||||
assert(!(prevOut in this.prevTxMap), 'Transaction is already an input')
|
assert(!(prevOut in this.prevTxMap), 'Transaction is already an input')
|
||||||
|
|
||||||
var vin = this.tx.addInput(prevOutHash, index, sequence)
|
var vin = this.tx.addInput(txHash, vout, sequence)
|
||||||
this.inputs[vin] = input
|
this.inputs[vin] = input
|
||||||
this.prevTxMap[prevOut] = vin
|
this.prevTxMap[prevOut] = vin
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue