Auto refund

This commit is contained in:
Jay Graber 2017-08-30 12:14:42 -07:00
parent e6768147c6
commit 2436f0066b
2 changed files with 16 additions and 5 deletions

View File

@ -27,9 +27,11 @@ def checkSellStatus(tradeid):
if 'redeem_tx' in txs:
trade.buy.redeem_tx = txs['redeem_tx']
print("Redeem tx: ", txs['redeem_tx'])
elif 'refund_tx' in txs:
if 'refund_tx' in txs:
trade.buy.redeem_tx = txs['refund_tx']
print("Refund tx: ", txs['refund_tx'])
print("Buyer refund tx: ", txs['refund_tx'])
txs = refund_contract(trade.sell) # Refund to seller
print("Your refund txid: ", txs['refund_tx'])
save_state(trade, tradeid)
cleanup(tradeid)
elif status == 'sellerFunded':
@ -44,7 +46,6 @@ def buyer_check_status(trade):
return 'sellerFunded' # step1
# TODO: Find funding txid. How does buyer get seller redeemed tx?
elif sellState == 'funded' and hasattr(trade.buy, 'fund_tx'):
print("Seller redeemed")
return 'sellerRedeemed' # step3
elif sellState == 'funded' and buyState == 'funded':
return 'buyerFunded' # step2
@ -101,6 +102,7 @@ def checkBuyStatus(tradeid):
save_state(trade, tradeid)
print("XCAT trade complete!")
else:
# Search if tx has been refunded from p2sh
print("Secret not found in redeemtx")
# Import a trade in hex, and save to db
@ -264,5 +266,6 @@ def main():
tradeid = args.arguments[0]
checkSellStatus(tradeid)
elif command == "step4":
generate(1)
tradeid = args.arguments[0]
checkBuyStatus(tradeid)

View File

@ -101,6 +101,16 @@ def redeem_p2sh(contract, secret):
raise ValueError("Currency not recognized: ", currency)
return res
def refund_contract(contract):
currency = contract.currency
if currency == 'bitcoin':
res = bitcoinRPC.refund(contract)
elif currency == 'zcash':
res = zcashRPC.refund(contract)
else:
raise ValueError("Currency not recognized: ", currency)
return res
def parse_secret(currency, txid):
if currency == 'bitcoin':
secret = bitcoinRPC.parse_secret(txid)
@ -171,7 +181,6 @@ def buyer_redeem(trade):
def seller_redeem_p2sh(trade, secret):
buy = trade.buy
userInput.authorize_seller_redeem(buy)
if trade.sell.get_status() == 'redeemed':
print("You already redeemed the funds and acquired {0} {1}".format(buy.amount, buy.currency))
exit()
@ -226,7 +235,6 @@ def initialize_trade(tradeid, **kwargs):
print(trade.buy.__dict__)
return tradeid, trade
def seller_init(tradeid, trade, network):
secret = generate_password()
db.save_secret(tradeid, secret)