sighash
This commit is contained in:
parent
592e26453c
commit
a54b42c645
|
@ -10,7 +10,7 @@ import bitcoin.rpc
|
|||
from bitcoin import SelectParams
|
||||
from bitcoin.core import b2x, lx, b2lx, x, COIN, COutPoint, CMutableTxOut, CMutableTxIn, CMutableTransaction, Hash160, CTransaction
|
||||
from bitcoin.base58 import decode
|
||||
from bitcoin.core.script import CScript, OP_DUP, OP_IF, OP_ELSE, OP_ENDIF, OP_HASH160, OP_EQUALVERIFY, OP_CHECKSIG, SignatureHash, SIGHASH_ALL, SIGHASH_ANYONECANPAY, OP_FALSE, OP_DROP, OP_CHECKLOCKTIMEVERIFY, OP_SHA256, OP_TRUE, OP_FALSE
|
||||
from bitcoin.core.script import CScript, OP_DUP, OP_IF, OP_ELSE, OP_ENDIF, OP_HASH160, OP_EQUALVERIFY, OP_CHECKSIG, SignatureHash, SIGHASH_ALL, SIGHASH_NONE, SIGHASH_ANYONECANPAY, OP_FALSE, OP_DROP, OP_CHECKLOCKTIMEVERIFY, OP_SHA256, OP_TRUE, OP_FALSE
|
||||
from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH
|
||||
from bitcoin.wallet import CBitcoinAddress, CBitcoinSecret, P2SHBitcoinAddress, P2PKHBitcoinAddress
|
||||
|
||||
|
@ -22,12 +22,19 @@ FEE = 0.001*COIN
|
|||
SelectParams('regtest')
|
||||
bitcoind = bitcoin.rpc.Proxy()
|
||||
|
||||
address = bitcoind.getnewaddress()
|
||||
print(address)
|
||||
privkey = bitcoind.dumpprivkey(address)
|
||||
|
||||
# Simple CLTV test p2sh
|
||||
blocknum = bitcoind.getblockcount()
|
||||
print("Current blocknum on Bitcoin: ", blocknum)
|
||||
redeemblocknum = blocknum + 1
|
||||
print("Redeemblocknum on Bitcoin: ", redeemblocknum)
|
||||
|
||||
# Script
|
||||
redeemScript = CScript([redeemblocknum, OP_CHECKLOCKTIMEVERIFY])
|
||||
|
||||
print("Redeem script for p2sh contract on Bitcoin blockchain: {0}".format(b2x(redeemScript)))
|
||||
txin_scriptPubKey = redeemScript.to_p2sh_scriptPubKey()
|
||||
# Convert the P2SH scriptPubKey to a base58 Bitcoin address
|
||||
|
@ -63,16 +70,18 @@ txout = CMutableTxOut(fundtx['amount'] - FEE, refundAddr.to_scriptPubKey())
|
|||
# Create the unsigned raw transaction.
|
||||
tx = CMutableTransaction([txin], [txout])
|
||||
# tx.nLockTime = 2430
|
||||
sighash = SignatureHash(redeemScript, tx, 0, SIGHASH_ANYONECANPAY)
|
||||
|
||||
sighash = bytes(SignatureHash(redeemScript, tx, 0, SIGHASH_NONE))
|
||||
# privkey = bitcoind.dumpprivkey(refundPubKey)
|
||||
# sig = privkey.sign(sighash) + bytes([SIGHASH_ALL])
|
||||
# sig = privkey.sign(sighash) + bytes([SIGHASH_NONE])
|
||||
sig = privkey.sign(sighash) + bytes([SIGHASH_NONE])
|
||||
signed_scriptSig = CScript([sig] + list([SIGHASH_NONE]))
|
||||
|
||||
# Sign without secret
|
||||
# OP_IF, OP_SHA256, commitment, OP_EQUALVERIFY,OP_DUP, OP_HASH160, redeemerAddr,
|
||||
# OP_ELSE, redeemblocknum, OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_DUP, OP_HASH160, funderAddr,
|
||||
# OP_ENDIF,
|
||||
# OP_EQUALVERIFY, OP_CHECKSIG
|
||||
txin.scriptSig = CScript([redeemScript])
|
||||
txin.scriptSig = CScript([signed_scriptSig, redeemScript])
|
||||
# txin.nSequence = 2185
|
||||
txin_scriptPubKey = redeemScript.to_p2sh_scriptPubKey()
|
||||
print('Raw redeem transaction hex: {0}'.format(b2x(tx.serialize())))
|
||||
|
|
Loading…
Reference in New Issue