|
22 | 22 | from keys.keychain import KeyChain |
23 | 23 | from log import Logger |
24 | 24 | from market.contracts import Contract |
25 | | -from market.moderation import process_dispute |
| 25 | +from market.moderation import process_dispute, close_dispute |
26 | 26 | from market.profile import Profile |
27 | 27 | from market.protocol import MarketProtocol |
28 | 28 | from market.transactions import BitcoinTransaction |
@@ -559,6 +559,11 @@ def parse_messages(messages): |
559 | 559 | self.db, self.protocol.get_message_listener(), |
560 | 560 | self.protocol.get_notification_listener(), |
561 | 561 | self.protocol.multiplexer.testnet) |
| 562 | + elif p.type == objects.PlaintextMessage.Type.Value("DISPUTE_CLOSE"): |
| 563 | + close_dispute(json.loads(p.message, object_pairs_hook=OrderedDict), |
| 564 | + self.db, self.protocol.get_message_listener(), |
| 565 | + self.protocol.get_notification_listener(), |
| 566 | + self.protocol.multiplexer.testnet) |
562 | 567 | else: |
563 | 568 | listener.notify(p, signature) |
564 | 569 | except Exception: |
@@ -854,7 +859,7 @@ def history_fetched(ec, history): |
854 | 859 | dispute_json["dispute_resolution"]["resolution"]["decision"] = resolution |
855 | 860 | dispute_json["dispute_resolution"]["signature"] = \ |
856 | 861 | base64.b64encode(KeyChain(self.db).signing_key.sign(json.dumps( |
857 | | - dispute_json["dispute_resolution"]["resolution"]))[:64]) |
| 862 | + dispute_json["dispute_resolution"]["resolution"], indent=4))[:64]) |
858 | 863 |
|
859 | 864 | def get_node(node_to_ask, recipient_guid, public_key): |
860 | 865 | def parse_response(response): |
@@ -904,48 +909,41 @@ def release_funds(self, order_id): |
904 | 909 | vendor_address = contract["vendor_order_confirmation"]["invoice"]["payout"]["address"] |
905 | 910 | buyer_address = contract["buyer_order"]["order"]["refund_address"] |
906 | 911 |
|
907 | | - for moderator in contract["vendor_offer"]["listing"]["moderators"]: |
908 | | - if moderator["guid"] == contract["buyer_order"]["order"]["moderator"]: |
909 | | - masterkey_m = moderator["pubkeys"]["bitcoin"]["key"] |
910 | | - |
911 | 912 | outputs = [] |
912 | 913 |
|
913 | | - outputs.append({'value': contract["dispute_resolution"]["resolution"]["moderator_fee"], |
| 914 | + outputs.append({'value': int(contract["dispute_resolution"]["resolution"]["moderator_fee"]), |
914 | 915 | 'address': contract["dispute_resolution"]["resolution"]["moderator_address"]}) |
915 | 916 |
|
916 | 917 | if "buyer_payout" in contract["dispute_resolution"]["resolution"]: |
917 | | - outputs.append({'value': contract["dispute_resolution"]["resolution"]["buyer_payout"], |
| 918 | + outputs.append({'value': int(contract["dispute_resolution"]["resolution"]["buyer_payout"]), |
918 | 919 | 'address': buyer_address}) |
919 | 920 |
|
920 | 921 | if "vendor_payout" in contract["dispute_resolution"]["resolution"]: |
921 | | - outputs.append({'value': contract["dispute_resolution"]["resolution"]["vendor_payout"], |
| 922 | + outputs.append({'value': int(contract["dispute_resolution"]["resolution"]["vendor_payout"]), |
922 | 923 | 'address': vendor_address}) |
923 | 924 |
|
924 | | - tx = bitcointools.mktx(outpoints, outputs) |
925 | | - signatures = [] |
| 925 | + tx = BitcoinTransaction.make_unsigned(outpoints, outputs) |
926 | 926 | chaincode = contract["buyer_order"]["order"]["payment"]["chaincode"] |
927 | 927 | redeem_script = str(contract["buyer_order"]["order"]["payment"]["redeem_script"]) |
928 | 928 | masterkey = bitcointools.bip32_extract_key(KeyChain(self.db).bitcoin_master_privkey) |
929 | 929 | childkey = derive_childkey(masterkey, chaincode, bitcointools.MAINNET_PRIVATE) |
930 | 930 |
|
931 | | - mod_key = derive_childkey(masterkey_m, chaincode) |
| 931 | + own_sig = tx.create_signature(childkey, redeem_script) |
932 | 932 |
|
933 | | - valid_inputs = 0 |
| 933 | + signatures = [] |
934 | 934 | for index in range(0, len(outpoints)): |
935 | | - sig = bitcointools.multisign(tx, index, redeem_script, childkey) |
936 | | - signatures.append({"input_index": index, "signature": sig}) |
| 935 | + sig_ob = {"index": index, "signatures": []} |
| 936 | + for s in own_sig: |
| 937 | + if int(s["index"]) == index: |
| 938 | + sig_ob["signatures"].append(s["signature"]) |
937 | 939 | for s in contract["dispute_resolution"]["resolution"]["tx_signatures"]: |
938 | | - if s["input_index"] == index: |
939 | | - if bitcointools.verify_tx_input(tx, index, redeem_script, s["signature"], mod_key): |
940 | | - tx = bitcointools.apply_multisignatures(tx, index, str(redeem_script), |
941 | | - sig, str(s["signature"])) |
942 | | - valid_inputs += 1 |
943 | | - |
944 | | - if valid_inputs == len(outpoints): |
945 | | - self.log.info("Broadcasting payout tx %s to network" % bitcointools.txhash(tx)) |
946 | | - self.protocol.multiplexer.blockchain.broadcast(tx) |
947 | | - else: |
948 | | - raise Exception("Failed to reconstruct transaction with moderator signature.") |
| 940 | + if int(s["index"]) == index: |
| 941 | + sig_ob["signatures"].append(s["signature"]) |
| 942 | + signatures.append(sig_ob) |
| 943 | + |
| 944 | + tx.multisign(signatures, redeem_script) |
| 945 | + tx.broadcast(self.protocol.multiplexer.blockchain) |
| 946 | + self.log.info("Broadcasting payout tx %s to network" % tx.get_hash()) |
949 | 947 |
|
950 | 948 | def get_ratings(self, node_to_ask, listing_hash=None): |
951 | 949 | """ |
|
0 commit comments