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