How to use the duniterpy.documents.block_uid.BlockUID function in duniterpy

To help you get started, we’ve selected a few duniterpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github duniter / duniter-python-api / duniterpy / documents / block.py View on Github external
def blockUID(self) -> BlockUID:
        return BlockUID(self.number, self.proof_of_work())
github duniter / duniter-python-api / duniterpy / documents / ws2p / heads.py View on Github external
version = int(head[1]) if len(head) == 2 else 0
            return cls(version)
        except AttributeError:
            raise MalformedDocumentError("Head")

    def __str__(self) -> str:
        return "HEAD" if self.version == 0 else "HEAD:{}".format(str(self.version))


@attr.s()
class HeadV0(Head):
    signature = attr.ib(type=str)
    api = attr.ib(type=API)
    head = attr.ib(type=Head)
    pubkey = attr.ib(type=str)
    blockstamp = attr.ib(type=BlockUID)

    re_inline = re.compile(
        "^(WS2P(?:{ws2p_private})?(?:{ws2p_public})?):({head}):({pubkey}):({blockstamp})(?::)?(.*)".format(
            ws2p_private=WS2P_PRIVATE_PREFIX_REGEX,
            ws2p_public=WS2P_PUBLIC_PREFIX_REGEX,
            head=WS2P_HEAD_REGEX,
            pubkey=PUBKEY_REGEX,
            blockstamp=BLOCK_UID_REGEX,
        )
    )

    re_signature = re.compile(SIGNATURE_REGEX)

    @classmethod
    def from_inline(cls, inline: str, signature: str):
        try:
github duniter / duniter-python-api / duniterpy / documents / certification.py View on Github external
:param version: Version of document
        :param currency: Name of the currency
        :param blockhash: Hash of the block
        :param inline: Inline document
        :return:
        """
        cert_data = Certification.re_inline.match(inline)
        if cert_data is None:
            raise MalformedDocumentError("Certification ({0})".format(inline))
        pubkey_from = cert_data.group(1)
        pubkey_to = cert_data.group(2)
        blockid = int(cert_data.group(3))
        if blockid == 0 or blockhash is None:
            timestamp = BlockUID.empty()
        else:
            timestamp = BlockUID(blockid, blockhash)

        signature = cert_data.group(4)
        return cls(version, currency, pubkey_from, pubkey_to, timestamp, signature)
github duniter / duniter-python-api / duniterpy / documents / block_uid.py View on Github external
def block_uid(value: Union[str, BlockUID, None]) -> BlockUID:
    """
    Convert value to BlockUID instance

    :param value: Value to convert
    :return:
    """
    if isinstance(value, BlockUID):
        result = value
    elif isinstance(value, str):
        result = BlockUID.from_str(value)
    elif value is None:
        result = BlockUID.empty()
    else:
        raise TypeError("Cannot convert {0} to BlockUID".format(type(value)))

    return result
github duniter / duniter-python-api / duniterpy / documents / block_uid.py View on Github external
def __eq__(self, other: object) -> bool:
        if not isinstance(other, BlockUID):
            return NotImplemented
        return self.number == other.number and self.sha_hash == other.sha_hash
github duniter / duniter-python-api / duniterpy / documents / identity.py View on Github external
def from_inline(
        cls: Type[IdentityType], version: int, currency: str, inline: str
    ) -> IdentityType:
        """
        Return Identity instance from inline Identity string
        :param version: Document version number
        :param currency: Name of the currency
        :param inline: Inline string of the Identity
        :return:
        """
        selfcert_data = Identity.re_inline.match(inline)
        if selfcert_data is None:
            raise MalformedDocumentError("Inline self certification")
        pubkey = selfcert_data.group(1)
        signature = selfcert_data.group(2)
        ts = BlockUID.from_str(selfcert_data.group(3))
        uid = selfcert_data.group(4)

        return cls(version, currency, pubkey, uid, ts, signature)
github duniter / duniter-python-api / duniterpy / documents / block_uid.py View on Github external
def __init__(self, number: int, sha_hash: str) -> None:
        assert type(number) is int
        assert BlockUID.re_hash.match(sha_hash) is not None
        self.number = number
        self.sha_hash = sha_hash