Transaction: remove TxIn/TxOut from API
This commit is contained in:
parent
a6b9dd9473
commit
5bd636cab7
2 changed files with 6 additions and 36 deletions
|
@ -49,18 +49,12 @@ function Transaction(doc) {
|
||||||
*
|
*
|
||||||
* Can be called with any of:
|
* Can be called with any of:
|
||||||
*
|
*
|
||||||
* - An existing TransactionIn object
|
|
||||||
* - A transaction and an index
|
* - A transaction and an index
|
||||||
* - A transaction hash and an index
|
* - A transaction hash and an index
|
||||||
*
|
*
|
||||||
* 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, outIndex) {
|
||||||
if (arguments[0] instanceof TransactionIn) {
|
|
||||||
this.ins.push(arguments[0])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var hash = typeof tx === "string" ? tx : tx.hash
|
var hash = typeof tx === "string" ? tx : tx.hash
|
||||||
|
|
||||||
this.ins.push(new TransactionIn({
|
this.ins.push(new TransactionIn({
|
||||||
|
@ -77,16 +71,10 @@ Transaction.prototype.addInput = function (tx, outIndex) {
|
||||||
*
|
*
|
||||||
* Can be called with:
|
* Can be called with:
|
||||||
*
|
*
|
||||||
* i) An existing TransactionOut object
|
* - An address object and a value
|
||||||
* ii) An address object or a string address, and a value
|
* - A base58 address string and a value
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
Transaction.prototype.addOutput = function (address, value) {
|
Transaction.prototype.addOutput = function (address, value) {
|
||||||
if (arguments[0] instanceof TransactionOut) {
|
|
||||||
this.outs.push(arguments[0])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof address === 'string') {
|
if (typeof address === 'string') {
|
||||||
address = Address.fromBase58Check(address)
|
address = Address.fromBase58Check(address)
|
||||||
}
|
}
|
||||||
|
@ -222,12 +210,12 @@ Transaction.prototype.clone = function () {
|
||||||
newTx.version = this.version
|
newTx.version = this.version
|
||||||
newTx.locktime = this.locktime
|
newTx.locktime = this.locktime
|
||||||
|
|
||||||
this.ins.forEach(function(txin) {
|
newTx.ins = this.ins.map(function(txin) {
|
||||||
newTx.addInput(txin.clone())
|
return new TransactionIn(txin)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.outs.forEach(function(txout) {
|
newTx.outs = this.outs.map(function(txout) {
|
||||||
newTx.addOutput(txout.clone())
|
return new TransactionOut(txout)
|
||||||
})
|
})
|
||||||
|
|
||||||
return newTx
|
return newTx
|
||||||
|
|
|
@ -118,15 +118,6 @@ describe('Transaction', function() {
|
||||||
verifyTransactionIn()
|
verifyTransactionIn()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('allows a TransactionIn object to be passed in', function() {
|
|
||||||
var txCopy = tx.clone()
|
|
||||||
txCopy.addInput(prevTx, 0)
|
|
||||||
var transactionIn = txCopy.ins[0]
|
|
||||||
|
|
||||||
tx.addInput(transactionIn)
|
|
||||||
verifyTransactionIn()
|
|
||||||
})
|
|
||||||
|
|
||||||
function verifyTransactionIn() {
|
function verifyTransactionIn() {
|
||||||
assert.equal(tx.ins.length, 1)
|
assert.equal(tx.ins.length, 1)
|
||||||
|
|
||||||
|
@ -151,15 +142,6 @@ describe('Transaction', function() {
|
||||||
verifyTransactionOut()
|
verifyTransactionOut()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('allows a TransactionOut object to be passed in', function() {
|
|
||||||
var txCopy = tx.clone()
|
|
||||||
txCopy.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3", 40000)
|
|
||||||
var transactionOut = txCopy.outs[0]
|
|
||||||
|
|
||||||
tx.addOutput(transactionOut)
|
|
||||||
verifyTransactionOut()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports alternative networks', function() {
|
it('supports alternative networks', function() {
|
||||||
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
|
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue