From 16ebdcc8e08b23714ea18c29428273547bc744d9 Mon Sep 17 00:00:00 2001 From: Ariel Gabizon Date: Wed, 5 Jul 2017 15:54:40 +0200 Subject: [PATCH] have api methods look at trade file themselves instead of expectin parameter --- secret.json | 2 +- test.py | 9 ++++----- utils.py | 27 ++++++++++++++++++++++----- xcat.json | 2 +- xcat.py | 4 ++-- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/secret.json b/secret.json index c825b9f..9bbc47b 100644 --- a/secret.json +++ b/secret.json @@ -1 +1 @@ -bRSoJpPA \ No newline at end of file +73tBpIOr \ No newline at end of file diff --git a/test.py b/test.py index 9b3a46e..6b3589e 100644 --- a/test.py +++ b/test.py @@ -3,15 +3,14 @@ from api import * print("Starting test of xcat...") htlcTrade = initiate() -buyer_fulfill(htlcTrade) +# buyer_fulfill(htlcTrade) # zXcat.generate(8) -# print("LLLLTTTTTTTTTTTTT:: ",zXcat.zcashd.listtransactions()) -zXcat.generate(2) +zXcat.generate(6) redeem_seller(htlcTrade) -zXcat.generate(2) +# zXcat.generate(2) -redeem_buyer(htlcTrade) +# redeem_buyer(htlcTrade) # addr = CBitcoinAddress('tmFRXyju7ANM7A9mg75ZjyhFW1UJEhUPwfQ') diff --git a/utils.py b/utils.py index 03d0eec..049cd98 100644 --- a/utils.py +++ b/utils.py @@ -2,6 +2,7 @@ import hashlib import json import random import binascii +import trades def hex2str(hexstring): return binascii.unhexlify(hexstring).decode('utf-8') @@ -24,11 +25,27 @@ def save_trade(trade): def get_trade(): with open('xcat.json') as data_file: - try: - xcatdb = json.load(data_file) - return xcatdb - except: - return None + # try: + xcatdb = json.load(data_file) + sellContract = trades.Contract(xcatdb['sell']) + buyContract = trades.Contract(xcatdb['buy']) + trade = trades.Trade(sellContract,buyContract) + + # trade.sellContract.currency = xcatdb['sell']['currency'] + # trade.sellContract.amount = xcatdb['sell']['amount'] + # trade.sellContract.p2sh = xcatdb['sell']['p2sh'] + # trade.sellContract.redeemscript = xcatdb['sell']['redeemscript'] + # # trade.buyContract = xcatdb['buy'] + # trade.buyContract.currency = xcatdb['buy']['currency'] + # trade.buyContract.amount = xcatdb['buy']['amount'] + # trade.buyContract.p2sh = xcatdb['buy']['p2sh'] + # trade.buyContract.redeemscript = xcatdb['buy']['redeemscript'] + + # trade.buyContract = xcatdb['buy'] + return trade + # except: + # print("HHHEERREE") + # return None def erase_trade(): with open('xcat.json', 'w') as outfile: diff --git a/xcat.json b/xcat.json index 3252c3f..e174d1c 100644 --- a/xcat.json +++ b/xcat.json @@ -1 +1 @@ -{"buy": {"initiator": "tmSMxPZhpDn9AkwjRjNS3Qd5yMVDYhsFkC8", "fulfiller": "tmUnWCoC3t8rxHQzceUTACD7HeRwiAxXNPe", "redeemblocknum": 2060, "currency": "zcash", "p2sh": "t2TwPo6mdu8bxejBe2LNQFAFKghXNo56s7w", "amount": "1.12", "redeemScript": "63a820af56bf1a42daa1278805ed6da37c150ee7a0123238ffeae6e186abb838d692468876a914b69eab222264f8be1b4c8be18ce636262da3f5cf67020c08b17576a914d13375de703dc3e78147ade514ea4ef2dbf059bf6888ac", "redeem_tx": "ae9b7731d47df3161df946ccf64d4d05fbb2bc4d0ed17fb99fe260dd4450557c", "fund_tx": "bef433c943bd2b9a2283fac9c0cd37dc24e13cab9fa4e59d42f8ad5d52cd3748"}, "sell": {"initiator": "mhVaDPABnd7bWTgYtwSkghbgXQF3Am6EXE", "fulfiller": "miUPnv6ZR3GSWGM9RuqMJXxwuGH8EnSwZY", "redeemblocknum": 7929, "currency": "bitcoin", "p2sh": "2MstbS4GLbRJctDzEAHjgVBvcGg78UUZhZ4", "amount": "0.5", "redeemScript": "63a820af56bf1a42daa1278805ed6da37c150ee7a0123238ffeae6e186abb838d692468876a914206c69ef89d5b53cde7f5b83b65fa64562b005186702f91eb17576a91415ad6758fa7915fda349fc6f3be2f907d70e4e266888ac", "redeem_tx": false, "fund_tx": "bec92dcb673b91c09a77b2a108a645bbb1fb4db77b7c23e11fc1a81d44d626e3"}} \ No newline at end of file +{"buy": {"initiator": "mwLoknDCfVqHoEkqyu6FqRzf6rJ8xR9Lm5", "p2sh": "2NEJHQU1wKVK7UoJ5eqnFZQFK38q7mUBHTb", "amount": "1.12", "currency": "bitcoin", "redeemblocknum": 7926, "redeemScript": "63a8208583d9db4246e330ffa3b368cecf040001f3a1887bc2d7787ee9f2c479aaa88e8876a914ad96b98996f1d31520a70c4cbf902a09edfb43546702f61eb17576a914731928ef8204f6929dab9cf7429c984aafcf68226888ac", "redeem_tx": false, "fulfiller": "mr1Y9FmD9SFkAD37adiRGZQwb5SS95vANG", "fund_tx": "4bd7eb93bdbf62f24dd00c22655508762328454cc70ec1e5ed3b49c1da1f770b"}, "sell": {"initiator": "tmBBfdMrVZmvxvxqCZDDzU7uF9cH62zHzfU", "p2sh": "t2J9UKHfA94p5kkriuVSQACjhw4ENVDsWo8", "amount": "0.01", "currency": "zcash", "redeemblocknum": 2073, "redeemScript": "63a8208583d9db4246e330ffa3b368cecf040001f3a1887bc2d7787ee9f2c479aaa88e8876a91448bb1bb9bc89d859d282959e5a5df84d73a3b68067021908b17576a9141022a1396b2209034d9c45f7c45b5c9c8a98f0c56888ac", "redeem_tx": false, "fulfiller": "tmGLv8VjTGyWBWB4tRR8n3yBSsjfjVSVaKh", "fund_tx": "1cdeacc609a0d942fa39e18ef32d46b49280b723025409b40f53a6606a984e4b"}} \ No newline at end of file diff --git a/xcat.py b/xcat.py index c94cb05..9430ba1 100644 --- a/xcat.py +++ b/xcat.py @@ -102,7 +102,7 @@ def redeem_p2sh(contract, secret, revertcontract): try: res = bXcat.redeem_after_timelock(revertcontract) except Exception: - print("Failed - the other party might have redeemed the fund tx with the secret by now") + print("Failed - the other party might have redeemed the fund tx on the btc chain with the secret by now") if(res): print("You have redeemed {0} {1}!".format(revertcontract.amount, revertcontract.currency)) if (revert_currency == 'zcash'): if(zXcat.still_locked(revertcontract)): @@ -112,7 +112,7 @@ def redeem_p2sh(contract, secret, revertcontract): try: res = zXcat.redeem_after_timelock(revertcontract) except Exception: - print("Failed - the other party might have redeemed the fund tx with the secret by now") + print("Failed - the other party might have redeemed the fund tx on the zcash chain with the secret by now") if(res): print("You have redeemed {0} {1}!".format(revertcontract.amount, revertcontract.currency)) return res