Browse Source

Fixes network support for TxOut

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
a77846701f
  1. 8
      src/transaction.js
  2. 9
      test/transaction.js
  3. 3
      test/wallet.js

8
src/transaction.js

@ -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)

9
test/transaction.js

@ -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)

3
test/wallet.js

@ -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…
Cancel
Save