Transaction: remove address from txOut
This commit is contained in:
parent
5551c38812
commit
f85792ba22
3 changed files with 23 additions and 17 deletions
|
@ -91,21 +91,16 @@ Transaction.prototype.addOutput = function(scriptPubKey, value) {
|
||||||
scriptPubKey = Address.fromBase58Check(scriptPubKey)
|
scriptPubKey = Address.fromBase58Check(scriptPubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove me
|
|
||||||
var addressString
|
|
||||||
|
|
||||||
// Attempt to get a valid script if it's an Address object
|
// Attempt to get a valid script if it's an Address object
|
||||||
if (scriptPubKey instanceof Address) {
|
if (scriptPubKey instanceof Address) {
|
||||||
var address = scriptPubKey
|
var address = scriptPubKey
|
||||||
|
|
||||||
addressString = address.toBase58Check()
|
|
||||||
scriptPubKey = address.toOutputScript()
|
scriptPubKey = address.toOutputScript()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.outs.push(new TransactionOut({
|
this.outs.push(new TransactionOut({
|
||||||
script: scriptPubKey,
|
script: scriptPubKey,
|
||||||
value: value,
|
value: value,
|
||||||
address: addressString
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,14 +381,12 @@ TransactionIn.prototype.clone = function () {
|
||||||
function TransactionOut(data) {
|
function TransactionOut(data) {
|
||||||
this.script = data.script
|
this.script = data.script
|
||||||
this.value = data.value
|
this.value = data.value
|
||||||
this.address = data.address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionOut.prototype.clone = function() {
|
TransactionOut.prototype.clone = function() {
|
||||||
return new TransactionOut({
|
return new TransactionOut({
|
||||||
script: this.script,
|
script: this.script,
|
||||||
value: this.value,
|
value: this.value
|
||||||
address: this.address
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,12 +143,13 @@ describe('Transaction', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports alternative networks', function() {
|
it('supports alternative networks', function() {
|
||||||
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'
|
var address = Address.fromBase58Check('mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR')
|
||||||
|
var script = address.toOutputScript()
|
||||||
|
|
||||||
tx.addOutput(addr, 40000)
|
tx.addOutput(address, 40000)
|
||||||
verifyTransactionOut()
|
verifyTransactionOut()
|
||||||
|
|
||||||
assert.equal(tx.outs[0].address.toString(), addr)
|
assert.deepEqual(tx.outs[0].script, script)
|
||||||
})
|
})
|
||||||
|
|
||||||
function verifyTransactionOut() {
|
function verifyTransactionOut() {
|
||||||
|
|
|
@ -455,7 +455,9 @@ describe('Wallet', function() {
|
||||||
|
|
||||||
var tx = wallet.createTx(to, toValue)
|
var tx = wallet.createTx(to, toValue)
|
||||||
assert.equal(tx.outs.length, 1)
|
assert.equal(tx.outs.length, 1)
|
||||||
assert.equal(tx.outs[0].address.toString(), to)
|
|
||||||
|
var outAddress = Address.fromOutputScript(tx.outs[0].script, networks.testnet)
|
||||||
|
assert.equal(outAddress.toString(), to)
|
||||||
assert.equal(tx.outs[0].value, toValue)
|
assert.equal(tx.outs[0].value, toValue)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -480,10 +482,14 @@ describe('Wallet', function() {
|
||||||
|
|
||||||
var tx = wallet.createTx(to, toValue, fee, changeAddress)
|
var tx = wallet.createTx(to, toValue, fee, changeAddress)
|
||||||
assert.equal(tx.outs.length, 2)
|
assert.equal(tx.outs.length, 2)
|
||||||
assert.equal(tx.outs[0].address.toString(), to)
|
|
||||||
|
var outAddress0 = Address.fromOutputScript(tx.outs[0].script, networks.testnet)
|
||||||
|
var outAddress1 = Address.fromOutputScript(tx.outs[1].script, networks.testnet)
|
||||||
|
|
||||||
|
assert.equal(outAddress0.toString(), to)
|
||||||
assert.equal(tx.outs[0].value, toValue)
|
assert.equal(tx.outs[0].value, toValue)
|
||||||
|
|
||||||
assert.equal(tx.outs[1].address.toString(), changeAddress)
|
assert.equal(outAddress1.toString(), changeAddress)
|
||||||
assert.equal(tx.outs[1].value, value - (toValue + fee))
|
assert.equal(tx.outs[1].value, value - (toValue + fee))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -494,7 +500,9 @@ describe('Wallet', function() {
|
||||||
|
|
||||||
assert.equal(tx.outs.length, 1)
|
assert.equal(tx.outs.length, 1)
|
||||||
var out = tx.outs[0]
|
var out = tx.outs[0]
|
||||||
assert.equal(out.address, to)
|
var outAddress = Address.fromOutputScript(out.script)
|
||||||
|
|
||||||
|
assert.equal(outAddress.toString(), to)
|
||||||
assert.equal(out.value, value)
|
assert.equal(out.value, value)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -507,7 +515,9 @@ describe('Wallet', function() {
|
||||||
|
|
||||||
assert.equal(tx.outs.length, 2)
|
assert.equal(tx.outs.length, 2)
|
||||||
var out = tx.outs[1]
|
var out = tx.outs[1]
|
||||||
assert.equal(out.address, wallet.changeAddresses[1])
|
var outAddress = Address.fromOutputScript(out.script)
|
||||||
|
|
||||||
|
assert.equal(outAddress.toString(), wallet.changeAddresses[1])
|
||||||
assert.equal(out.value, 15000)
|
assert.equal(out.value, 15000)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -519,7 +529,9 @@ describe('Wallet', function() {
|
||||||
|
|
||||||
assert.equal(wallet.changeAddresses.length, 1)
|
assert.equal(wallet.changeAddresses.length, 1)
|
||||||
var out = tx.outs[1]
|
var out = tx.outs[1]
|
||||||
assert.equal(out.address, wallet.changeAddresses[0])
|
var outAddress = Address.fromOutputScript(out.script)
|
||||||
|
|
||||||
|
assert.equal(outAddress.toString(), wallet.changeAddresses[0])
|
||||||
assert.equal(out.value, 15000)
|
assert.equal(out.value, 15000)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue