Fixes network support for TxOut

This commit is contained in:
Daniel Cousens 2014-05-06 14:12:37 +10:00
parent 4012b82bec
commit a77846701f
3 changed files with 18 additions and 2 deletions

View file

@ -112,7 +112,8 @@ Transaction.prototype.addOutput = function (address, value, network) {
this.outs.push(new TransactionOut({
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)
: 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 =
Array.isArray(data.value) ? convert.bytesToNum(data.value)

View file

@ -173,6 +173,15 @@ describe('Transaction', function() {
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(){
assert.equal(tx.outs.length, 1)

View file

@ -467,7 +467,10 @@ describe('Wallet', function() {
var to = 'mt7MyTVVEWnbwpF5hBn6fgnJcv95Syk2ue'
var wallet = new Wallet(seed, {network: 'testnet'})
var tx = wallet.createTx(to, value)
assert.equal(tx.outs.length, 1)
assert.equal(tx.outs[0].address.toString(), to)
assert.equal(tx.outs[0].value, value)
})
})