have api methods look at trade file themselves instead of expectin parameter

This commit is contained in:
Ariel Gabizon 2017-07-05 15:54:40 +02:00
parent 5cbed011ea
commit 16ebdcc8e0
5 changed files with 30 additions and 14 deletions

View File

@ -1 +1 @@
bRSoJpPA
73tBpIOr

View File

@ -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')

View File

@ -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:

View File

@ -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"}}
{"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"}}

View File

@ -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