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

Commit

Permalink
Sort outpoints when releasing funds from moderator
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Jun 4, 2016
1 parent 068bfa9 commit 39d1885
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions market/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pickle
import time
from binascii import unhexlify
from bitcoin.core import COutPoint, lx
from collections import OrderedDict
from config import DATA_FOLDER, TRANSACTION_FEE
from dht.node import Node
Expand Down Expand Up @@ -953,6 +954,14 @@ def release_funds(self, order_id):
This function should be called to release funds from a disputed contract after
the moderator has resolved the dispute and provided his signature.
"""
def sort_outpoints():
o = []
for s in contract["dispute_resolution"]["resolution"]["tx_signatures"]:
for outpoint in outpoints:
if COutPoint(lx(outpoint["txid"]), outpoint["vout"]).encode("hex") == s["outpoint"]:
o.append(outpoint)
outpoints = o

if os.path.exists(os.path.join(DATA_FOLDER, "purchases", "in progress", order_id + ".json")):
file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", order_id + ".json")
outpoints = json.loads(self.db.purchases.get_outpoint(order_id))
Expand Down Expand Up @@ -983,6 +992,10 @@ def release_funds(self, order_id):
["resolution"]["vendor_payout"]) * 100000000)),
'address': vendor_address})

for s in contract["dispute_resolution"]["resolution"]["tx_signatures"]:
if "outpoint" in s:
sort_outpoints()
break
tx = BitcoinTransaction.make_unsigned(outpoints, outputs, testnet=self.protocol.multiplexer.testnet)
chaincode = contract["buyer_order"]["order"]["payment"]["chaincode"]
redeem_script = str(contract["buyer_order"]["order"]["payment"]["redeem_script"])
Expand Down
3 changes: 2 additions & 1 deletion market/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def create_signature(self, privkey, reedem_script):
sighash = SignatureHash(CScript(x(reedem_script)), self.tx, i, SIGHASH_ALL)
signatures.append({
"index": i,
"signature": (seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)).encode("hex")
"signature": (seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)).encode("hex"),
"outpoint": self.tx.vin[i].prevout.encode("hex")
})
return signatures

Expand Down

0 comments on commit 39d1885

Please sign in to comment.