Transaction: now returns index of added input/output
This commit is contained in:
parent
4f995fcae1
commit
009fcb9b82
2 changed files with 20 additions and 6 deletions
|
@ -34,7 +34,7 @@ function Transaction() {
|
||||||
*
|
*
|
||||||
* Note that this method does not sign the created input.
|
* Note that this method does not sign the created input.
|
||||||
*/
|
*/
|
||||||
Transaction.prototype.addInput = function(tx, outIndex) {
|
Transaction.prototype.addInput = function(tx, index) {
|
||||||
var hash
|
var hash
|
||||||
|
|
||||||
if (typeof tx === 'string') {
|
if (typeof tx === 'string') {
|
||||||
|
@ -50,13 +50,15 @@ Transaction.prototype.addInput = function(tx, outIndex) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ins.push(new TransactionIn({
|
assert.equal(typeof index, 'number', 'Expected number index, got ' + index)
|
||||||
|
|
||||||
|
return (this.ins.push(new TransactionIn({
|
||||||
outpoint: {
|
outpoint: {
|
||||||
hash: hash,
|
hash: hash,
|
||||||
index: outIndex
|
index: index
|
||||||
},
|
},
|
||||||
script: Script.EMPTY
|
script: Script.EMPTY
|
||||||
}))
|
})) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,10 +83,10 @@ Transaction.prototype.addOutput = function(scriptPubKey, value) {
|
||||||
scriptPubKey = address.toOutputScript()
|
scriptPubKey = address.toOutputScript()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.outs.push(new TransactionOut({
|
return (this.outs.push(new TransactionOut({
|
||||||
script: scriptPubKey,
|
script: scriptPubKey,
|
||||||
value: value,
|
value: value,
|
||||||
}))
|
})) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.toBuffer = function () {
|
Transaction.prototype.toBuffer = function () {
|
||||||
|
|
|
@ -107,6 +107,11 @@ describe('Transaction', function() {
|
||||||
verifyTransactionIn()
|
verifyTransactionIn()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns an index', function() {
|
||||||
|
assert.equal(tx.addInput(prevTx, 0), 0)
|
||||||
|
assert.equal(tx.addInput(prevTx, 0), 1)
|
||||||
|
})
|
||||||
|
|
||||||
function verifyTransactionIn() {
|
function verifyTransactionIn() {
|
||||||
assert.equal(tx.ins.length, 1)
|
assert.equal(tx.ins.length, 1)
|
||||||
|
|
||||||
|
@ -142,6 +147,13 @@ describe('Transaction', function() {
|
||||||
verifyTransactionOut()
|
verifyTransactionOut()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns an index', function() {
|
||||||
|
var dest = '15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3'
|
||||||
|
|
||||||
|
assert.equal(tx.addOutput(dest, 40000), 0)
|
||||||
|
assert.equal(tx.addOutput(dest, 40000), 1)
|
||||||
|
})
|
||||||
|
|
||||||
function verifyTransactionOut() {
|
function verifyTransactionOut() {
|
||||||
assert.equal(tx.outs.length, 1)
|
assert.equal(tx.outs.length, 1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue