2017-07-24 13:23:40 -07:00
|
|
|
import json
|
|
|
|
|
2017-05-26 15:21:23 -07:00
|
|
|
class Trade(object):
|
2017-07-26 13:23:12 -07:00
|
|
|
def __init__(self, sell=None, buy=None, commitment=None):
|
2017-05-26 15:21:23 -07:00
|
|
|
'''Create a new trade with a sell contract and buy contract across two chains'''
|
2017-07-24 13:23:40 -07:00
|
|
|
self.sell = sell
|
|
|
|
self.buy = buy
|
2017-07-26 13:23:12 -07:00
|
|
|
self.commitment = commitment
|
2017-07-24 13:23:40 -07:00
|
|
|
|
|
|
|
def toJSON(self):
|
|
|
|
return json.dumps(self, default=lambda o: o.__dict__,
|
|
|
|
sort_keys=True, indent=4)
|
2017-05-22 18:00:34 -07:00
|
|
|
|
|
|
|
class Contract(object):
|
2017-05-26 09:23:49 -07:00
|
|
|
def __init__(self, data):
|
2017-07-28 13:57:44 -07:00
|
|
|
allowed = ('fulfiller', 'initiator', 'currency', 'p2sh', 'amount', 'fund_tx', 'redeem_tx', 'secret', 'redeemScript', 'redeemblocknum', 'locktime')
|
2017-05-26 09:23:49 -07:00
|
|
|
for key in data:
|
|
|
|
if key in allowed:
|
|
|
|
setattr(self, key, data[key])
|
|
|
|
|
|
|
|
def get_status(self):
|
|
|
|
if hasattr(self, 'redeem_tx'):
|
|
|
|
return 'redeemed'
|
|
|
|
elif hasattr(self, 'refund_tx'):
|
|
|
|
return 'refunded'
|
|
|
|
elif hasattr(self, 'fund_tx'):
|
|
|
|
# Do additional validation here to check amts on blockchain
|
|
|
|
return 'funded'
|
|
|
|
else:
|
|
|
|
return 'empty'
|