From 89bf76f2f5b11131b893f91e07a2d2d59aae4d37 Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Fri, 2 Jul 2021 19:40:46 +0200 Subject: [PATCH] [enh] #175 rename timestamp and blockstamp attributes/arguments depending on the type (BBC) BlockUID is renamed BlockID timestamp is used for integer time in seconds block_id is used for BlockID instances --- duniterpy/constants.py | 6 +- duniterpy/documents/__init__.py | 2 +- duniterpy/documents/block.py | 16 +++--- .../documents/{block_uid.py => block_id.py} | 48 ++++++++-------- duniterpy/documents/certification.py | 48 ++++++++-------- duniterpy/documents/identity.py | 56 +++++++++---------- duniterpy/documents/membership.py | 52 +++++++++-------- duniterpy/documents/peer.py | 18 +++--- duniterpy/documents/revocation.py | 12 ++-- duniterpy/documents/transaction.py | 48 ++++++++-------- duniterpy/documents/ws2p/heads.py | 18 +++--- duniterpy/helpers/network.py | 12 ++-- examples/request_available_nodes.py | 2 +- examples/send_certification.py | 6 +- examples/send_identity.py | 10 ++-- examples/send_membership.py | 16 +++--- examples/send_transaction.py | 6 +- tests/api/ws2p/test_ws2p.py | 4 +- tests/documents/test_block.py | 38 ++++++------- tests/documents/test_certification.py | 26 ++++----- tests/documents/test_membership.py | 27 +++++---- tests/documents/test_peer.py | 4 +- tests/documents/test_transaction.py | 10 ++-- tests/documents/test_ws2p_heads.py | 6 +- 24 files changed, 246 insertions(+), 245 deletions(-) rename duniterpy/documents/{block_uid.py => block_id.py} (68%) diff --git a/duniterpy/constants.py b/duniterpy/constants.py index 7d6b7cea..dc64f472 100644 --- a/duniterpy/constants.py +++ b/duniterpy/constants.py @@ -19,9 +19,9 @@ SIGNATURE_REGEX = "[A-Za-z0-9+/]+(?:=|==)?" BLOCK_HASH_REGEX = "[0-9a-fA-F]{5,64}" TRANSACTION_HASH_REGEX = "[0-9a-fA-F]{5,64}" HASH_REGEX = "[A-F0-9]{64}" -BLOCK_ID_REGEX = "[0-9]+" -BLOCK_UID_REGEX = "{block_id_regex}-{block_hash_regex}".format( - block_id_regex=BLOCK_ID_REGEX, block_hash_regex=BLOCK_HASH_REGEX +BLOCK_NUMBER_REGEX = "[0-9]+" +BLOCK_ID_REGEX = "{block_number_regex}-{block_hash_regex}".format( + block_number_regex=BLOCK_NUMBER_REGEX, block_hash_regex=BLOCK_HASH_REGEX ) CONDITIONS_REGEX = ( "(&&|\\|\\|| |[()]|(SIG\\({pubkey_regex}\\)|(XHX\\({hash_regex}\\))))*".format( diff --git a/duniterpy/documents/__init__.py b/duniterpy/documents/__init__.py index 2cf40ae0..e60ff1c3 100644 --- a/duniterpy/documents/__init__.py +++ b/duniterpy/documents/__init__.py @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from .block import Block -from .block_uid import BlockUID, block_uid +from .block_id import BlockID, get_block_id from .certification import Certification from .document import Document, MalformedDocumentError from .identity import Identity diff --git a/duniterpy/documents/block.py b/duniterpy/documents/block.py index d93fa412..57c31a85 100644 --- a/duniterpy/documents/block.py +++ b/duniterpy/documents/block.py @@ -22,7 +22,7 @@ from ..constants import BLOCK_HASH_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX # required to type hint cls in classmethod from ..key import SigningKey, VerifyingKey -from .block_uid import BlockUID +from .block_id import BlockID from .certification import Certification from .document import Document, MalformedDocumentError from .identity import Identity @@ -255,13 +255,13 @@ class Block(Document): self.sign(signing_key) @property - def blockUID(self) -> BlockUID: + def block_id(self) -> BlockID: """ Return Block UID :return: """ - return BlockUID(self.number, self.proof_of_work()) + return BlockID(self.number, self.proof_of_work()) @classmethod def from_parsed_json(cls: Type[BlockType], parsed_json_block: dict) -> BlockType: @@ -701,27 +701,27 @@ Nonce: {nonce} def __eq__(self, other: object) -> bool: if not isinstance(other, Block): return NotImplemented - return self.blockUID == other.blockUID + return self.block_id == other.block_id def __lt__(self, other: object) -> bool: if not isinstance(other, Block): return False - return self.blockUID < other.blockUID + return self.block_id < other.block_id def __gt__(self, other: object) -> bool: if not isinstance(other, Block): return False - return self.blockUID > other.blockUID + return self.block_id > other.block_id def __le__(self, other: object) -> bool: if not isinstance(other, Block): return False - return self.blockUID <= other.blockUID + return self.block_id <= other.block_id def __ge__(self, other: object) -> bool: if not isinstance(other, Block): return False - return self.blockUID >= other.blockUID + return self.block_id >= other.block_id def check_signature(self, pubkey: str): """ diff --git a/duniterpy/documents/block_uid.py b/duniterpy/documents/block_id.py similarity index 68% rename from duniterpy/documents/block_uid.py rename to duniterpy/documents/block_id.py index 3707b27f..eebee167 100644 --- a/duniterpy/documents/block_uid.py +++ b/duniterpy/documents/block_id.py @@ -16,21 +16,21 @@ import re from typing import Type, TypeVar, Union -from ..constants import BLOCK_HASH_REGEX, BLOCK_ID_REGEX, EMPTY_HASH +from ..constants import BLOCK_HASH_REGEX, BLOCK_NUMBER_REGEX, EMPTY_HASH from .document import MalformedDocumentError # required to type hint cls in classmethod -BlockUIDType = TypeVar("BlockUIDType", bound="BlockUID") +BlockIDType = TypeVar("BlockIDType", bound="BlockID") -class BlockUID: +class BlockID: """ A simple block id """ - re_block_uid = re.compile( - "({block_id_regex})-({block_hash_regex})".format( - block_id_regex=BLOCK_ID_REGEX, block_hash_regex=BLOCK_HASH_REGEX + re_block_id = re.compile( + "({block_number_regex})-({block_hash_regex})".format( + block_number_regex=BLOCK_NUMBER_REGEX, block_hash_regex=BLOCK_HASH_REGEX ) ) re_hash = re.compile( @@ -39,26 +39,26 @@ class BlockUID: def __init__(self, number: int, sha_hash: str) -> None: assert type(number) is int - assert BlockUID.re_hash.match(sha_hash) is not None + assert BlockID.re_hash.match(sha_hash) is not None self.number = number self.sha_hash = sha_hash @classmethod - def empty(cls: Type[BlockUIDType]) -> BlockUIDType: + def empty(cls: Type[BlockIDType]) -> BlockIDType: return cls(0, EMPTY_HASH) @classmethod - def from_str(cls: Type[BlockUIDType], blockid: str) -> BlockUIDType: + def from_str(cls: Type[BlockIDType], blockid: str) -> BlockIDType: """ :param blockid: The block id """ - data = BlockUID.re_block_uid.match(blockid) + data = BlockID.re_block_id.match(blockid) if data is None: - raise MalformedDocumentError("BlockUID") + raise MalformedDocumentError("BlockID") try: number = int(data.group(1)) except AttributeError: - raise MalformedDocumentError("BlockUID") from AttributeError + raise MalformedDocumentError("BlockID") from AttributeError try: sha_hash = data.group(2) @@ -71,27 +71,27 @@ class BlockUID: return "{0}-{1}".format(self.number, self.sha_hash) def __eq__(self, other: object) -> bool: - if not isinstance(other, BlockUID): + if not isinstance(other, BlockID): return NotImplemented return self.number == other.number and self.sha_hash == other.sha_hash def __lt__(self, other: object) -> bool: - if not isinstance(other, BlockUID): + if not isinstance(other, BlockID): return NotImplemented return self.number < other.number def __gt__(self, other: object) -> bool: - if not isinstance(other, BlockUID): + if not isinstance(other, BlockID): return NotImplemented return self.number > other.number def __le__(self, other: object) -> bool: - if not isinstance(other, BlockUID): + if not isinstance(other, BlockID): return NotImplemented return self.number <= other.number def __ge__(self, other: object) -> bool: - if not isinstance(other, BlockUID): + if not isinstance(other, BlockID): return NotImplemented return self.number >= other.number @@ -99,23 +99,23 @@ class BlockUID: return hash((self.number, self.sha_hash)) def __bool__(self) -> bool: - return self != BlockUID.empty() + return self != BlockID.empty() -def block_uid(value: Union[str, BlockUID, None]) -> BlockUID: +def get_block_id(value: Union[str, BlockID, None]) -> BlockID: """ - Convert value to BlockUID instance + Convert value to BlockID instance :param value: Value to convert :return: """ - if isinstance(value, BlockUID): + if isinstance(value, BlockID): result = value elif isinstance(value, str): - result = BlockUID.from_str(value) + result = BlockID.from_str(value) elif value is None: - result = BlockUID.empty() + result = BlockID.empty() else: - raise TypeError("Cannot convert {0} to BlockUID".format(type(value))) + raise TypeError("Cannot convert {0} to BlockID".format(type(value))) return result diff --git a/duniterpy/documents/certification.py b/duniterpy/documents/certification.py index b0c93bc5..8ed73bcb 100644 --- a/duniterpy/documents/certification.py +++ b/duniterpy/documents/certification.py @@ -18,7 +18,7 @@ from typing import Optional, Type, TypeVar, Union from ..constants import ( BLOCK_ID_REGEX, - BLOCK_UID_REGEX, + BLOCK_NUMBER_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX, SIGNATURE_REGEX, @@ -26,7 +26,7 @@ from ..constants import ( # required to type hint cls in classmethod from ..key import SigningKey -from .block_uid import BlockUID +from .block_id import BlockID from .document import Document, MalformedDocumentError from .identity import Identity @@ -41,10 +41,10 @@ class Certification(Document): """ re_inline = re.compile( - "({certifier_regex}):({certified_regex}):({block_id_regex}):({signature_regex})\n".format( + "({certifier_regex}):({certified_regex}):({block_number_regex}):({signature_regex})\n".format( certifier_regex=PUBKEY_REGEX, certified_regex=PUBKEY_REGEX, - block_id_regex=BLOCK_ID_REGEX, + block_number_regex=BLOCK_NUMBER_REGEX, signature_regex=SIGNATURE_REGEX, ) ) @@ -52,20 +52,20 @@ class Certification(Document): re_issuer = re.compile( "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) ) - re_cert_timestamp = re.compile( - "CertTimestamp: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + re_cert_block_id = re.compile( + "CertTimestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) fields_parsers = { **Document.fields_parsers, - **{"Type": re_type, "Issuer": re_issuer, "CertTimestamp": re_cert_timestamp}, + **{"Type": re_type, "Issuer": re_issuer, "CertTimestamp": re_cert_block_id}, } def __init__( self, pubkey_from: str, identity: Union[Identity, str], - timestamp: BlockUID, + block_id: BlockID, signing_key: SigningKey = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, @@ -75,7 +75,7 @@ class Certification(Document): :param pubkey_from: Pubkey of the certifier :param identity: Document instance of the certified identity or identity pubkey string - :param timestamp: the blockuid + :param block_id: Current BlockID instance :param signing_key: SigningKey instance to sign the document (default=None) :param version: Document version (default=certification.VERSION) :param currency: Currency codename (default=constants.CURRENCY_CODENAME_G1) @@ -84,7 +84,7 @@ class Certification(Document): self.pubkey_from = pubkey_from self.identity = identity if isinstance(identity, Identity) else None self.pubkey_to = identity.pubkey if isinstance(identity, Identity) else identity - self.timestamp = timestamp + self.block_id = block_id if signing_key is not None: self.sign(signing_key) @@ -114,7 +114,7 @@ class Certification(Document): pubkey_from = Certification.parse_field("Issuer", lines[n]) n += 5 - timestamp = BlockUID.from_str( + block_id = BlockID.from_str( Certification.parse_field("CertTimestamp", lines[n]) ) n += 1 @@ -124,7 +124,7 @@ class Certification(Document): identity = Identity.from_certification_raw(signed_raw) certification = cls( - pubkey_from, identity, timestamp, version=version, currency=currency + pubkey_from, identity, block_id, version=version, currency=currency ) # return certification with signature @@ -134,7 +134,7 @@ class Certification(Document): @classmethod def from_inline( cls: Type[CertificationType], - blockhash: Optional[str], + block_hash: Optional[str], inline: str, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, @@ -145,7 +145,7 @@ class Certification(Document): Only self.pubkey_to is populated. You must populate self.identity with an Identity instance to use raw/sign/signed_raw methods - :param blockhash: Hash of the block + :param block_hash: Hash of the block :param inline: Inline document :param version: Document version (default=certification.VERSION) :param currency: Currency codename (default=constants.CURRENCY_CODENAME_G1) @@ -156,15 +156,15 @@ class Certification(Document): 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() + block_number = int(cert_data.group(3)) + if block_number == 0 or block_hash is None: + block_id = BlockID.empty() else: - timestamp = BlockUID(blockid, blockhash) + block_id = BlockID(block_number, block_hash) signature = cert_data.group(4) certification = cls( - pubkey_from, pubkey_to, timestamp, version=version, currency=currency + pubkey_from, pubkey_to, block_id, version=version, currency=currency ) # return certification with signature @@ -186,18 +186,18 @@ Currency: {currency} Issuer: {issuer} IdtyIssuer: {certified_pubkey} IdtyUniqueID: {certified_uid} -IdtyTimestamp: {certified_ts} +IdtyTimestamp: {certified_block_id} IdtySignature: {certified_signature} -CertTimestamp: {timestamp} +CertTimestamp: {block_id} """.format( version=self.version, currency=self.currency, issuer=self.pubkey_from, certified_pubkey=self.identity.pubkey, certified_uid=self.identity.uid, - certified_ts=self.identity.timestamp, + certified_block_id=self.identity.block_id, certified_signature=self.identity.signature, - timestamp=self.timestamp, + block_id=self.block_id, ) def sign(self, key: SigningKey) -> None: @@ -236,5 +236,5 @@ CertTimestamp: {timestamp} :return: """ return "{0}:{1}:{2}:{3}".format( - self.pubkey_from, self.pubkey_to, self.timestamp.number, self.signature + self.pubkey_from, self.pubkey_to, self.block_id.number, self.signature ) diff --git a/duniterpy/documents/identity.py b/duniterpy/documents/identity.py index 6cf3007c..50d3d572 100644 --- a/duniterpy/documents/identity.py +++ b/duniterpy/documents/identity.py @@ -17,7 +17,7 @@ import re from typing import Type, TypeVar from ..constants import ( - BLOCK_UID_REGEX, + BLOCK_ID_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX, SIGNATURE_REGEX, @@ -26,7 +26,7 @@ from ..constants import ( # required to type hint cls in classmethod from ..key import SigningKey -from .block_uid import BlockUID +from .block_id import BlockID from .document import Document, MalformedDocumentError IdentityType = TypeVar("IdentityType", bound="Identity") @@ -40,10 +40,10 @@ class Identity(Document): """ re_inline = re.compile( - "({pubkey_regex}):({signature_regex}):({block_uid_regex}):([^\n]+)\n".format( + "({pubkey_regex}):({signature_regex}):({block_id_regex}):([^\n]+)\n".format( pubkey_regex=PUBKEY_REGEX, signature_regex=SIGNATURE_REGEX, - block_uid_regex=BLOCK_UID_REGEX, + block_id_regex=BLOCK_ID_REGEX, ) ) re_type = re.compile("Type: (Identity)") @@ -53,10 +53,10 @@ class Identity(Document): re_unique_id = re.compile("UniqueID: ({uid_regex})\n".format(uid_regex=UID_REGEX)) re_uid = re.compile("UID:([^\n]+)\n") re_meta_ts = re.compile( - "META:TS:({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + "META:TS:({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) - re_timestamp = re.compile( - "Timestamp: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + re_block_id = re.compile( + "Timestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) re_idty_issuer = re.compile( @@ -65,8 +65,8 @@ class Identity(Document): re_idty_unique_id = re.compile( "IdtyUniqueID: ({uid_regex})\n".format(uid_regex=UID_REGEX) ) - re_idty_timestamp = re.compile( - "IdtyTimestamp: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + re_idty_block_id = re.compile( + "IdtyTimestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) re_idty_signature = re.compile( "IdtySignature: ({signature_regex})\n".format(signature_regex=SIGNATURE_REGEX) @@ -78,10 +78,10 @@ class Identity(Document): "Type": re_type, "UniqueID": re_unique_id, "Issuer": re_issuer, - "Timestamp": re_timestamp, + "Timestamp": re_block_id, "IdtyIssuer": re_idty_issuer, "IdtyUniqueID": re_idty_unique_id, - "IdtyTimestamp": re_idty_timestamp, + "IdtyTimestamp": re_idty_block_id, "IdtySignature": re_idty_signature, }, } @@ -90,7 +90,7 @@ class Identity(Document): self, pubkey: str, uid: str, - timestamp: BlockUID, + block_id: BlockID, signing_key: SigningKey = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, @@ -100,7 +100,7 @@ class Identity(Document): :param pubkey: Public key of the account linked to the identity :param uid: Unique identifier - :param timestamp: BlockUID instance + :param block_id: BlockID instance :param signing_key: SigningKey instance to sign the document (default=None) :param version: Document version (default=identity.VERSION) :param currency: Currency codename (default=constants.CURRENCY_CODENAME_G1) @@ -108,7 +108,7 @@ class Identity(Document): super().__init__(version, currency) self.pubkey = pubkey - self.timestamp = timestamp + self.block_id = block_id self.uid = uid if signing_key is not None: @@ -134,10 +134,10 @@ class Identity(Document): raise MalformedDocumentError("Inline self certification") pubkey = selfcert_data.group(1) signature = selfcert_data.group(2) - timestamp = BlockUID.from_str(selfcert_data.group(3)) + block_id = BlockID.from_str(selfcert_data.group(3)) uid = selfcert_data.group(4) - identity = cls(pubkey, uid, timestamp, version=version, currency=currency) + identity = cls(pubkey, uid, block_id, version=version, currency=currency) # return identity with signature identity.signature = signature @@ -169,12 +169,12 @@ class Identity(Document): uid = Identity.parse_field("UniqueID", lines[n]) n += 1 - timestamp = BlockUID.from_str(Identity.parse_field("Timestamp", lines[n])) + block_id = BlockID.from_str(Identity.parse_field("Timestamp", lines[n])) n += 1 signature = Identity.parse_field("Signature", lines[n]) - identity = cls(pubkey, uid, timestamp, version=version, currency=currency) + identity = cls(pubkey, uid, block_id, version=version, currency=currency) # return identity with signature identity.signature = signature @@ -191,13 +191,13 @@ Type: Identity Currency: {currency} Issuer: {pubkey} UniqueID: {uid} -Timestamp: {timestamp} +Timestamp: {block_id} """.format( version=self.version, currency=self.currency, pubkey=self.pubkey, uid=self.uid, - timestamp=self.timestamp, + block_id=self.block_id, ) def inline(self) -> str: @@ -206,10 +206,10 @@ Timestamp: {timestamp} :return: """ - return "{pubkey}:{signature}:{timestamp}:{uid}".format( + return "{pubkey}:{signature}:{block_id}:{uid}".format( pubkey=self.pubkey, signature=self.signature, - timestamp=self.timestamp, + block_id=self.block_id, uid=self.uid, ) @@ -237,12 +237,12 @@ Timestamp: {timestamp} uid = Identity.parse_field("IdtyUniqueID", lines[n]) n += 1 - timestamp = BlockUID.from_str(Identity.parse_field("IdtyTimestamp", lines[n])) + block_id = BlockID.from_str(Identity.parse_field("IdtyTimestamp", lines[n])) n += 1 signature = Identity.parse_field("IdtySignature", lines[n]) - identity = cls(issuer, uid, timestamp, version=version, currency=currency) + identity = cls(issuer, uid, block_id, version=version, currency=currency) identity.signature = signature return identity @@ -271,12 +271,12 @@ Timestamp: {timestamp} uid = Identity.parse_field("IdtyUniqueID", lines[n]) n += 1 - timestamp = BlockUID.from_str(Identity.parse_field("IdtyTimestamp", lines[n])) + block_id = BlockID.from_str(Identity.parse_field("IdtyTimestamp", lines[n])) n += 1 signature = Identity.parse_field("IdtySignature", lines[n]) - identity = cls(issuer, uid, timestamp, version=version, currency=currency) + identity = cls(issuer, uid, block_id, version=version, currency=currency) identity.signature = signature return identity @@ -305,7 +305,7 @@ Timestamp: {timestamp} uids = result["uids"] uid_data = uids[0] # capture data - timestamp = BlockUID.from_str(uid_data["meta"]["timestamp"]) + block_id = BlockID.from_str(uid_data["meta"]["timestamp"]) uid = uid_data["uid"] # type: str signature = uid_data["self"] # type: str @@ -313,7 +313,7 @@ Timestamp: {timestamp} identity = cls( pubkey=pubkey, uid=uid, - timestamp=timestamp, + block_id=block_id, version=version, currency=currency, ) diff --git a/duniterpy/documents/membership.py b/duniterpy/documents/membership.py index 3c966357..767fb0b4 100644 --- a/duniterpy/documents/membership.py +++ b/duniterpy/documents/membership.py @@ -17,7 +17,7 @@ import re from typing import Type, TypeVar from ..constants import ( - BLOCK_UID_REGEX, + BLOCK_ID_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX, SIGNATURE_REGEX, @@ -25,7 +25,7 @@ from ..constants import ( # required to type hint cls in classmethod from ..key import SigningKey -from .block_uid import BlockUID +from .block_id import BlockID from .document import Document, MalformedDocumentError MembershipType = TypeVar("MembershipType", bound="Membership") @@ -50,11 +50,11 @@ class Membership(Document): # PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID re_inline = re.compile( - "({pubkey_regex}):({signature_regex}):({ms_block_uid_regex}):({identity_block_uid_regex}):([^\n]+)\n".format( + "({pubkey_regex}):({signature_regex}):({ms_block_id_regex}):({identity_block_id_regex}):([^\n]+)\n".format( pubkey_regex=PUBKEY_REGEX, signature_regex=SIGNATURE_REGEX, - ms_block_uid_regex=BLOCK_UID_REGEX, - identity_block_uid_regex=BLOCK_UID_REGEX, + ms_block_id_regex=BLOCK_ID_REGEX, + identity_block_id_regex=BLOCK_ID_REGEX, ) ) re_type = re.compile("Type: (Membership)") @@ -62,12 +62,12 @@ class Membership(Document): "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) ) re_block = re.compile( - "Block: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + "Block: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) re_membership_type = re.compile("Membership: (IN|OUT)") re_userid = re.compile("UserID: ([^\n]+)\n") re_certts = re.compile( - "CertTS: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + "CertTS: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) fields_parsers = { @@ -85,9 +85,9 @@ class Membership(Document): def __init__( self, issuer: str, - membership_ts: BlockUID, + membership_block_id: BlockID, uid: str, - identity_ts: BlockUID, + identity_block_id: BlockID, signing_key: SigningKey = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, @@ -97,9 +97,9 @@ class Membership(Document): Create a membership document :param issuer: Public key of the issuer - :param membership_ts: BlockUID of this membership + :param membership_block_id: BlockID of this membership :param uid: Unique identifier of the identity - :param identity_ts: BlockUID of the identity + :param identity_block_id: BlockID of the identity :param signing_key: SigningKey instance to sign the document (default=None) :param version: Document version (default=membership.VERSION) :param currency: Currency codename (default=constants.CURRENCY_CODENAME_G1) @@ -108,10 +108,10 @@ class Membership(Document): super().__init__(version, currency) self.issuer = issuer - self.membership_ts = membership_ts + self.membership_block_id = membership_block_id self.membership_type = membership_type self.uid = uid - self.identity_ts = identity_ts + self.identity_block_id = identity_block_id if signing_key is not None: self.sign(signing_key) @@ -138,14 +138,14 @@ class Membership(Document): raise MalformedDocumentError("Inline membership ({0})".format(inline)) issuer = data.group(1) signature = data.group(2) - membership_blockstamp = BlockUID.from_str(data.group(3)) - identity_blockstamp = BlockUID.from_str(data.group(4)) + membership_block_id = BlockID.from_str(data.group(3)) + identity_block_id = BlockID.from_str(data.group(4)) uid = data.group(5) membership = cls( issuer, - membership_blockstamp, + membership_block_id, uid, - identity_blockstamp, + identity_block_id, version=version, currency=currency, membership_type=membership_type, @@ -178,7 +178,7 @@ class Membership(Document): issuer = Membership.parse_field("Issuer", lines[n]) n += 1 - membership_blockstamp = BlockUID.from_str( + membership_block_id = BlockID.from_str( Membership.parse_field("Block", lines[n]) ) n += 1 @@ -189,9 +189,7 @@ class Membership(Document): uid = Membership.parse_field("UserID", lines[n]) n += 1 - identity_blockstamp = BlockUID.from_str( - Membership.parse_field("CertTS", lines[n]) - ) + identity_block_id = BlockID.from_str(Membership.parse_field("CertTS", lines[n])) n += 1 signature = Membership.parse_field("Signature", lines[n]) @@ -199,9 +197,9 @@ class Membership(Document): membership = cls( issuer, - membership_blockstamp, + membership_block_id, uid, - identity_blockstamp, + identity_block_id, version=version, currency=currency, membership_type=membership_type, @@ -229,10 +227,10 @@ CertTS: {6} self.version, self.currency, self.issuer, - self.membership_ts, + self.membership_block_id, self.membership_type, self.uid, - self.identity_ts, + self.identity_block_id, ) def inline(self) -> str: @@ -243,7 +241,7 @@ CertTS: {6} return "{0}:{1}:{2}:{3}:{4}".format( self.issuer, self.signature, - self.membership_ts, - self.identity_ts, + self.membership_block_id, + self.identity_block_id, self.uid, ) diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index 7df979ab..c5dae7ab 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -22,7 +22,7 @@ from ..constants import BLOCK_HASH_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX # required to type hint cls in classmethod from ..key import SigningKey -from .block_uid import BlockUID +from .block_id import BlockID from .document import Document, MalformedDocumentError PeerType = TypeVar("PeerType", bound="Peer") @@ -69,7 +69,7 @@ class Peer(Document): def __init__( self, pubkey: str, - block_uid: BlockUID, + block_id: BlockID, endpoints: List[Endpoint], signing_key: SigningKey = None, version: int = VERSION, @@ -79,7 +79,7 @@ class Peer(Document): Init Peer instance :param pubkey: Public key of the issuer - :param block_uid: BlockUID instance timestamp + :param block_id: BlockID instance :param endpoints: List of endpoints string :param signing_key: SigningKey instance to sign the document (default=None) :param version: Document version (default=peer.VERSION) @@ -88,7 +88,7 @@ class Peer(Document): super().__init__(version, currency) self.pubkey = pubkey - self.blockUID = block_uid + self.block_id = block_id self.endpoints: List[Endpoint] = endpoints if signing_key is not None: @@ -117,7 +117,7 @@ class Peer(Document): pubkey = Peer.parse_field("Pubkey", lines[n]) n += 1 - block_uid = BlockUID.from_str(Peer.parse_field("Block", lines[n])) + block_id = BlockID.from_str(Peer.parse_field("Block", lines[n])) n += 1 Peer.parse_field("Endpoints", lines[n]) @@ -133,7 +133,7 @@ class Peer(Document): raise MalformedDocumentError("Peer") signature = data.group(1) - peer = cls(pubkey, block_uid, endpoints, version=version, currency=currency) + peer = cls(pubkey, block_id, endpoints, version=version, currency=currency) # return peer with signature peer.signature = signature @@ -152,7 +152,7 @@ PublicKey: {2} Block: {3} Endpoints: """.format( - self.version, self.currency, self.pubkey, self.blockUID + self.version, self.currency, self.pubkey, self.block_id ) for _endpoint in self.endpoints: @@ -166,7 +166,7 @@ Endpoints: version = data["version"] currency = data["currency"] pubkey = data["pubkey"] - block_uid = BlockUID.from_str(data["block"]) + block_id = BlockID.from_str(data["block"]) endpoints = [] for _endpoint in data["endpoints"]: @@ -174,7 +174,7 @@ Endpoints: signature = str(Peer.re_signature.match(data["signature"])) - peer = cls(pubkey, block_uid, endpoints, version=version, currency=currency) + peer = cls(pubkey, block_id, endpoints, version=version, currency=currency) # return peer with signature peer.signature = signature diff --git a/duniterpy/documents/revocation.py b/duniterpy/documents/revocation.py index 0bb43542..44aa8bfa 100644 --- a/duniterpy/documents/revocation.py +++ b/duniterpy/documents/revocation.py @@ -17,7 +17,7 @@ import re from typing import Type, TypeVar, Union from ..constants import ( - BLOCK_UID_REGEX, + BLOCK_ID_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX, SIGNATURE_REGEX, @@ -49,8 +49,8 @@ class Revocation(Document): "Issuer: ({pubkey_regex})\n".format(pubkey_regex=PUBKEY_REGEX) ) re_uniqueid = re.compile("IdtyUniqueID: ([^\n]+)\n") - re_timestamp = re.compile( - "IdtyTimestamp: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + re_block_id = re.compile( + "IdtyTimestamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) re_idtysignature = re.compile( "IdtySignature: ({signature_regex})\n".format(signature_regex=SIGNATURE_REGEX) @@ -62,7 +62,7 @@ class Revocation(Document): "Type": re_type, "Issuer": re_issuer, "IdtyUniqueID": re_uniqueid, - "IdtyTimestamp": re_timestamp, + "IdtyTimestamp": re_block_id, "IdtySignature": re_idtysignature, }, } @@ -183,14 +183,14 @@ Type: Revocation Currency: {currency} Issuer: {pubkey} IdtyUniqueID: {uid} -IdtyTimestamp: {timestamp} +IdtyTimestamp: {block_id} IdtySignature: {signature} """.format( version=self.version, currency=self.currency, pubkey=self.identity.pubkey, uid=self.identity.uid, - timestamp=self.identity.timestamp, + block_id=self.identity.block_id, signature=self.identity.signature, ) diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py index 21e4ba10..fb565bd0 100644 --- a/duniterpy/documents/transaction.py +++ b/duniterpy/documents/transaction.py @@ -23,14 +23,14 @@ from duniterpy.grammars.output import Condition from ..constants import ( BLOCK_ID_REGEX, - BLOCK_UID_REGEX, + BLOCK_NUMBER_REGEX, G1_CURRENCY_CODENAME, PUBKEY_REGEX, TRANSACTION_HASH_REGEX, ) from ..grammars import output from ..key import SigningKey, VerifyingKey -from .block_uid import BlockUID +from .block_id import BlockID from .document import Document, MalformedDocumentError VERSION = 10 @@ -77,10 +77,10 @@ class InputSource: """ re_inline = re.compile( - "([0-9]+):([0-9]):(?:(?:(D):({pubkey_regex}):({block_id_regex}))|(?:(T):({transaction_hash_regex}):\ + "([0-9]+):([0-9]):(?:(?:(D):({pubkey_regex}):({block_number_regex}))|(?:(T):({transaction_hash_regex}):\ ([0-9]+)))".format( pubkey_regex=PUBKEY_REGEX, - block_id_regex=BLOCK_ID_REGEX, + block_number_regex=BLOCK_NUMBER_REGEX, transaction_hash_regex=TRANSACTION_HASH_REGEX, ) ) @@ -506,11 +506,11 @@ class Transaction(Document): re_header = re.compile( "TX:([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([01]):([0-9]+)\n" ) - re_compact_blockstamp = re.compile( - "({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + re_compact_block_id = re.compile( + "({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) - re_blockstamp = re.compile( - "Blockstamp: ({block_uid_regex})\n".format(block_uid_regex=BLOCK_UID_REGEX) + re_block_id = re.compile( + "Blockstamp: ({block_id_regex})\n".format(block_id_regex=BLOCK_ID_REGEX) ) re_locktime = re.compile("Locktime: ([0-9]+)\n") re_issuers = re.compile("Issuers:\n") @@ -525,8 +525,8 @@ class Transaction(Document): **Document.fields_parsers, **{ "Type": re_type, - "Blockstamp": re_blockstamp, - "CompactBlockstamp": re_compact_blockstamp, + "Blockstamp": re_block_id, + "CompactBlockstamp": re_compact_block_id, "Locktime": re_locktime, "TX": re_header, "Issuers": re_issuers, @@ -541,7 +541,7 @@ class Transaction(Document): def __init__( self, - blockstamp: Optional[BlockUID], + block_id: Optional[BlockID], locktime: int, issuers: List[str], inputs: List[InputSource], @@ -556,7 +556,7 @@ class Transaction(Document): """ Init Transaction instance - :param blockstamp: BlockUID timestamp of the block + :param block_id: BlockID instance :param locktime: Lock time in seconds :param issuers: List of issuers public key :param inputs: List of InputSource instances @@ -569,7 +569,7 @@ class Transaction(Document): :param currency: Currency codename (default=constants.CURRENCY_CODENAME_G1) """ super().__init__(version, currency) - self.blockstamp = blockstamp + self.block_id = block_id self.locktime = locktime self.issuers = issuers self.inputs = inputs @@ -592,7 +592,7 @@ class Transaction(Document): self.version == other.version and self.currency == other.currency and self.signatures == other.signatures - and self.blockstamp == other.blockstamp + and self.block_id == other.block_id and self.locktime == other.locktime and self.issuers == other.issuers and self.inputs == other.inputs @@ -608,7 +608,7 @@ class Transaction(Document): self.version, self.currency, self.signatures, - self.blockstamp, + self.block_id, self.locktime, self.issuers, self.inputs, @@ -682,7 +682,7 @@ Comment: {comment} locktime = int(header_data.group(7)) n += 1 - blockstamp = BlockUID.from_str( + block_id = BlockID.from_str( Transaction.parse_field("CompactBlockstamp", lines[n]) ) n += 1 @@ -730,7 +730,7 @@ Comment: {comment} raise MalformedDocumentError("Compact TX Signatures") transaction = cls( - blockstamp, + block_id, locktime, issuers, inputs, @@ -769,7 +769,7 @@ Comment: {comment} currency = Transaction.parse_field("Currency", lines[n]) n += 1 - blockstamp = BlockUID.from_str(Transaction.parse_field("Blockstamp", lines[n])) + block_id = BlockID.from_str(Transaction.parse_field("Blockstamp", lines[n])) n += 1 locktime = Transaction.parse_field("Locktime", lines[n]) @@ -819,7 +819,7 @@ Comment: {comment} n += 1 transaction = cls( - blockstamp, + block_id, locktime, issuers, inputs, @@ -848,7 +848,7 @@ Currency: {1} self.version, self.currency ) - doc += "Blockstamp: {0}\n".format(self.blockstamp) + doc += "Blockstamp: {0}\n".format(self.block_id) doc += "Locktime: {0}\n".format(self.locktime) @@ -896,7 +896,7 @@ Currency: {1} "1" if self.comment != "" else "0", self.locktime, ) - doc += "{0}\n".format(self.blockstamp) + doc += "{0}\n".format(self.block_id) for pubkey in self.issuers: doc += "{0}\n".format(pubkey) @@ -983,7 +983,7 @@ class SimpleTransaction(Transaction): def __init__( self, - blockstamp: BlockUID, + block_id: BlockID, locktime: int, issuer: str, single_input: InputSource, @@ -998,7 +998,7 @@ class SimpleTransaction(Transaction): """ Init instance - :param blockstamp: BlockUID timestamp + :param block_id: BlockID instance :param locktime: Lock time in seconds :param issuer: Issuer public key :param single_input: InputSource instance @@ -1011,7 +1011,7 @@ class SimpleTransaction(Transaction): :param currency: Currency codename (default=constants.CURRENCY_CODENAME_G1) """ super().__init__( - blockstamp, + block_id, locktime, [issuer], [single_input], diff --git a/duniterpy/documents/ws2p/heads.py b/duniterpy/documents/ws2p/heads.py index c2ec8b58..fc79f48c 100644 --- a/duniterpy/documents/ws2p/heads.py +++ b/duniterpy/documents/ws2p/heads.py @@ -17,7 +17,7 @@ import re import attr from ...constants import ( - BLOCK_UID_REGEX, + BLOCK_ID_REGEX, PUBKEY_REGEX, SIGNATURE_REGEX, WS2P_HEAD_REGEX, @@ -26,7 +26,7 @@ from ...constants import ( WS2PID_REGEX, ) from ...key import VerifyingKey -from ..block_uid import BlockUID +from ..block_id import BlockID from ..document import MalformedDocumentError @@ -82,15 +82,15 @@ class HeadV0(Head): api = attr.ib(type=API) head = attr.ib(type=Head) pubkey = attr.ib(type=str) - blockstamp = attr.ib(type=BlockUID) + block_id = attr.ib(type=BlockID) re_inline = re.compile( - "^(WS2P(?:{ws2p_private})?(?:{ws2p_public})?):({head}):({pubkey}):({blockstamp})(?::)?(.*)".format( + "^(WS2P(?:{ws2p_private})?(?:{ws2p_public})?):({head}):({pubkey}):({block_id})(?::)?(.*)".format( ws2p_private=WS2P_PRIVATE_PREFIX_REGEX, ws2p_public=WS2P_PUBLIC_PREFIX_REGEX, head=WS2P_HEAD_REGEX, pubkey=PUBKEY_REGEX, - blockstamp=BLOCK_UID_REGEX, + block_id=BLOCK_ID_REGEX, ) ) @@ -105,9 +105,9 @@ class HeadV0(Head): api = API.from_inline(data.group(1)) head = Head.from_inline(data.group(2), "") pubkey = data.group(3) - blockstamp = BlockUID.from_str(data.group(4)) + block_id = BlockID.from_str(data.group(4)) offload = data.group(5) - return cls(head.version, signature, api, head, pubkey, blockstamp), offload + return cls(head.version, signature, api, head, pubkey, block_id), offload except AttributeError: raise MalformedDocumentError("HeadV0") from AttributeError @@ -173,7 +173,7 @@ class HeadV1(HeadV0): v0.api, v0.head, v0.pubkey, - v0.blockstamp, + v0.block_id, ws2pid, software, software_version, @@ -212,7 +212,7 @@ class HeadV2(HeadV1): v1.api, v1.head, v1.pubkey, - v1.blockstamp, + v1.block_id, v1.ws2pid, v1.software, v1.software_version, diff --git a/duniterpy/helpers/network.py b/duniterpy/helpers/network.py index e268303b..1586aaec 100644 --- a/duniterpy/helpers/network.py +++ b/duniterpy/helpers/network.py @@ -24,9 +24,9 @@ from duniterpy.documents.ws2p.heads import HeadV2 def get_available_nodes(client: Client) -> List[List[Dict[str, Any]]]: """ - Get available nodes grouped and sorted by descending blockstamp + Get available nodes grouped and sorted by descending block_id - Each entry is a list of nodes (HeadV2 instance, inline endpoint list) sharing the same blockstamp: + Each entry is a list of nodes (HeadV2 instance, inline endpoint list) sharing the same block_id: [ [{"head": HeadV2, "endpoints": [str, ...]}, ...], @@ -57,12 +57,12 @@ def get_available_nodes(client: Client) -> List[List[Dict[str, Any]]]: head, _ = HeadV2.from_inline(entry["messageV2"], entry["sigV2"]) heads.append(head) - # sort by blockstamp by descending order - heads = sorted(heads, key=lambda x: x.blockstamp, reverse=True) + # sort by block_id by descending order + heads = sorted(heads, key=lambda x: x.block_id, reverse=True) - # group heads by blockstamp + # group heads by block_id groups = [] - for _, group in groupby(heads, key=lambda x: x.blockstamp): + for _, group in groupby(heads, key=lambda x: x.block_id): nodes = [] for head in list(group): diff --git a/examples/request_available_nodes.py b/examples/request_available_nodes.py index 958d8101..8952e030 100644 --- a/examples/request_available_nodes.py +++ b/examples/request_available_nodes.py @@ -36,7 +36,7 @@ def request_available_nodes(): groups = network.get_available_nodes(client) for group in groups: - block = group[0]["head"].blockstamp + block = group[0]["head"].block_id print(f"block {block} shared by {len(group)} nodes") print("\nAvailable endpoints:") diff --git a/examples/send_certification.py b/examples/send_certification.py index c0143425..f9a41b2c 100644 --- a/examples/send_certification.py +++ b/examples/send_certification.py @@ -19,7 +19,7 @@ from typing import Optional from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents import BlockUID, Certification, Identity +from duniterpy.documents import BlockID, Certification, Identity from duniterpy.key import SigningKey # CONFIG ####################################### @@ -68,7 +68,7 @@ def get_certification_document( return Certification( pubkey_from=signing_key.pubkey, identity=identity, - timestamp=BlockUID(current_block["number"], current_block["hash"]), + block_id=BlockID(current_block["number"], current_block["hash"]), signing_key=signing_key, currency=current_block["currency"], ) @@ -97,7 +97,7 @@ def send_certification(): # prompt entry pubkey_to = input("Enter pubkey to certify: ") - # capture current block to get version and currency and blockstamp + # capture current block to get version and currency and block_id current_block = client(bma.blockchain.current) # create our Identity document to sign the Certification document diff --git a/examples/send_identity.py b/examples/send_identity.py index 3f805c13..9c7b2d3b 100644 --- a/examples/send_identity.py +++ b/examples/send_identity.py @@ -18,7 +18,7 @@ import urllib from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents import BlockUID, Identity +from duniterpy.documents import BlockID, Identity from duniterpy.key import SigningKey # CONFIG ####################################### @@ -47,14 +47,14 @@ def get_identity_document( :rtype: Identity """ - # get current block BlockStamp - timestamp = BlockUID(current_block["number"], current_block["hash"]) + # get current BlockID + block_id = BlockID(current_block["number"], current_block["hash"]) # create identity document identity = Identity( pubkey=key.pubkey, uid=uid, - timestamp=timestamp, + block_id=block_id, signing_key=key, currency=current_block["currency"], ) @@ -73,7 +73,7 @@ def send_identity(): response = client(bma.node.summary) print(response) - # capture current block to get version and currency and blockstamp + # capture current block to get version and currency and block_id current_block = client(bma.blockchain.current) # prompt entry diff --git a/examples/send_membership.py b/examples/send_membership.py index dfb69f83..b22076a8 100644 --- a/examples/send_membership.py +++ b/examples/send_membership.py @@ -18,7 +18,7 @@ import urllib from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents import BlockUID, Membership +from duniterpy.documents import BlockID, Membership from duniterpy.key import SigningKey # CONFIG ####################################### @@ -49,19 +49,19 @@ def get_membership_document( :rtype: Membership """ - # get current block BlockStamp - timestamp = BlockUID(current_block["number"], current_block["hash"]) + # get current BlockID + block_id = BlockID(current_block["number"], current_block["hash"]) - # get the uid and the timestamp of the corresponding identity + # get the uid and the block_id of the corresponding identity uid = identity["uids"][0]["uid"] - identity_timestamp = identity["uids"][0]["meta"]["timestamp"] + identity_block_id = identity["uids"][0]["meta"]["timestamp"] # create membership document membership = Membership( issuer=key.pubkey, - membership_ts=timestamp, + membership_block_id=block_id, uid=uid, - identity_ts=identity_timestamp, + identity_block_id=identity_block_id, signing_key=key, currency=current_block["currency"], membership_type=membership_type, @@ -81,7 +81,7 @@ def send_membership(): response = client(bma.node.summary) print(response) - # capture current block to get version and currency and blockstamp + # capture current block to get version and currency and block_id current_block = client(bma.blockchain.current) # prompt hidden user entry diff --git a/examples/send_transaction.py b/examples/send_transaction.py index 1ddf631b..afa6ab3c 100644 --- a/examples/send_transaction.py +++ b/examples/send_transaction.py @@ -19,7 +19,7 @@ from typing import List, Union from duniterpy.api import bma from duniterpy.api.client import Client -from duniterpy.documents import BlockUID, Transaction +from duniterpy.documents import BlockID, Transaction from duniterpy.documents.transaction import ( InputSource, OutputSource, @@ -90,7 +90,7 @@ def get_transaction_document( ] transaction = Transaction( - blockstamp=BlockUID(current_block["number"], current_block["hash"]), + block_id=BlockID(current_block["number"], current_block["hash"]), locktime=0, issuers=issuers, inputs=inputs, @@ -128,7 +128,7 @@ def send_transaction(): # prompt entry pubkey_to = input("Enter recipient pubkey: ") - # capture current block to get version and currency and blockstamp + # capture current block to get version and currency and block_id current_block = client(bma.blockchain.current) # capture sources of account diff --git a/tests/api/ws2p/test_ws2p.py b/tests/api/ws2p/test_ws2p.py index 45761b97..94d6ef59 100644 --- a/tests/api/ws2p/test_ws2p.py +++ b/tests/api/ws2p/test_ws2p.py @@ -26,7 +26,7 @@ from duniterpy.api.ws2p.requests import ( ERROR_RESPONSE_SCHEMA, REQUIREMENTS_RESPONSE_SCHEMA, ) -from duniterpy.documents import BlockUID, Identity +from duniterpy.documents import BlockID, Identity from duniterpy.documents.ws2p.messages import DocumentMessage @@ -190,7 +190,7 @@ class TestWs2p(unittest.TestCase): identity_document = Identity( "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd", "lolcat", - BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), + BlockID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), version=10, currency="beta_brousouf", ) diff --git a/tests/documents/test_block.py b/tests/documents/test_block.py index b2639e20..e51bafee 100644 --- a/tests/documents/test_block.py +++ b/tests/documents/test_block.py @@ -17,7 +17,7 @@ import json import unittest from duniterpy.documents.block import Block -from duniterpy.documents.block_uid import BlockUID, block_uid +from duniterpy.documents.block_id import BlockID, get_block_id from duniterpy.key.signing_key import SigningKey raw_block = """Version: 11 @@ -1861,11 +1861,11 @@ class TestBlock(unittest.TestCase): self.assertEqual(block.signed_raw(), raw_block_with_leavers) - def test_block_uid__compare(self): - lower = BlockUID( + def test_block_id__compare(self): + lower = BlockID( 10, "8101618234DBE5AAD529C13C8BE45E2F9BBE1150CD2FAA25095671F56C1DCDA5" ) - higher = BlockUID( + higher = BlockID( 14, "E1C0AD728983D8A57335E52CF1064F1AFFD1D454173D8CEBD3ED8B4A72B48704" ) self.assertTrue(lower < higher) @@ -1884,8 +1884,8 @@ class TestBlock(unittest.TestCase): from_rendered_raw = block.from_signed_raw(rendered_raw) self.assertEqual(from_rendered_raw.signed_raw(), negative_issuers_frame_var) - def test_block_uid_converter(self): - buid = block_uid( + def test_block_id_converter(self): + buid = get_block_id( "1345-0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0" ) self.assertEqual(buid.number, 1345) @@ -1894,30 +1894,30 @@ class TestBlock(unittest.TestCase): "0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0", ) - def test_block_uid_converter_error(self): + def test_block_id_converter_error(self): with self.assertRaises(TypeError): - block_uid(1235654) + get_block_id(1235654) - def test_block_uid_no_convert(self): - buid = block_uid( - BlockUID( + def test_block_id_no_convert(self): + block_id = get_block_id( + BlockID( 1345, "0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0" ) ) - self.assertEqual(buid.number, 1345) + self.assertEqual(block_id.number, 1345) self.assertEqual( - buid.sha_hash, + block_id.sha_hash, "0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0", ) - def test_block_uid_non_zero(self): - buid = BlockUID( + def test_block_id_non_zero(self): + block_id = BlockID( 1345, "0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0" ) - if not buid: + if not block_id: self.fail("__nonzero__ comparison failed") - elif BlockUID.empty(): - self.fail("Empty blockuid __nonzero__ comparison failed") + elif BlockID.empty(): + self.fail("Empty block_id __nonzero__ comparison failed") def test_proof_of_work(self): block = """Version: 11 @@ -1969,7 +1969,7 @@ AywstQpC0S5iaA/YQvbz2alpP6zTYG3tjkWpxy1jgeCo028Te2V327bBZbfDGDzsjxOrF4UVmEBiGsgb parsed_json_block = json.loads(json_block_250004) block = Block.from_parsed_json(parsed_json_block) self.assertEqual(len(block.transactions), 8) - self.assertEqual(block.transactions[5].blockstamp.number, 250002) + self.assertEqual(block.transactions[5].block_id.number, 250002) self.assertEqual( block.transactions[5].comment, "Merci pour la farine de chataigne" ) diff --git a/tests/documents/test_certification.py b/tests/documents/test_certification.py index a4f6b40e..94ee5365 100644 --- a/tests/documents/test_certification.py +++ b/tests/documents/test_certification.py @@ -16,7 +16,7 @@ import unittest from duniterpy.constants import EMPTY_HASH -from duniterpy.documents.block import BlockUID +from duniterpy.documents.block import BlockID from duniterpy.documents.certification import Certification from duniterpy.documents.identity import Identity from duniterpy.documents.revocation import Revocation @@ -56,7 +56,7 @@ class TestCertification(unittest.TestCase): "h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==", ) self.assertEqual( - str(selfcert.timestamp), "32-DB30D958EE5CB75186972286ED3F4686B8A1C2CD" + str(selfcert.block_id), "32-DB30D958EE5CB75186972286ED3F4686B8A1C2CD" ) self.assertEqual(selfcert.uid, "lolcat") @@ -69,7 +69,7 @@ class TestCertification(unittest.TestCase): "Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==", ) self.assertEqual( - str(selfcert.timestamp), "36-1076F10A7397715D2BEE82579861999EA1F274AC" + str(selfcert.block_id), "36-1076F10A7397715D2BEE82579861999EA1F274AC" ) self.assertEqual(selfcert.uid, "lolmouse") @@ -78,10 +78,10 @@ class TestCertification(unittest.TestCase): currency = "beta_brousouf" issuer = "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd" uid = "lolcat" - timestamp = BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD") + block_id = BlockID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD") signature = "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci" - selfcert = Identity(issuer, uid, timestamp, version=version, currency=currency) + selfcert = Identity(issuer, uid, block_id, version=version, currency=currency) selfcert.signature = signature result = """Version: 2 @@ -105,8 +105,8 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf cert.pubkey_from, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" ) self.assertEqual(cert.pubkey_to, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk") - self.assertEqual(cert.timestamp.number, 0) - self.assertEqual(cert.timestamp.sha_hash, EMPTY_HASH) + self.assertEqual(cert.block_id.number, 0) + self.assertEqual(cert.block_id.sha_hash, EMPTY_HASH) self.assertEqual( cert.signature, "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==", @@ -122,9 +122,9 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf cert.pubkey_from, "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y" ) self.assertEqual(cert.pubkey_to, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU") - self.assertEqual(cert.timestamp.number, 12) + self.assertEqual(cert.block_id.number, 12) self.assertEqual( - cert.timestamp.sha_hash, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD" + cert.block_id.sha_hash, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD" ) self.assertEqual( cert.signature, @@ -136,19 +136,19 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf currency = "beta_brousouf" pubkey_from = "DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV" pubkey_to = "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd" - timestamp = BlockUID(36, "1076F10A7397715D2BEE82579861999EA1F274AC") + block_id = BlockID(36, "1076F10A7397715D2BEE82579861999EA1F274AC") signature = "SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneNYSMV3rk" identity = Identity( pubkey_to, "lolcat", - BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), + BlockID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), version=version, currency=currency, ) identity.signature = "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci" certification = Certification( - pubkey_from, identity, timestamp, version=version, currency=currency + pubkey_from, identity, block_id, version=version, currency=currency ) certification.signature = signature @@ -190,7 +190,7 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN identity = Identity( pubkey, "lolcat", - BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), + BlockID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), version=version, currency=currency, ) diff --git a/tests/documents/test_membership.py b/tests/documents/test_membership.py index 12b50e14..edadb065 100644 --- a/tests/documents/test_membership.py +++ b/tests/documents/test_membership.py @@ -41,14 +41,15 @@ class TestMembership(unittest.TestCase): self.assertEqual( membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" ) - self.assertEqual(membership.membership_ts.number, 0) + self.assertEqual(membership.membership_block_id.number, 0) self.assertEqual( - membership.membership_ts.sha_hash, + membership.membership_block_id.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", ) - self.assertEqual(membership.identity_ts.number, 0) + self.assertEqual(membership.identity_block_id.number, 0) self.assertEqual( - membership.identity_ts.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" + membership.identity_block_id.sha_hash, + "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", ) self.assertEqual(membership.uid, "cgeek") self.assertEqual( @@ -62,14 +63,15 @@ class TestMembership(unittest.TestCase): self.assertEqual( membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" ) - self.assertEqual(membership.membership_ts.number, 0) + self.assertEqual(membership.membership_block_id.number, 0) self.assertEqual( - membership.membership_ts.sha_hash, + membership.membership_block_id.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", ) - self.assertEqual(membership.identity_ts.number, 0) + self.assertEqual(membership.identity_block_id.number, 0) self.assertEqual( - membership.identity_ts.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" + membership.identity_block_id.sha_hash, + "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", ) self.assertEqual(membership.uid, "cgeek") self.assertEqual( @@ -86,14 +88,15 @@ class TestMembership(unittest.TestCase): from_rendered_membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk", ) - self.assertEqual(from_rendered_membership.membership_ts.number, 0) + self.assertEqual(from_rendered_membership.membership_block_id.number, 0) self.assertEqual( - from_rendered_membership.membership_ts.sha_hash, + from_rendered_membership.membership_block_id.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", ) - self.assertEqual(membership.identity_ts.number, 0) + self.assertEqual(membership.identity_block_id.number, 0) self.assertEqual( - membership.identity_ts.sha_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" + membership.identity_block_id.sha_hash, + "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", ) self.assertEqual(from_rendered_membership.uid, "cgeek") self.assertEqual( diff --git a/tests/documents/test_peer.py b/tests/documents/test_peer.py index 62374b34..00da8039 100644 --- a/tests/documents/test_peer.py +++ b/tests/documents/test_peer.py @@ -49,7 +49,7 @@ class TestPeer(unittest.TestCase): self.assertEqual(peer.currency, "beta_brousouf") self.assertEqual(peer.pubkey, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY") self.assertEqual( - str(peer.blockUID), "8-1922C324ABC4AF7EF7656734A31F5197888DDD52" + str(peer.block_id), "8-1922C324ABC4AF7EF7656734A31F5197888DDD52" ) self.assertEqual(len(peer.endpoints), 4) self.assertIsInstance(peer.endpoints[0], BMAEndpoint) @@ -86,7 +86,7 @@ class TestPeer(unittest.TestCase): from_rendered_peer.pubkey, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY" ) self.assertEqual( - str(from_rendered_peer.blockUID), + str(from_rendered_peer.block_id), "8-1922C324ABC4AF7EF7656734A31F5197888DDD52", ) self.assertEqual(len(peer.endpoints), 4) diff --git a/tests/documents/test_transaction.py b/tests/documents/test_transaction.py index 4cf2ead0..b1baa85e 100644 --- a/tests/documents/test_transaction.py +++ b/tests/documents/test_transaction.py @@ -18,7 +18,7 @@ import unittest import pypeg2 from duniterpy.constants import G1_TEST_CURRENCY_CODENAME -from duniterpy.documents import BlockUID +from duniterpy.documents import BlockID from duniterpy.documents.transaction import ( InputSource, OutputSource, @@ -301,9 +301,9 @@ class TestTransaction(unittest.TestCase): self.assertEqual(tx.version, 10) self.assertEqual(tx.currency, "beta_brousouf") - self.assertEqual(tx.blockstamp.number, 32) + self.assertEqual(tx.block_id.number, 32) self.assertEqual( - tx.blockstamp.sha_hash, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD" + tx.block_id.sha_hash, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD" ) self.assertEqual(len(tx.issuers), 3) self.assertEqual(len(tx.inputs), 6) @@ -465,7 +465,7 @@ class TestTransaction(unittest.TestCase): def test_transaction_document_generation(self): transaction = Transaction( - blockstamp=BlockUID( + block_id=BlockID( 8979, "000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC" ), locktime=0, @@ -498,7 +498,7 @@ class TestTransaction(unittest.TestCase): ] transaction = Transaction( - blockstamp=BlockUID( + block_id=BlockID( 8979, "000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC" ), locktime=0, diff --git a/tests/documents/test_ws2p_heads.py b/tests/documents/test_ws2p_heads.py index 8b79ac15..e517d065 100644 --- a/tests/documents/test_ws2p_heads.py +++ b/tests/documents/test_ws2p_heads.py @@ -15,7 +15,7 @@ import unittest -from duniterpy.documents.ws2p.heads import BlockUID, HeadV0, HeadV1, HeadV2 +from duniterpy.documents.ws2p.heads import BlockID, HeadV0, HeadV1, HeadV2 headv1_clear = "" @@ -35,8 +35,8 @@ class TestWS2PHeads(unittest.TestCase): self.assertEqual(headv0.head.version, 0) self.assertEqual(headv0.pubkey, "3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj") self.assertEqual( - headv0.blockstamp, - BlockUID.from_str( + headv0.block_id, + BlockID.from_str( "54813-00000A24802B33B71A91B6E990038C145A4815A45C71E57B2F2EF393183C7E2C" ), ) -- GitLab