Fixes Transaction.addOutput() param handling to match documentation
Now (horrendously) supports other networks
This commit is contained in:
parent
f3a55f63dc
commit
92f1c3e319
1 changed files with 11 additions and 3 deletions
|
@ -85,26 +85,33 @@ Transaction.prototype.addInput = function (tx, outIndex) {
|
||||||
* i) An existing TransactionOut object
|
* i) An existing TransactionOut object
|
||||||
* ii) An address object or an address and a value
|
* ii) An address object or an address and a value
|
||||||
* iii) An address:value string
|
* iii) An address:value string
|
||||||
|
* iv) Either ii), iii) with an optional network argument
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Transaction.prototype.addOutput = function (address, value) {
|
Transaction.prototype.addOutput = function (address, value, network) {
|
||||||
if (arguments[0] instanceof TransactionOut) {
|
if (arguments[0] instanceof TransactionOut) {
|
||||||
this.outs.push(arguments[0])
|
this.outs.push(arguments[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments[0].indexOf(':') >= 0) {
|
if (arguments[0].indexOf(':') >= 0) {
|
||||||
|
network = value
|
||||||
|
|
||||||
var args = arguments[0].split(':')
|
var args = arguments[0].split(':')
|
||||||
address = args[0]
|
address = args[0]
|
||||||
value = parseInt(args[1])
|
value = parseInt(args[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network = network || Network.bitcoin
|
||||||
|
|
||||||
// FIXME: Stricter Transaction API
|
// FIXME: Stricter Transaction API
|
||||||
address = Address.fromBase58Check(address)
|
if (!(address instanceof Address)) {
|
||||||
|
address = Address.fromBase58Check(address)
|
||||||
|
}
|
||||||
|
|
||||||
this.outs.push(new TransactionOut({
|
this.outs.push(new TransactionOut({
|
||||||
value: value,
|
value: value,
|
||||||
script: Script.createOutputScript(address)
|
script: Script.createOutputScript(address, network)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,6 +425,7 @@ TransactionIn.prototype.clone = function () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Support for alternate networks
|
||||||
var TransactionOut = function (data) {
|
var TransactionOut = function (data) {
|
||||||
this.script =
|
this.script =
|
||||||
data.script instanceof Script ? data.script.clone()
|
data.script instanceof Script ? data.script.clone()
|
||||||
|
|
Loading…
Reference in a new issue