示例#1
0
    def get_addresses(self, testnet=False):
        """ Returns all addresses found in this script

        For output scripts, P2PKH scripts will return a single
        address the funds are being sent to. P2SH scripts will
        return a single address of the script the funds are being
        sent to.

        For input scripts, only standard signature and
        multi-signature scripts will return results: the
        address(es) used to sign. For standard signature scripts,
        a single address is returned while for multi-sig scripts,
        all n addresses in the redeem script are returned.

        Args:
            testnet (bool): True if the addresses are being used on testnet,
                False if used on mainnet.

        Returns:
            list: A list of Base58Check encoded bitcoin addresses.
        """
        rv = []
        # Determine script type
        if self.is_p2pkh():
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            rv.append(key_hash_to_address(self.get_hash160(), version))
        elif self.is_p2sh():
            version = self.P2SH_TESTNET_VERSION if testnet else self.P2SH_MAINNET_VERSION
            rv.append(key_hash_to_address(self.get_hash160(), version))
        elif self.is_multisig_sig():
            # Extract out the info
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            sig_info = self.extract_multisig_sig_info()
            redeem_info = sig_info[
                'redeem_script'].extract_multisig_redeem_info()
            for p in redeem_info['public_keys']:
                rv.append(key_hash_to_address(hash160(p), version))
            # Also include the address of the redeem script itself.
            redeem_version = self.P2SH_TESTNET_VERSION if testnet else self.P2SH_MAINNET_VERSION
            rv.append(
                key_hash_to_address(sig_info['redeem_script'].hash160(),
                                    redeem_version))
        elif self.is_p2pkh_sig():
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            # Normal signature script...
            sig_info = self.extract_sig_info()
            rv.append(
                key_hash_to_address(hash160(sig_info['public_key']), version))
        elif Script.validate_template(self, [bytes, 'OP_CHECKSIG']):
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            rv.append(key_hash_to_address(hash160(self[0]), version))

        return rv
示例#2
0
    def get_addresses(self, testnet=False):
        """ Returns all addresses found in this script

        For output scripts, P2PKH scripts will return a single
        address the funds are being sent to. P2SH scripts will
        return a single address of the script the funds are being
        sent to.

        For input scripts, only standard signature and
        multi-signature scripts will return results: the
        address(es) used to sign. For standard signature scripts,
        a single address is returned while for multi-sig scripts,
        all n addresses in the redeem script are returned.

        Args:
            testnet (bool): True if the addresses are being used on testnet,
                False if used on mainnet.

        Returns:
            list: A list of Base58Check encoded bitcoin addresses.
        """
        rv = []
        # Determine script type
        if self.is_p2pkh():
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            rv.append(key_hash_to_address(self.get_hash160(), version))
        elif self.is_p2sh():
            version = self.P2SH_TESTNET_VERSION if testnet else self.P2SH_MAINNET_VERSION
            rv.append(key_hash_to_address(self.get_hash160(), version))
        elif self.is_multisig_sig():
            # Extract out the info
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            sig_info = self.extract_multisig_sig_info()
            redeem_info = sig_info['redeem_script'].extract_multisig_redeem_info()
            for p in redeem_info['public_keys']:
                rv.append(key_hash_to_address(hash160(p), version))
            # Also include the address of the redeem script itself.
            redeem_version = self.P2SH_TESTNET_VERSION if testnet else self.P2SH_MAINNET_VERSION
            rv.append(key_hash_to_address(sig_info['redeem_script'].hash160(), redeem_version))
        elif self.is_p2pkh_sig():
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            # Normal signature script...
            sig_info = self.extract_sig_info()
            rv.append(key_hash_to_address(hash160(sig_info['public_key']),
                                          version))
        elif Script.validate_template(self, [bytes, 'OP_CHECKSIG']):
            version = self.P2PKH_TESTNET_VERSION if testnet else self.P2PKH_MAINNET_VERSION
            rv.append(key_hash_to_address(hash160(self[0]), version))

        return rv
示例#3
0
    def hash160(self):
        """ Return the RIPEMD-160 hash of the SHA-256 hash of the
        script.

        Returns:
            bytes: RIPEMD-160 byte string.
        """
        return hash160(bytes(self))
示例#4
0
    def hash160(self):
        """ Return the RIPEMD-160 hash of the SHA-256 hash of the
        script.

        Returns:
            bytes: RIPEMD-160 byte string.
        """
        return hash160(bytes(self))
示例#5
0
    def _op_hash160(self):
        """ The input is hashed twice: first with SHA-256 and then
            with RIPEMD-160.
        """
        self._check_stack_len(1)

        x = self._stack.pop()
        self._stack.append(utils.hash160(x))
示例#6
0
    def _op_hash160(self):
        """ The input is hashed twice: first with SHA-256 and then
            with RIPEMD-160.
        """
        self._check_stack_len(1)

        x = self._stack.pop()
        self._stack.append(utils.hash160(x))
示例#7
0
文件: script.py 项目: masonicGIT/two1
    def hash160(self):
        """ Return the RIPEMD-160 hash of the SHA-256 hash of a
            multisig redeem script.

        Returns
            bytes: RIPEMD-160 byte string or b"" if this script
                is not a multisig redeem script.
        """
        rv = b""
        if self.is_multisig_redeem():
            rv = hash160(bytes(self))

        return rv