p2sh – Utilizing bitcoinlib to ship timelock transaction

on

|

views

and

comments


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?

Share this
Tags

Must-read

US regulators open inquiry into Waymo self-driving automobile that struck youngster in California | Expertise

The US’s federal transportation regulator stated Thursday it had opened an investigation after a Waymo self-driving car struck a toddler close to an...

US robotaxis bear coaching for London’s quirks earlier than deliberate rollout this yr | London

American robotaxis as a consequence of be unleashed on London’s streets earlier than the tip of the yr have been quietly present process...

Nvidia CEO reveals new ‘reasoning’ AI tech for self-driving vehicles | Nvidia

The billionaire boss of the chipmaker Nvidia, Jensen Huang, has unveiled new AI know-how that he says will assist self-driving vehicles assume like...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here