Beispiel #1
0
    def get_multisig(self):
        """Generate a fresh multisig on node0

        Returns a named tuple of privkeys, pubkeys and all address and scripts."""
        addrs = []
        pubkeys = []
        for _ in range(3):
            addr = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
            addrs.append(addr['address'])
            pubkeys.append(addr['pubkey'])
        script_code = CScript([OP_2] +
                              [hex_str_to_bytes(pubkey)
                               for pubkey in pubkeys] +
                              [OP_3, OP_CHECKMULTISIG])
        witness_script = CScript([OP_0, sha256(script_code)])
        return Multisig(
            [self.nodes[0].dumpprivkey(addr) for addr in addrs],
            pubkeys,
            CScript([OP_HASH160, hash160(script_code),
                     OP_EQUAL]).hex(),  # p2sh
            script_to_p2sh(script_code),  # p2sh addr
            script_code.hex(),  # redeem script
            witness_script.hex(),  # p2wsh
            script_to_p2wsh(script_code),  # p2wsh addr
            CScript([OP_HASH160, witness_script,
                     OP_EQUAL]).hex(),  # p2sh-p2wsh
            script_to_p2sh_p2wsh(script_code))  # p2sh-p2wsh addr
Beispiel #2
0
def get_multisig(node):
    """Generate a fresh 2-of-3 multisig on node

    Returns a named tuple of privkeys, pubkeys and all address and scripts."""
    addrs = []
    pubkeys = []
    for _ in range(3):
        addr = node.getaddressinfo(node.getnewaddress())
        addrs.append(addr['address'])
        pubkeys.append(addr['pubkey'])
    script_code = CScript([OP_2] +
                          [hex_str_to_bytes(pubkey)
                           for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG])
    witness_script = CScript([OP_0, sha256(script_code)])
    return Multisig(
        privkeys=[node.dumpprivkey(addr) for addr in addrs],
        pubkeys=pubkeys,
        p2sh_script=CScript([OP_HASH160,
                             hash160(script_code), OP_EQUAL]).hex(),
        p2sh_addr=script_to_p2sh(script_code),
        redeem_script=script_code.hex(),
        p2wsh_script=witness_script.hex(),
        p2wsh_addr=script_to_p2wsh(script_code),
        p2sh_p2wsh_script=CScript([OP_HASH160, witness_script,
                                   OP_EQUAL]).hex(),
        p2sh_p2wsh_addr=script_to_p2sh_p2wsh(script_code))
Beispiel #3
0
    def get_multisig(self):
        """Generate a fresh multisig on node0

        Returns a named tuple of privkeys, pubkeys and all address and scripts."""
        addrs = []
        pubkeys = []
        for _ in range(3):
            addr = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
            addrs.append(addr['address'])
            pubkeys.append(addr['pubkey'])
        script_code = CScript([OP_2] + [hex_str_to_bytes(pubkey) for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG])
        witness_script = CScript([OP_0, sha256(script_code)])
        return Multisig([self.nodes[0].dumpprivkey(addr) for addr in addrs],
                        pubkeys,
                        CScript([OP_HASH160, hash160(script_code), OP_EQUAL]).hex(),  # p2sh
                        script_to_p2sh(script_code),  # p2sh addr
                        script_code.hex(),  # redeem script
                        witness_script.hex(),  # p2wsh
                        script_to_p2wsh(script_code),  # p2wsh addr
                        CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(),  # p2sh-p2wsh
                        script_to_p2sh_p2wsh(script_code))  # p2sh-p2wsh addr
Beispiel #4
0
def get_multisig(node):
    """Generate a fresh 2-of-3 multisig on node

    Returns a named tuple of privkeys, pubkeys and all address and scripts."""
    addrs = []
    pubkeys = []
    for _ in range(3):
        addr = node.getaddressinfo(node.getnewaddress())
        addrs.append(addr['address'])
        pubkeys.append(addr['pubkey'])
    script_code = CScript([OP_2] + [hex_str_to_bytes(pubkey) for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG])
    witness_script = CScript([OP_0, sha256(script_code)])
    return Multisig(privkeys=[node.dumpprivkey(addr) for addr in addrs],
                    pubkeys=pubkeys,
                    p2sh_script=CScript([OP_HASH160, hash160(script_code), OP_EQUAL]).hex(),
                    p2sh_addr=script_to_p2sh(script_code),
                    redeem_script=script_code.hex(),
                    p2wsh_script=witness_script.hex(),
                    p2wsh_addr=script_to_p2wsh(script_code),
                    p2sh_p2wsh_script=CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(),
                    p2sh_p2wsh_addr=script_to_p2sh_p2wsh(script_code))
Beispiel #5
0
def script_to_p2wsh_script(script):
    script = check_script(script)
    return program_to_witness_script(0, sha256(script))
Beispiel #6
0
def script_to_p2sh_p2wsh_script(script):
    script = check_script(script)
    p2shscript = CScript([OP_0, sha256(script)])
    return script_to_p2sh_script(p2shscript)
Beispiel #7
0
def script_to_p2wsh_script(script, main=False):
    script = check_script(script)
    return program_to_witness_script(0, sha256(script), main)