Fixes network support for TxOut
This commit is contained in:
parent
4012b82bec
commit
a77846701f
3 changed files with 18 additions and 2 deletions
|
@ -112,7 +112,8 @@ Transaction.prototype.addOutput = function (address, value, network) {
|
||||||
|
|
||||||
this.outs.push(new TransactionOut({
|
this.outs.push(new TransactionOut({
|
||||||
value: value,
|
value: value,
|
||||||
script: Script.createOutputScript(address, network)
|
script: Script.createOutputScript(address, network),
|
||||||
|
network: network
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +486,10 @@ var TransactionOut = function (data) {
|
||||||
: data.address ? Script.createOutputScript(data.address)
|
: data.address ? Script.createOutputScript(data.address)
|
||||||
: new Script()
|
: new Script()
|
||||||
|
|
||||||
if (this.script.buffer.length > 0) this.address = this.script.getToAddress();
|
var network = data.network || Network.bitcoin
|
||||||
|
if (this.script.buffer.length > 0) {
|
||||||
|
this.address = this.script.getToAddress(network)
|
||||||
|
}
|
||||||
|
|
||||||
this.value =
|
this.value =
|
||||||
Array.isArray(data.value) ? convert.bytesToNum(data.value)
|
Array.isArray(data.value) ? convert.bytesToNum(data.value)
|
||||||
|
|
|
@ -173,6 +173,15 @@ describe('Transaction', function() {
|
||||||
verifyTransactionOut()
|
verifyTransactionOut()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('supports alternative networks', function(){
|
||||||
|
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
|
||||||
|
|
||||||
|
tx.addOutput(addr, 40000, network.testnet)
|
||||||
|
verifyTransactionOut()
|
||||||
|
|
||||||
|
assert.equal(tx.outs[0].address.toString(), addr)
|
||||||
|
})
|
||||||
|
|
||||||
function verifyTransactionOut(){
|
function verifyTransactionOut(){
|
||||||
assert.equal(tx.outs.length, 1)
|
assert.equal(tx.outs.length, 1)
|
||||||
|
|
||||||
|
|
|
@ -467,7 +467,10 @@ describe('Wallet', function() {
|
||||||
var to = 'mt7MyTVVEWnbwpF5hBn6fgnJcv95Syk2ue'
|
var to = 'mt7MyTVVEWnbwpF5hBn6fgnJcv95Syk2ue'
|
||||||
var wallet = new Wallet(seed, {network: 'testnet'})
|
var wallet = new Wallet(seed, {network: 'testnet'})
|
||||||
var tx = wallet.createTx(to, value)
|
var tx = wallet.createTx(to, value)
|
||||||
|
|
||||||
assert.equal(tx.outs.length, 1)
|
assert.equal(tx.outs.length, 1)
|
||||||
|
assert.equal(tx.outs[0].address.toString(), to)
|
||||||
|
assert.equal(tx.outs[0].value, value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue