1414
1515class BitcoinTransaction (object ):
1616 """
17- A Bitcoin transaction object which is used for building, signing, and broadcasting
18- Bitcoin transactions. It is designed primarily to take in a list of outpoints
19- (all paid to the same address) and payout to a single address. At present this is the
20- only way we make transactions in OpenBazaar so more advanced functionality is not needed.
17+ A Bitcoin transaction object which is used for building, signing, and broadcasting Bitcoin transactions.
2118 """
2219 def __init__ (self , tx , testnet = False ):
2320 """
@@ -31,13 +28,14 @@ def __init__(self, tx, testnet=False):
3128 self .log = Logger (system = self )
3229
3330 @classmethod
34- def make_unsigned (cls , outpoints , output_address , tx_fee = TRANSACTION_FEE , testnet = False , out_value = None ):
31+ def make_unsigned (cls , outpoints , outputs , tx_fee = TRANSACTION_FEE , testnet = False , out_value = None ):
3532 """
3633 Build an unsigned transaction.
3734
3835 Args:
3936 outpoints: A `list` of `dict` objects which contain a txid, vout, value, and scriptPubkey.
40- output_address: The address to send the full value (minus the tx fee) of the inputs to.
37+ outputs: If a single address the full value of the inputs (minus the tx fee) will be sent there.
38+ Otherwise it should be a `list` of `dict` objects containing address and value.
4139 tx_fee: The Bitcoin network fee to be paid on this transaction.
4240 testnet: Should this transaction be built for testnet?
4341 out_value: used if you want to specify a specific output value otherwise the full value
@@ -53,12 +51,19 @@ def make_unsigned(cls, outpoints, output_address, tx_fee=TRANSACTION_FEE, testne
5351 txin .scriptSig = CScript (x (outpoint ["scriptPubKey" ]))
5452 txins .append (txin )
5553
56- # build the output
57- value = out_value if out_value is not None else (in_value - tx_fee )
58- txout = CMutableTxOut (value , CBitcoinAddress (output_address ).to_scriptPubKey ())
54+ # build the outputs
55+ txouts = []
56+ if isinstance (outputs , list ):
57+ for output in outputs :
58+ value = output ["value" ]
59+ address = output ["address" ]
60+ txouts .append (CMutableTxOut (value , CBitcoinAddress (address ).to_scriptPubKey ()))
61+ else :
62+ value = out_value if out_value is not None else (in_value - tx_fee )
63+ txouts .append (CMutableTxOut (value , CBitcoinAddress (outputs ).to_scriptPubKey ()))
5964
6065 # make the transaction
61- tx = CMutableTransaction (txins , [ txout ] )
66+ tx = CMutableTransaction (txins , txouts )
6267
6368 return BitcoinTransaction (tx )
6469
0 commit comments