Transaction: support non-addressable output scripts

This commit is contained in:
Daniel Cousens 2014-05-19 14:55:54 +10:00
parent 5bd636cab7
commit 867465a03f
2 changed files with 24 additions and 6 deletions

View file

@ -71,18 +71,31 @@ Transaction.prototype.addInput = function (tx, outIndex) {
*
* Can be called with:
*
* - An address object and a value
* - A base58 address string and a value
* - An Address object and a value
* - A scriptPubKey Script and a value
*/
Transaction.prototype.addOutput = function (address, value) {
if (typeof address === 'string') {
address = Address.fromBase58Check(address)
Transaction.prototype.addOutput = function(scriptPubKey, value) {
// Attempt to get a valid address if it's a base58 address string
if (typeof scriptPubKey === 'string') {
scriptPubKey = Address.fromBase58Check(scriptPubKey)
}
// TODO: remove me
var addressString
// Attempt to get a valid script if it's an Address object
if (scriptPubKey instanceof Address) {
var address = scriptPubKey
addressString = address.toBase58Check()
scriptPubKey = address.toOutputScript()
}
this.outs.push(new TransactionOut({
script: scriptPubKey,
value: value,
script: address.toOutputScript(),
address: address // TODO: Remove me
address: addressString
}))
}

View file

@ -142,6 +142,11 @@ describe('Transaction', function() {
verifyTransactionOut()
})
it('allows a scriptPubKey and a value to be passed in', function() {
tx.addOutput(Address.fromBase58Check('15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3').toOutputScript(), 40000)
verifyTransactionOut()
})
it('supports alternative networks', function() {
var addr = 'mkHJaNR7uuwRG1JrmTZsV4MszaTKjCBvCR'