@@ -85,26 +85,33 @@ Transaction.prototype.addInput = function (tx, outIndex) {
8585 * i) An existing TransactionOut object
8686 * ii) An address object or an address and a value
8787 * iii) An address:value string
88+ * iv) Either ii), iii) with an optional network argument
8889 *
8990 */
90- Transaction . prototype . addOutput = function ( address , value ) {
91+ Transaction . prototype . addOutput = function ( address , value , network ) {
9192 if ( arguments [ 0 ] instanceof TransactionOut ) {
9293 this . outs . push ( arguments [ 0 ] )
9394 return
9495 }
9596
9697 if ( arguments [ 0 ] . indexOf ( ':' ) >= 0 ) {
98+ network = value
99+
97100 var args = arguments [ 0 ] . split ( ':' )
98101 address = args [ 0 ]
99102 value = parseInt ( args [ 1 ] )
100103 }
101104
105+ network = network || Network . bitcoin
106+
102107 // FIXME: Stricter Transaction API
103- address = Address . fromBase58Check ( address )
108+ if ( ! ( address instanceof Address ) ) {
109+ address = Address . fromBase58Check ( address )
110+ }
104111
105112 this . outs . push ( new TransactionOut ( {
106113 value : value ,
107- script : Script . createOutputScript ( address )
114+ script : Script . createOutputScript ( address , network )
108115 } ) )
109116}
110117
@@ -418,6 +425,7 @@ TransactionIn.prototype.clone = function () {
418425 } )
419426}
420427
428+ // FIXME: Support for alternate networks
421429var TransactionOut = function ( data ) {
422430 this . script =
423431 data . script instanceof Script ? data . script . clone ( )
0 commit comments