Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 08163b0

Browse files
author
Tom Galloway
committed
Merge remote-tracking branch 'upstream/master'
2 parents fe981fb + 29885b4 commit 08163b0

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

market/network.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -822,33 +822,32 @@ def history_fetched(ec, history):
822822
outpoints.append(o)
823823

824824
satoshis -= TRANSACTION_FEE
825-
moderator_fee = round(float(moderator_percentage * satoshis))
825+
moderator_fee = int(float(moderator_percentage) * satoshis)
826826
satoshis -= moderator_fee
827827

828828
outputs.append({'value': moderator_fee, 'address': moderator_address})
829829
dispute_json["dispute_resolution"]["resolution"]["moderator_address"] = moderator_address
830830
dispute_json["dispute_resolution"]["resolution"]["moderator_fee"] = moderator_fee
831831
dispute_json["dispute_resolution"]["resolution"]["transaction_fee"] = TRANSACTION_FEE
832832
if float(buyer_percentage) > 0:
833-
amt = round(float(buyer_percentage * satoshis))
833+
amt = int(float(buyer_percentage) * satoshis)
834834
dispute_json["dispute_resolution"]["resolution"]["buyer_payout"] = amt
835835
outputs.append({'value': amt,
836836
'address': buyer_address})
837837
if float(vendor_percentage) > 0:
838-
amt = round(float(vendor_percentage * satoshis))
838+
amt = int(float(vendor_percentage) * satoshis)
839839
dispute_json["dispute_resolution"]["resolution"]["vendor_payout"] = amt
840840
outputs.append({'value': amt,
841841
'address': vendor_address})
842-
# FIXME: transactions need to take in multipe outputs now
843-
tx = BitcoinTransaction.make_unsigned(outpoints, payment_address)
842+
843+
tx = BitcoinTransaction.make_unsigned(outpoints, outputs,
844+
testnet=self.protocol.multiplexer.testnet)
844845
chaincode = contract["buyer_order"]["order"]["payment"]["chaincode"]
845846
redeem_script = str(contract["buyer_order"]["order"]["payment"]["redeem_script"])
846847
masterkey_m = bitcointools.bip32_extract_key(KeyChain(self.db).bitcoin_master_privkey)
847848
moderator_priv = derive_childkey(masterkey_m, chaincode, bitcointools.MAINNET_PRIVATE)
848-
signatures = []
849-
for index in range(0, len(outpoints)):
850-
sig = bitcointools.multisign(tx, index, redeem_script, moderator_priv)
851-
signatures.append({"input_index": index, "signature": sig})
849+
850+
signatures = tx.create_signature(moderator_priv, redeem_script)
852851
dispute_json["dispute_resolution"]["resolution"]["order_id"] = order_id
853852
dispute_json["dispute_resolution"]["resolution"]["tx_signatures"] = signatures
854853
dispute_json["dispute_resolution"]["resolution"]["claim"] = self.db.Cases().get_claim(order_id)

market/transactions.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
class 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

Comments
 (0)