Ejemplo n.º 1
0
    def get_address(self, offset=0, is_change=False, sort_keys=True):
        """
        If is_change=True, then we display change addresses.
        If is_change=False we display receive addresses.

        sort_keys is for expert users only and should be left as True
        """
        assert type(is_change) is bool, is_change
        assert type(offset) is int and offset >= 0, offset

        sec_hexes_to_use = []
        for key_record in self.key_records:
            hdpubkey = HDPublicKey.parse(key_record["xpub_parent"])
            if is_change is True:
                account = key_record["account_index"] + 1
            else:
                account = key_record["account_index"]
            leaf_xpub = hdpubkey.child(account).child(offset)
            sec_hexes_to_use.append(leaf_xpub.sec().hex())

        commands = [number_to_op_code(self.quorum_m)]
        if sort_keys:
            # BIP67 lexicographical sorting for sortedmulti
            commands.extend([bytes.fromhex(x) for x in sorted(sec_hexes_to_use)])
        else:
            commands.extend([bytes.fromhex(x) for x in sec_hexes_to_use])

        commands.append(number_to_op_code(len(self.key_records)))
        commands.append(174)  # OP_CHECKMULTISIG

        witness_script = WitnessScript(commands)
        redeem_script = P2WSHScriptPubKey(sha256(witness_script.raw_serialize()))
        return redeem_script.address(network=self.network)
Ejemplo n.º 2
0
def _get_address(pubkey_dicts, quorum_m, quorum_n, index, is_testnet):
    sec_hexes_to_use = []
    for pubkey_dict in pubkey_dicts:
        leaf_xpub = pubkey_dict["child_pubkey_obj"].child(index=index)
        sec_hexes_to_use.append(leaf_xpub.sec().hex())

    commands = [OP_CODE_NAMES_LOOKUP["OP_{}".format(quorum_m)]]
    commands.extend([bytes.fromhex(x) for x in sorted(sec_hexes_to_use)])  # BIP67
    commands.append(OP_CODE_NAMES_LOOKUP["OP_{}".format(quorum_n)])
    commands.append(OP_CODE_NAMES_LOOKUP["OP_CHECKMULTISIG"])
    witness_script = WitnessScript(commands)
    redeem_script = P2WSHScriptPubKey(sha256(witness_script.raw_serialize()))
    return redeem_script.address(testnet=is_testnet)