json rpc – Retrieve tackle similar to pubkey utilizing bitcoin-cli/RPC

0
72


If you wish to attempt one thing past utilizing the RPC, you’ll be able to calculate addresses.

Within the ScriptPubKey object, take away 21 from the beginning and ac from the tip.
The 21 is hex to point the size of the pubkey.
ac is the opcode for OP_CHECKSIG.

You’ll be left together with your pubkey 03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1. From right here you’ll be able to convert it to a base58 encoded tackle.

An instance of how to do that in with python

import bitcoin
from bitcoin.core import x
from bitcoin.core import CoreMainParams
from bitcoin.pockets import P2PKHBitcoinAddress

def calc_addr_tool(pubkey, pubtype, p2shtype, wiftype):
    class CoinParams(CoreMainParams):
        MESSAGE_START = b'x24xe9x27x64'
        DEFAULT_PORT = 7770
        BASE58_PREFIXES = {'PUBKEY_ADDR': int(pubtype),
                           'SCRIPT_ADDR': int(p2shtype),
                           'SECRET_KEY': int(wiftype)}
    bitcoin.params = CoinParams

    attempt:
        tackle = str(P2PKHBitcoinAddress.from_pubkey(x(pubkey)))
        return {
            "pubkey": pubkey,
            "pubtype": pubtype,
            "p2shtype": p2shtype,
            "wiftype": wiftype,
            "tackle": tackle
        }

    besides Exception as e:
        logger.error(f"[calc_addr_tool] Exception: {e}")
        return {"error": str(e)}

(from https://github.com/smk762/kmd_ntx_stats_docker/blob/grasp/code/kmd_ntx_api/lib_base58.py#L242-L263)

For a segwit tackle attempt

from bip32utils import Base58

def p2wpkh_in_p2sh_addr(pk, testnet=False):
    """
    Compressed public key (hex string) -> p2wpkh nested in p2sh tackle. 'SegWit tackle.'
    """
    # Script sig is simply PUSH(20){hash160(cpk)}
    push_20 = bytes.fromhex("0014")
    script_sig = push_20 + hash160_bytes(bytes.fromhex(pk))

    # Handle is then prefix + hash160(script_sig)
    prefix = b"xc4" if testnet else b"x05"
    tackle = Base58.check_encode(prefix + hash160(script_sig))
    return tackle

(from https://matthewdowney.github.io/create-segwit-address.html)

Watch out with any output and make sure with sending a small quantity first.

LEAVE A REPLY

Please enter your comment!
Please enter your name here