Browse Source

TxBuilder: disable Address object as valid input

hk-custom-address
Daniel Cousens 10 years ago
parent
commit
abd27dd2be
  1. 7
      src/transaction_builder.js
  2. 9
      test/transaction_builder.js

7
src/transaction_builder.js

@ -188,12 +188,7 @@ TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) {
// Attempt to get a valid address if it's a base58 address string // Attempt to get a valid address if it's a base58 address string
if (typeof scriptPubKey === 'string') { if (typeof scriptPubKey === 'string') {
scriptPubKey = Address.fromBase58Check(scriptPubKey) scriptPubKey = Address.fromBase58Check(scriptPubKey).toOutputScript()
}
// Attempt to get a valid script if it's an Address object
if (scriptPubKey instanceof Address) {
scriptPubKey = scriptPubKey.toOutputScript()
} }
return this.tx.addOutput(scriptPubKey, value) return this.tx.addOutput(scriptPubKey, value)

9
test/transaction_builder.js

@ -133,15 +133,6 @@ describe('TransactionBuilder', function () {
assert.strictEqual(txout.value, 1000) assert.strictEqual(txout.value, 1000)
}) })
it('accepts an Address object and value', function () {
var vout = txb.addOutput(privAddress, 1000)
assert.strictEqual(vout, 0)
var txout = txb.tx.outs[0]
assert.deepEqual(txout.script, privScript)
assert.strictEqual(txout.value, 1000)
})
it('accepts a ScriptPubKey and value', function () { it('accepts a ScriptPubKey and value', function () {
var vout = txb.addOutput(privScript, 1000) var vout = txb.addOutput(privScript, 1000)
assert.strictEqual(vout, 0) assert.strictEqual(vout, 0)

Loading…
Cancel
Save