Transaction: remove hash:index notation
This commit is contained in:
parent
1f2becbb45
commit
a6b9dd9473
3 changed files with 14 additions and 40 deletions
|
@ -29,15 +29,15 @@ function Transaction(doc) {
|
|||
if (doc.version) this.version = doc.version;
|
||||
if (doc.locktime) this.locktime = doc.locktime;
|
||||
if (doc.ins && doc.ins.length) {
|
||||
doc.ins.forEach(function(input) {
|
||||
this.addInput(new TransactionIn(input))
|
||||
}, this)
|
||||
this.ins = doc.ins.map(function(input) {
|
||||
return new TransactionIn(input)
|
||||
})
|
||||
}
|
||||
|
||||
if (doc.outs && doc.outs.length) {
|
||||
doc.outs.forEach(function(output) {
|
||||
this.addOutput(new TransactionOut(output))
|
||||
}, this)
|
||||
this.outs = doc.outs.map(function(output) {
|
||||
return new TransactionOut(output)
|
||||
})
|
||||
}
|
||||
|
||||
this.hash = this.hash || this.getHash()
|
||||
|
@ -52,7 +52,6 @@ function Transaction(doc) {
|
|||
* - An existing TransactionIn object
|
||||
* - A transaction and an index
|
||||
* - A transaction hash and an index
|
||||
* - A single string argument of the form txhash:index
|
||||
*
|
||||
* Note that this method does not sign the created input.
|
||||
*/
|
||||
|
@ -62,15 +61,7 @@ Transaction.prototype.addInput = function (tx, outIndex) {
|
|||
return
|
||||
}
|
||||
|
||||
var hash
|
||||
if (arguments[0].length > 65) {
|
||||
var args = arguments[0].split(':')
|
||||
hash = args[0]
|
||||
outIndex = parseInt(args[1])
|
||||
|
||||
} else {
|
||||
hash = typeof tx === "string" ? tx : tx.hash
|
||||
}
|
||||
var hash = typeof tx === "string" ? tx : tx.hash
|
||||
|
||||
this.ins.push(new TransactionIn({
|
||||
outpoint: {
|
||||
|
@ -88,9 +79,7 @@ Transaction.prototype.addInput = function (tx, outIndex) {
|
|||
*
|
||||
* i) An existing TransactionOut object
|
||||
* ii) An address object or a string address, and a value
|
||||
* iii) An address:value string
|
||||
*
|
||||
* FIXME: This is a bit convoluted
|
||||
*/
|
||||
Transaction.prototype.addOutput = function (address, value) {
|
||||
if (arguments[0] instanceof TransactionOut) {
|
||||
|
@ -99,12 +88,6 @@ Transaction.prototype.addOutput = function (address, value) {
|
|||
}
|
||||
|
||||
if (typeof address === 'string') {
|
||||
if (arguments[0].indexOf(':') >= 0) {
|
||||
var args = arguments[0].split(':')
|
||||
address = args[0]
|
||||
value = parseInt(args[1])
|
||||
}
|
||||
|
||||
address = Address.fromBase58Check(address)
|
||||
}
|
||||
|
||||
|
|
|
@ -190,11 +190,12 @@ function Wallet(seed, network) {
|
|||
for (var i = 0; i < utxos.length; ++i) {
|
||||
var utxo = utxos[i]
|
||||
|
||||
tx.addInput(utxo.receive)
|
||||
accum += utxo.value
|
||||
var outpoint = utxo.receive.split(':')
|
||||
tx.addInput(outpoint[0], parseInt(outpoint[1]))
|
||||
|
||||
var fee = fixedFee == undefined ? estimateFeePadChangeOutput(tx) : fixedFee
|
||||
|
||||
accum += utxo.value
|
||||
subTotal = value + fee
|
||||
if (accum >= subTotal) {
|
||||
var change = accum - subTotal
|
||||
|
|
|
@ -127,11 +127,6 @@ describe('Transaction', function() {
|
|||
verifyTransactionIn()
|
||||
})
|
||||
|
||||
it('allows a string in the form of txhash:index to be passed in', function() {
|
||||
tx.addInput("0cb859105100ebc3344f749c835c7af7d7103ec0d8cbc3d8ccbd5d28c3c36b57:0")
|
||||
verifyTransactionIn()
|
||||
})
|
||||
|
||||
function verifyTransactionIn() {
|
||||
assert.equal(tx.ins.length, 1)
|
||||
|
||||
|
@ -156,14 +151,9 @@ describe('Transaction', function() {
|
|||
verifyTransactionOut()
|
||||
})
|
||||
|
||||
it('allows a string in the form of address:index to be passed in', function() {
|
||||
tx.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3:40000")
|
||||
verifyTransactionOut()
|
||||
})
|
||||
|
||||
it('allows a TransactionOut object to be passed in', function() {
|
||||
var txCopy = tx.clone()
|
||||
txCopy.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3:40000")
|
||||
txCopy.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3", 40000)
|
||||
var transactionOut = txCopy.outs[0]
|
||||
|
||||
tx.addOutput(transactionOut)
|
||||
|
@ -190,9 +180,9 @@ describe('Transaction', function() {
|
|||
|
||||
describe('sign', function() {
|
||||
it('works', function() {
|
||||
tx.addInput("0cb859105100ebc3344f749c835c7af7d7103ec0d8cbc3d8ccbd5d28c3c36b57:0")
|
||||
tx.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3:40000")
|
||||
tx.addOutput("1Bu3bhwRmevHLAy1JrRB6AfcxfgDG2vXRd:50000")
|
||||
tx.addInput("0cb859105100ebc3344f749c835c7af7d7103ec0d8cbc3d8ccbd5d28c3c36b57", 0)
|
||||
tx.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3", 40000)
|
||||
tx.addOutput("1Bu3bhwRmevHLAy1JrRB6AfcxfgDG2vXRd", 50000)
|
||||
|
||||
var key = ECKey.fromWIF('L44f7zxJ5Zw4EK9HZtyAnzCYz2vcZ5wiJf9AuwhJakiV4xVkxBeb')
|
||||
tx.sign(0, key)
|
||||
|
|
Loading…
Add table
Reference in a new issue