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

Commit 39d1885

Browse files
committed
Sort outpoints when releasing funds from moderator
1 parent 068bfa9 commit 39d1885

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

market/network.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import pickle
1515
import time
1616
from binascii import unhexlify
17+
from bitcoin.core import COutPoint, lx
1718
from collections import OrderedDict
1819
from config import DATA_FOLDER, TRANSACTION_FEE
1920
from dht.node import Node
@@ -953,6 +954,14 @@ def release_funds(self, order_id):
953954
This function should be called to release funds from a disputed contract after
954955
the moderator has resolved the dispute and provided his signature.
955956
"""
957+
def sort_outpoints():
958+
o = []
959+
for s in contract["dispute_resolution"]["resolution"]["tx_signatures"]:
960+
for outpoint in outpoints:
961+
if COutPoint(lx(outpoint["txid"]), outpoint["vout"]).encode("hex") == s["outpoint"]:
962+
o.append(outpoint)
963+
outpoints = o
964+
956965
if os.path.exists(os.path.join(DATA_FOLDER, "purchases", "in progress", order_id + ".json")):
957966
file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", order_id + ".json")
958967
outpoints = json.loads(self.db.purchases.get_outpoint(order_id))
@@ -983,6 +992,10 @@ def release_funds(self, order_id):
983992
["resolution"]["vendor_payout"]) * 100000000)),
984993
'address': vendor_address})
985994

995+
for s in contract["dispute_resolution"]["resolution"]["tx_signatures"]:
996+
if "outpoint" in s:
997+
sort_outpoints()
998+
break
986999
tx = BitcoinTransaction.make_unsigned(outpoints, outputs, testnet=self.protocol.multiplexer.testnet)
9871000
chaincode = contract["buyer_order"]["order"]["payment"]["chaincode"]
9881001
redeem_script = str(contract["buyer_order"]["order"]["payment"]["redeem_script"])

market/transactions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def create_signature(self, privkey, reedem_script):
9797
sighash = SignatureHash(CScript(x(reedem_script)), self.tx, i, SIGHASH_ALL)
9898
signatures.append({
9999
"index": i,
100-
"signature": (seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)).encode("hex")
100+
"signature": (seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)).encode("hex"),
101+
"outpoint": self.tx.vin[i].prevout.encode("hex")
101102
})
102103
return signatures
103104

0 commit comments

Comments
 (0)