Merge branch 'master' of https://github.com/zcash-hackworks/zbxcat
This commit is contained in:
commit
2a0b86c021
|
@ -48,8 +48,8 @@ class bitcoinProxy():
|
||||||
return
|
return
|
||||||
|
|
||||||
def parse_secret(self, txid):
|
def parse_secret(self, txid):
|
||||||
raw = zcashd.gettransaction(txid, True)['hex']
|
raw = self.bitcoind.call('gettransaction', txid, True)['hex']
|
||||||
decoded = zcashd.call('decoderawtransaction', raw)
|
decoded = self.bitcoind.call('decoderawtransaction', raw)
|
||||||
scriptSig = decoded['vin'][0]['scriptSig']
|
scriptSig = decoded['vin'][0]['scriptSig']
|
||||||
asm = scriptSig['asm'].split(" ")
|
asm = scriptSig['asm'].split(" ")
|
||||||
pubkey = asm[1]
|
pubkey = asm[1]
|
||||||
|
@ -125,11 +125,8 @@ class bitcoinProxy():
|
||||||
print("txs", txs)
|
print("txs", txs)
|
||||||
for tx in txs:
|
for tx in txs:
|
||||||
txhex = b2x(tx.serialize())
|
txhex = b2x(tx.serialize())
|
||||||
# Using my fork of python-zcashlib to get result of decoderawtransaction
|
|
||||||
txhex = txhex + '00'
|
txhex = txhex + '00'
|
||||||
rawtx = zcashd.decoderawtransaction(txhex)
|
rawtx = self.bitcoind.call('decoderawtransaction', txhex)
|
||||||
# print('rawtx', rawtx)
|
|
||||||
print(rawtx)
|
|
||||||
for vout in rawtx['vout']:
|
for vout in rawtx['vout']:
|
||||||
if 'addresses' in vout['scriptPubKey']:
|
if 'addresses' in vout['scriptPubKey']:
|
||||||
for addr in vout['scriptPubKey']['addresses']:
|
for addr in vout['scriptPubKey']['addresses']:
|
||||||
|
@ -163,7 +160,7 @@ class bitcoinProxy():
|
||||||
print("Found {0} in p2sh {1}, redeeming...".format(amount, p2sh))
|
print("Found {0} in p2sh {1}, redeeming...".format(amount, p2sh))
|
||||||
|
|
||||||
blockcount = self.bitcoind.getblockcount()
|
blockcount = self.bitcoind.getblockcount()
|
||||||
print("\nCurrent blocknum at time of redeem on Zcash:", blockcount)
|
print("\nCurrent blocknum at time of redeem on Bitcoin:", blockcount)
|
||||||
if blockcount < int(redeemblocknum):
|
if blockcount < int(redeemblocknum):
|
||||||
return self.redeem(contract, fundtx, secret)
|
return self.redeem(contract, fundtx, secret)
|
||||||
else:
|
else:
|
||||||
|
@ -208,6 +205,9 @@ class bitcoinProxy():
|
||||||
txout = CMutableTxOut(fundtx['amount'] - FEE, refundPubKey.to_scriptPubKey())
|
txout = CMutableTxOut(fundtx['amount'] - FEE, refundPubKey.to_scriptPubKey())
|
||||||
# Create the unsigned raw transaction.
|
# Create the unsigned raw transaction.
|
||||||
tx = CMutableTransaction([txin], [txout])
|
tx = CMutableTransaction([txin], [txout])
|
||||||
|
# Set nSequence and nLockTime
|
||||||
|
txin.nSequence = 0
|
||||||
|
tx.nLockTime = contract.redeemblocknum
|
||||||
sighash = SignatureHash(redeemScript, tx, 0, SIGHASH_ALL)
|
sighash = SignatureHash(redeemScript, tx, 0, SIGHASH_ALL)
|
||||||
privkey = self.bitcoind.dumpprivkey(refundPubKey)
|
privkey = self.bitcoind.dumpprivkey(refundPubKey)
|
||||||
sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])
|
sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])
|
||||||
|
|
|
@ -262,7 +262,7 @@ def main():
|
||||||
tradeid = args.arguments[0]
|
tradeid = args.arguments[0]
|
||||||
checkBuyStatus(tradeid)
|
checkBuyStatus(tradeid)
|
||||||
elif command == "step3":
|
elif command == "step3":
|
||||||
generate(31)
|
# generate(31)
|
||||||
tradeid = args.arguments[0]
|
tradeid = args.arguments[0]
|
||||||
checkSellStatus(tradeid)
|
checkSellStatus(tradeid)
|
||||||
elif command == "step4":
|
elif command == "step4":
|
||||||
|
|
|
@ -157,27 +157,7 @@ def create_buy_p2sh(trade, commitment, locktime):
|
||||||
|
|
||||||
save(trade)
|
save(trade)
|
||||||
|
|
||||||
#### Main functions determining user flow from command line
|
#### Main functions related to user flow from command line
|
||||||
def buyer_redeem(trade):
|
|
||||||
userInput.authorize_buyer_redeem(trade)
|
|
||||||
if trade.sell.get_status() == 'redeemed':
|
|
||||||
print("You already redeemed the funds and acquired {0} {1}".format(trade.sell.amount, trade.sell.currency))
|
|
||||||
exit()
|
|
||||||
else:
|
|
||||||
# Buyer redeems seller's funded tx
|
|
||||||
p2sh = trade.sell.p2sh
|
|
||||||
currency = trade.sell.currency
|
|
||||||
# Buy contract is where seller disclosed secret in redeeming
|
|
||||||
if trade.buy.currency == 'bitcoin':
|
|
||||||
secret = bitcoinRPC.parse_secret(trade.buy.redeem_tx)
|
|
||||||
else:
|
|
||||||
secret = zcashRPC.parse_secret(trade.buy.redeem_tx)
|
|
||||||
print("Found secret in seller's redeem tx", secret)
|
|
||||||
redeem_tx = redeem_p2sh(trade.sell, secret)
|
|
||||||
setattr(trade.sell, 'redeem_tx', redeem_tx)
|
|
||||||
save(trade)
|
|
||||||
exit()
|
|
||||||
|
|
||||||
def seller_redeem_p2sh(trade, secret):
|
def seller_redeem_p2sh(trade, secret):
|
||||||
buy = trade.buy
|
buy = trade.buy
|
||||||
userInput.authorize_seller_redeem(buy)
|
userInput.authorize_seller_redeem(buy)
|
||||||
|
@ -190,22 +170,6 @@ def seller_redeem_p2sh(trade, secret):
|
||||||
print("You have redeemed {0} {1}!".format(buy.amount, buy.currency))
|
print("You have redeemed {0} {1}!".format(buy.amount, buy.currency))
|
||||||
return txs
|
return txs
|
||||||
|
|
||||||
def buyer_fulfill(trade):
|
|
||||||
buy = trade.buy
|
|
||||||
sell = trade.sell
|
|
||||||
buy_p2sh_balance = check_p2sh(buy.currency, buy.p2sh)
|
|
||||||
sell_p2sh_balance = check_p2sh(sell.currency, sell.p2sh)
|
|
||||||
|
|
||||||
if buy_p2sh_balance == 0:
|
|
||||||
userInput.authorize_buyer_fulfill(sell_p2sh_balance, sell.currency, buy_p2sh_balance, buy.currency)
|
|
||||||
print("Buy amt:", buy.amount)
|
|
||||||
txid = fund_buy_contract(trade)
|
|
||||||
print("Fund tx txid:", txid)
|
|
||||||
else:
|
|
||||||
print("It looks like you've already funded the contract to buy {1}, the amount in escrow in the p2sh is {0}.".format(buy_p2sh_balance, buy.currency))
|
|
||||||
print("Please wait for the seller to remove your funds from escrow to complete the trade.")
|
|
||||||
print_trade('buyer')
|
|
||||||
|
|
||||||
def initialize_trade(tradeid, **kwargs):
|
def initialize_trade(tradeid, **kwargs):
|
||||||
trade = Trade()
|
trade = Trade()
|
||||||
conf = kwargs['conf']
|
conf = kwargs['conf']
|
||||||
|
|
|
@ -212,14 +212,16 @@ class zcashProxy():
|
||||||
redeemScript = CScript(x(contract.redeemScript))
|
redeemScript = CScript(x(contract.redeemScript))
|
||||||
txin = CMutableTxIn(fundtx['outpoint'])
|
txin = CMutableTxIn(fundtx['outpoint'])
|
||||||
txout = CMutableTxOut(fundtx['amount'] - FEE, refundPubKey.to_scriptPubKey())
|
txout = CMutableTxOut(fundtx['amount'] - FEE, refundPubKey.to_scriptPubKey())
|
||||||
# Create the unsigned raw transaction.
|
|
||||||
tx = CMutableTransaction([txin], [txout])
|
tx = CMutableTransaction([txin], [txout])
|
||||||
|
# Set nSequence and nLockTime
|
||||||
|
txin.nSequence = 0
|
||||||
|
tx.nLockTime = contract.redeemblocknum
|
||||||
|
# Create the unsigned raw transaction.
|
||||||
sighash = SignatureHash(redeemScript, tx, 0, SIGHASH_ALL)
|
sighash = SignatureHash(redeemScript, tx, 0, SIGHASH_ALL)
|
||||||
privkey = self.zcashd.dumpprivkey(refundPubKey)
|
privkey = self.zcashd.dumpprivkey(refundPubKey)
|
||||||
sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])
|
sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])
|
||||||
# Sign without secret
|
# Sign without secret
|
||||||
txin.scriptSig = CScript([sig, privkey.pub, OP_FALSE, redeemScript])
|
txin.scriptSig = CScript([sig, privkey.pub, OP_FALSE, redeemScript])
|
||||||
# txin.nSequence = 2185
|
|
||||||
txin_scriptPubKey = redeemScript.to_p2sh_scriptPubKey()
|
txin_scriptPubKey = redeemScript.to_p2sh_scriptPubKey()
|
||||||
print('Raw redeem transaction hex: {0}'.format(b2x(tx.serialize())))
|
print('Raw redeem transaction hex: {0}'.format(b2x(tx.serialize())))
|
||||||
res = VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))
|
res = VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))
|
||||||
|
|
Loading…
Reference in New Issue