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

Commit 096ae95

Browse files
committed
Don't fetch contract from cache
1 parent b61d92a commit 096ae95

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

api/restapi.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def remove_ban(host):
8787
def login(self, request):
8888
request.setHeader('content-type', "application/json")
8989
if request.getHost().host in self.failed_login_attempts and \
90-
self.failed_login_attempts[request.getHost().host] >= 5:
90+
self.failed_login_attempts[request.getHost().host] >= 7:
9191
return json.dumps({"success": False, "reason": "too many attempts"})
9292
try:
9393
if request.args["username"][0] == self.username and request.args["password"][0] == self.password:
@@ -500,12 +500,7 @@ def get_node(node):
500500
else:
501501
request.write(json.dumps({}))
502502
request.finish()
503-
try:
504-
with open(DATA_FOLDER + "cache/" + request.args["id"][0], "r") as filename:
505-
contract = json.loads(filename.read(), object_pairs_hook=OrderedDict)
506-
parse_contract(contract)
507-
except Exception:
508-
self.kserver.resolve(unhexlify(request.args["guid"][0])).addCallback(get_node)
503+
self.kserver.resolve(unhexlify(request.args["guid"][0])).addCallback(get_node)
509504
else:
510505
try:
511506
with open(self.db.HashMap().get_file(request.args["id"][0]), "r") as filename:

market/contracts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def on_tx_received(self, address_version, address_hash, height, block_hash, tx):
822822
for outpoint in outpoints:
823823
self.amount_funded += outpoint["value"]
824824
self.received_txs.append(tx)
825-
self.outpoints.append(outpoint)
825+
self.outpoints.extend(outpoint)
826826
if self.amount_funded >= amount_to_pay: # if fully funded
827827
self.blockchain.unsubscribe_address(
828828
self.contract["buyer_order"]["order"]["payment"]["address"], self.on_tx_received)

market/network.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from market.moderation import process_dispute
2626
from market.profile import Profile
2727
from market.protocol import MarketProtocol
28+
from market.transactions import BitcoinTransaction
2829
from nacl.public import PrivateKey, PublicKey, Box
2930
from protos import objects
3031
from seed import peers
@@ -783,7 +784,10 @@ def close_dispute(self, order_id, resolution, buyer_percentage,
783784
raise Exception("Libbitcoin server not online")
784785
with open(DATA_FOLDER + "cases/" + order_id + ".json", "r") as filename:
785786
contract = json.load(filename, object_pairs_hook=OrderedDict)
786-
vendor_address = contract["vendor_order_confirmation"]["invoice"]["payout"]["address"]
787+
788+
if "vendor_order_confirmation" in contract and float(vendor_percentage) > 0:
789+
vendor_address = contract["vendor_order_confirmation"]["invoice"]["payout"]["address"]
790+
787791
buyer_address = contract["buyer_order"]["order"]["refund_address"]
788792

789793
buyer_guid = contract["buyer_order"]["order"]["id"]["guid"]
@@ -808,9 +812,14 @@ def history_fetched(ec, history):
808812
for tx_type, txid, i, height, value in history: # pylint: disable=W0612
809813
if tx_type == obelisk.PointIdent.Output:
810814
satoshis += value
811-
outpoint = txid.encode("hex") + ":" + str(i)
812-
if outpoint not in outpoints:
813-
outpoints.append(outpoint)
815+
o = {
816+
"txid": txid.encode("hex"),
817+
"vout": i,
818+
"value": value,
819+
"scriptPubKey": "00"
820+
}
821+
if o not in outpoints:
822+
outpoints.append(o)
814823

815824
satoshis -= TRANSACTION_FEE
816825
moderator_fee = round(float(moderator_percentage * satoshis))
@@ -830,7 +839,8 @@ def history_fetched(ec, history):
830839
dispute_json["dispute_resolution"]["resolution"]["vendor_payout"] = amt
831840
outputs.append({'value': amt,
832841
'address': vendor_address})
833-
tx = bitcointools.mktx(outpoints, outputs)
842+
# FIXME: transactions need to take in multipe outputs now
843+
tx = BitcoinTransaction.make_unsigned(outpoints, payment_address)
834844
chaincode = contract["buyer_order"]["order"]["payment"]["chaincode"]
835845
redeem_script = str(contract["buyer_order"]["order"]["payment"]["redeem_script"])
836846
masterkey_m = bitcointools.bip32_extract_key(KeyChain(self.db).bitcoin_master_privkey)
@@ -872,6 +882,7 @@ def parse_response(response):
872882
self.kserver.resolve(unhexlify(buyer_guid)).addCallback(get_node, buyer_guid, buyer_enc_key)
873883
self.db.Cases().update_status(order_id, 1)
874884

885+
# TODO: add a timeout on this call
875886
self.protocol.multiplexer.blockchain.fetch_history2(payment_address, history_fetched)
876887
except Exception:
877888
pass

0 commit comments

Comments
 (0)