From e6cb6764ae1ed601d4731e0dd0d32def403c3a38 Mon Sep 17 00:00:00 2001 From: Jay Graber Date: Fri, 15 Sep 2017 11:51:40 -0700 Subject: [PATCH] Fix refund bug --- xcat/bitcoinRPC.py | 3 +++ xcat/zcashRPC.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xcat/bitcoinRPC.py b/xcat/bitcoinRPC.py index 338d8e3..0a3c73f 100644 --- a/xcat/bitcoinRPC.py +++ b/xcat/bitcoinRPC.py @@ -208,6 +208,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]) diff --git a/xcat/zcashRPC.py b/xcat/zcashRPC.py index b2cafd0..0aa38fd 100644 --- a/xcat/zcashRPC.py +++ b/xcat/zcashRPC.py @@ -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,))