This commit is contained in:
James Prestwich 2017-09-15 16:22:21 -06:00
commit 2a0b86c021
No known key found for this signature in database
GPG Key ID: 519E010A79028CCC
4 changed files with 13 additions and 47 deletions

View File

@ -48,8 +48,8 @@ class bitcoinProxy():
return
def parse_secret(self, txid):
raw = zcashd.gettransaction(txid, True)['hex']
decoded = zcashd.call('decoderawtransaction', raw)
raw = self.bitcoind.call('gettransaction', txid, True)['hex']
decoded = self.bitcoind.call('decoderawtransaction', raw)
scriptSig = decoded['vin'][0]['scriptSig']
asm = scriptSig['asm'].split(" ")
pubkey = asm[1]
@ -125,11 +125,8 @@ class bitcoinProxy():
print("txs", txs)
for tx in txs:
txhex = b2x(tx.serialize())
# Using my fork of python-zcashlib to get result of decoderawtransaction
txhex = txhex + '00'
rawtx = zcashd.decoderawtransaction(txhex)
# print('rawtx', rawtx)
print(rawtx)
rawtx = self.bitcoind.call('decoderawtransaction', txhex)
for vout in rawtx['vout']:
if 'addresses' in vout['scriptPubKey']:
for addr in vout['scriptPubKey']['addresses']:
@ -163,7 +160,7 @@ class bitcoinProxy():
print("Found {0} in p2sh {1}, redeeming...".format(amount, p2sh))
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):
return self.redeem(contract, fundtx, secret)
else:
@ -208,6 +205,9 @@ class bitcoinProxy():
txout = CMutableTxOut(fundtx['amount'] - FEE, refundPubKey.to_scriptPubKey())
# Create the unsigned raw transaction.
tx = CMutableTransaction([txin], [txout])
# Set nSequence and nLockTime
txin.nSequence = 0
tx.nLockTime = contract.redeemblocknum
sighash = SignatureHash(redeemScript, tx, 0, SIGHASH_ALL)
privkey = self.bitcoind.dumpprivkey(refundPubKey)
sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])

View File

@ -262,7 +262,7 @@ def main():
tradeid = args.arguments[0]
checkBuyStatus(tradeid)
elif command == "step3":
generate(31)
# generate(31)
tradeid = args.arguments[0]
checkSellStatus(tradeid)
elif command == "step4":

View File

@ -157,27 +157,7 @@ def create_buy_p2sh(trade, commitment, locktime):
save(trade)
#### Main functions determining 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()
#### Main functions related to user flow from command line
def seller_redeem_p2sh(trade, secret):
buy = trade.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))
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):
trade = Trade()
conf = kwargs['conf']

View File

@ -212,14 +212,16 @@ class zcashProxy():
redeemScript = CScript(x(contract.redeemScript))
txin = CMutableTxIn(fundtx['outpoint'])
txout = CMutableTxOut(fundtx['amount'] - FEE, refundPubKey.to_scriptPubKey())
# Create the unsigned raw transaction.
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)
privkey = self.zcashd.dumpprivkey(refundPubKey)
sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])
# Sign without secret
txin.scriptSig = CScript([sig, privkey.pub, OP_FALSE, redeemScript])
# txin.nSequence = 2185
txin_scriptPubKey = redeemScript.to_p2sh_scriptPubKey()
print('Raw redeem transaction hex: {0}'.format(b2x(tx.serialize())))
res = VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))