当前位置: 首页>>代码示例>>Python>>正文


Python bitcoin.base58方法代码示例

本文整理汇总了Python中bitcoin.base58方法的典型用法代码示例。如果您正苦于以下问题:Python bitcoin.base58方法的具体用法?Python bitcoin.base58怎么用?Python bitcoin.base58使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitcoin的用法示例。


在下文中一共展示了bitcoin.base58方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: base58_to_asset_id

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import base58 [as 别名]
def base58_to_asset_id(self, base58_asset_id):
        """
        Parses a base58 asset ID into its bytes representation.

        :param str base58_asset_id: The asset ID in base 58 representation.
        :return: The byte representation of the asset ID.
        :rtype: bytes
        """
        try:
            asset_id = bitcoin.base58.CBase58Data(base58_asset_id)
        except bitcoin.base58.Base58ChecksumError:
            raise colorcore.routing.ControllerError("Invalid asset ID.")

        if asset_id.nVersion != self.asset_byte or len(asset_id) != 20:
            raise colorcore.routing.ControllerError("Invalid asset ID.")

        return bytes(asset_id) 
开发者ID:OpenAssets,项目名称:colorcore,代码行数:19,代码来源:operations.py

示例2: __init__

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import base58 [as 别名]
def __init__(self, s):
        if self.nVersion != bitcoin.params.BASE58_PREFIXES['SECRET_KEY']:
            raise CBitcoinSecretError('Not a base58-encoded secret key: got nVersion=%d; expected nVersion=%d' % \
                                      (self.nVersion, bitcoin.params.BASE58_PREFIXES['SECRET_KEY']))

        CKey.__init__(self, self[0:32], len(self) > 32 and _bord(self[32]) == 1) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:8,代码来源:wallet.py

示例3: from_string

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import base58 [as 别名]
def from_string(cls, base58):
        """
        Creates a new instance of the Base58Address class.

        :param str base58: The Base-58 encoded address.
        :return: The Base58Address instance.
        :rtype: Base58Address
        """
        decoded_bytes = bitcoin.base58.decode(base58)

        checksum = decoded_bytes[-4:]
        calculated_checksum = bitcoin.core.Hash(decoded_bytes[:-4])[:4]

        if checksum != calculated_checksum:
            raise bitcoin.base58.Base58ChecksumError(
                'Checksum mismatch: expected %r, calculated %r' % (checksum, calculated_checksum))

        if len(decoded_bytes) == 26:
            # The address has a namespace defined
            namespace, version, data = decoded_bytes[0:1], decoded_bytes[1:2], decoded_bytes[2:-4]
            return cls(data, version[0], namespace[0])
        elif len(decoded_bytes) == 25:
            # The namespace is undefined
            version, data = decoded_bytes[0:1], decoded_bytes[1:-4]
            return cls(data, version[0], None)
        else:
            raise ValueError('Invalid length') 
开发者ID:OpenAssets,项目名称:colorcore,代码行数:29,代码来源:addresses.py

示例4: __str__

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import base58 [as 别名]
def __str__(self):
        """
        Converts the address to a string.

        :return: The base-58 encoded string.
        :rtype: str
        """
        if self.namespace is None:
            full_payload = bytes([self.address.nVersion]) + self
        else:
            full_payload = bytes([self.namespace]) + bytes([self.address.nVersion]) + self

        checksum = bitcoin.core.Hash(full_payload)[0:4]
        return bitcoin.base58.encode(full_payload + checksum) 
开发者ID:OpenAssets,项目名称:colorcore,代码行数:16,代码来源:addresses.py

示例5: _as_any_address

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import base58 [as 别名]
def _as_any_address(address):
        try:
            result = colorcore.addresses.Base58Address.from_string(address)
            return result.address
        except (bitcoin.wallet.CBitcoinAddressError, bitcoin.base58.Base58ChecksumError):
            raise colorcore.routing.ControllerError("The address {} is an invalid address.".format(address)) 
开发者ID:OpenAssets,项目名称:colorcore,代码行数:8,代码来源:operations.py

示例6: _as_openassets_address

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import base58 [as 别名]
def _as_openassets_address(self, address):
        try:
            result = colorcore.addresses.Base58Address.from_string(address)
            if result.namespace != self.configuration.namespace:
                raise colorcore.routing.ControllerError("The address {} is not an asset address.".format(address))
            return result.address
        except (bitcoin.wallet.CBitcoinAddressError, bitcoin.base58.Base58ChecksumError):
            raise colorcore.routing.ControllerError("The address {} is an invalid address.".format(address)) 
开发者ID:OpenAssets,项目名称:colorcore,代码行数:10,代码来源:operations.py


注:本文中的bitcoin.base58方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。