I am attempting to make use of the python bundle python-bitcoinlib to ship a timelock transaction on testnet. The github has two examples to create an deal with, after which use that deal with to ship the bitcoin to a different deal with.
The issue is, once I ship bitcoin to the generated deal with utilizing my very own non-public key, I by no means obtain the bitcoin in my pockets. I will broadcast the transaction to the second deal with, however I want to have entry to the bitcoin in case I alter my thoughts earlier than the timelock arrives. Right here is the code:
from bitcoinutils.setup import setup
from bitcoinutils.transactions import Transaction, TxInput, TxOutput, Sequence
from bitcoinutils.keys import P2pkhAddress, P2shAddress, PrivateKey
from bitcoinutils.script import Script
from bitcoinutils.constants import TYPE_RELATIVE_TIMELOCK
def most important():
# all the time bear in mind to setup the community
setup('testnet')
#
# This script creates a P2SH deal with containing a CHECKSEQUENCEVERIFY plus
# a P2PKH locking funds with a key in addition to for 20 blocks
#
# set values
relative_blocks = 20
seq = Sequence(TYPE_RELATIVE_TIMELOCK, relative_blocks)
# secret key akin to the pubkey wanted for the P2SH (P2PKH) transaction
p2pkh_sk = PrivateKey('cRvyLwCPLU88jsyj94L7iJjQX5C2f8koG4G2gevN4BeSGcEvfKe9')
# get the deal with (from the general public key)
p2pkh_addr = p2pkh_sk.get_public_key().get_address()
# create the redeem script
redeem_script = Script([seq.for_script(), 'OP_CHECKSEQUENCEVERIFY', 'OP_DROP', 'OP_DUP', 'OP_HASH160', p2pkh_addr.to_hash160(), 'OP_EQUALVERIFY', 'OP_CHECKSIG'])
# create a P2SH deal with from a redeem script
addr = P2shAddress.from_script(redeem_script)
print(addr.to_string())
if __name__ == "__main__":
most important()
Once I run this code with my very own non-public key, I get an deal with like:
2N3M2ZnDsw4FMDYTyMmtk6k12pBzbyKJvBR
From what I perceive, that deal with is created from my non-public key, so should not the funds I ship to it go straight again to my pockets?
