diff --git a/src/sakia/data/entities/blockchain.py b/src/sakia/data/entities/blockchain.py index 28de6a987a75b8244af1168583399133c040f664..ed5722cd5574725704ac1187e250d79b7be77af2 100644 --- a/src/sakia/data/entities/blockchain.py +++ b/src/sakia/data/entities/blockchain.py @@ -5,45 +5,45 @@ from duniterpy.documents import block_uid, BlockUID @attr.s(hash=False) class BlockchainParameters: # The decimal percent growth of the UD every [dt] period - c = attr.ib(convert=float, default=0, cmp=False, hash=False) + c = attr.ib(converter=float, default=0, cmp=False, hash=False) # Time period between two UD in seconds - dt = attr.ib(convert=int, default=0, cmp=False, hash=False) + dt = attr.ib(converter=int, default=0, cmp=False, hash=False) # UD(0), i.e. initial Universal Dividend - ud0 = attr.ib(convert=int, default=0, cmp=False, hash=False) + ud0 = attr.ib(converter=int, default=0, cmp=False, hash=False) # Minimum delay between 2 certifications of a same issuer, in seconds. Must be positive or zero - sig_period = attr.ib(convert=int, default=0, cmp=False, hash=False) + sig_period = attr.ib(converter=int, default=0, cmp=False, hash=False) # Maximum quantity of active certifications made by member - sig_stock = attr.ib(convert=int, default=0, cmp=False, hash=False) + sig_stock = attr.ib(converter=int, default=0, cmp=False, hash=False) # Maximum age of a active signature (in seconds) - sig_validity = attr.ib(convert=int, default=0, cmp=False, hash=False) + sig_validity = attr.ib(converter=int, default=0, cmp=False, hash=False) # Minimum quantity of signatures to be part of the WoT - sig_qty = attr.ib(convert=int, default=0, cmp=False, hash=False) + sig_qty = attr.ib(converter=int, default=0, cmp=False, hash=False) # Maximum delay in seconds a certification can wait before being expired for non-writing - sig_window = attr.ib(convert=int, default=0, cmp=False, hash=False) + sig_window = attr.ib(converter=int, default=0, cmp=False, hash=False) # Maximum delay in seconds an identity can wait before being expired for non-writing - idty_window = attr.ib(convert=int, default=0, cmp=False, hash=False) + idty_window = attr.ib(converter=int, default=0, cmp=False, hash=False) # Maximum delay in seconds a membership can wait before being expired for non-writing - ms_window = attr.ib(convert=int, default=0, cmp=False, hash=False) + ms_window = attr.ib(converter=int, default=0, cmp=False, hash=False) # Minimum decimal percent of sentries to reach to match the distance rule - xpercent = attr.ib(convert=float, default=0, cmp=False, hash=False) + xpercent = attr.ib(converter=float, default=0, cmp=False, hash=False) # Maximum age of an active membership( in seconds) - ms_validity = attr.ib(convert=int, default=0, cmp=False, hash=False) + ms_validity = attr.ib(converter=int, default=0, cmp=False, hash=False) # Maximum distance between each WoT member and a newcomer - step_max = attr.ib(convert=int, default=0, cmp=False, hash=False) + step_max = attr.ib(converter=int, default=0, cmp=False, hash=False) # Number of blocks used for calculating median time - median_time_blocks = attr.ib(convert=int, default=0, cmp=False, hash=False) + median_time_blocks = attr.ib(converter=int, default=0, cmp=False, hash=False) # The average time for writing 1 block (wished time) in seconds - avg_gen_time = attr.ib(convert=int, default=0, cmp=False, hash=False) + avg_gen_time = attr.ib(converter=int, default=0, cmp=False, hash=False) # The number of blocks required to evaluate again PoWMin value - dt_diff_eval = attr.ib(convert=int, default=0, cmp=False, hash=False) + dt_diff_eval = attr.ib(converter=int, default=0, cmp=False, hash=False) # The decimal percent of previous issuers to reach for personalized difficulty - percent_rot = attr.ib(convert=float, default=0, cmp=False, hash=False) + percent_rot = attr.ib(converter=float, default=0, cmp=False, hash=False) # The first UD time - ud_time_0 = attr.ib(convert=int, default=0, cmp=False, hash=False) + ud_time_0 = attr.ib(converter=int, default=0, cmp=False, hash=False) # The first UD reavallued - ud_reeval_time_0 = attr.ib(convert=int, default=0, cmp=False, hash=False) + ud_reeval_time_0 = attr.ib(converter=int, default=0, cmp=False, hash=False) # The dt recomputation of the ud - dt_reeval = attr.ib(convert=int, default=0, cmp=False, hash=False) + dt_reeval = attr.ib(converter=int, default=0, cmp=False, hash=False) @attr.s(hash=True) @@ -51,32 +51,32 @@ class Blockchain: # Parameters in block 0 parameters = attr.ib(default=BlockchainParameters(), cmp=False, hash=False) # block number and hash - current_buid = attr.ib(convert=block_uid, default=BlockUID.empty()) + current_buid = attr.ib(converter=block_uid, default=BlockUID.empty()) # Number of members - current_members_count = attr.ib(convert=int, default=0, cmp=False, hash=False) + current_members_count = attr.ib(converter=int, default=0, cmp=False, hash=False) # Current monetary mass in units - current_mass = attr.ib(convert=int, default=0, cmp=False, hash=False) + current_mass = attr.ib(converter=int, default=0, cmp=False, hash=False) # Median time in seconds - median_time = attr.ib(convert=int, default=0, cmp=False, hash=False) + median_time = attr.ib(converter=int, default=0, cmp=False, hash=False) # Last members count - last_mass = attr.ib(convert=int, default=0, cmp=False, hash=False) + last_mass = attr.ib(converter=int, default=0, cmp=False, hash=False) # Last members count - last_members_count = attr.ib(convert=int, default=0, cmp=False, hash=False) + last_members_count = attr.ib(converter=int, default=0, cmp=False, hash=False) # Last UD amount in units (multiply by 10^base) - last_ud = attr.ib(convert=int, default=1, cmp=False, hash=False) + last_ud = attr.ib(converter=int, default=1, cmp=False, hash=False) # Last UD base - last_ud_base = attr.ib(convert=int, default=0, cmp=False, hash=False) + last_ud_base = attr.ib(converter=int, default=0, cmp=False, hash=False) # Last UD base - last_ud_time = attr.ib(convert=int, default=0, cmp=False, hash=False) + last_ud_time = attr.ib(converter=int, default=0, cmp=False, hash=False) # Previous monetary mass in units - previous_mass = attr.ib(convert=int, default=0, cmp=False, hash=False) + previous_mass = attr.ib(converter=int, default=0, cmp=False, hash=False) # Previous members count - previous_members_count = attr.ib(convert=int, default=0, cmp=False, hash=False) + previous_members_count = attr.ib(converter=int, default=0, cmp=False, hash=False) # Previous UD amount in units (multiply by 10^base) - previous_ud = attr.ib(convert=int, default=0, cmp=False, hash=False) + previous_ud = attr.ib(converter=int, default=0, cmp=False, hash=False) # Previous UD base - previous_ud_base = attr.ib(convert=int, default=0, cmp=False, hash=False) + previous_ud_base = attr.ib(converter=int, default=0, cmp=False, hash=False) # Previous UD base - previous_ud_time = attr.ib(convert=int, default=0, cmp=False, hash=False) + previous_ud_time = attr.ib(converter=int, default=0, cmp=False, hash=False) # Currency name - currency = attr.ib(convert=str, default="", cmp=False, hash=False) + currency = attr.ib(converter=str, default="", cmp=False, hash=False) diff --git a/src/sakia/data/entities/certification.py b/src/sakia/data/entities/certification.py index 3e7c7d9a9b7dece178faf4a9f74629b037d33d96..b13d8d8605959d6a0982e8d2ff8f8878ba839d2b 100644 --- a/src/sakia/data/entities/certification.py +++ b/src/sakia/data/entities/certification.py @@ -4,10 +4,10 @@ from duniterpy.documents import block_uid, BlockUID @attr.s(hash=True) class Certification: - currency = attr.ib(convert=str) - certifier = attr.ib(convert=str) - certified = attr.ib(convert=str) - block = attr.ib(convert=int) - timestamp = attr.ib(convert=int, cmp=False) - signature = attr.ib(convert=str, cmp=False, hash=False) - written_on = attr.ib(convert=int, default=-1, cmp=False, hash=False) + currency = attr.ib(converter=str) + certifier = attr.ib(converter=str) + certified = attr.ib(converter=str) + block = attr.ib(converter=int) + timestamp = attr.ib(converter=int, cmp=False) + signature = attr.ib(converter=str, cmp=False, hash=False) + written_on = attr.ib(converter=int, default=-1, cmp=False, hash=False) diff --git a/src/sakia/data/entities/connection.py b/src/sakia/data/entities/connection.py index c7d655f17cb2d65bfd3ca5fdaad649c9cc5c76f9..1f87c0ef652be85928c0f0a3a7bef13fd7cc015c 100644 --- a/src/sakia/data/entities/connection.py +++ b/src/sakia/data/entities/connection.py @@ -11,17 +11,17 @@ class Connection: used to connect to it. If the user is using an identity, it is defined here too. """ - currency = attr.ib(convert=str) - pubkey = attr.ib(convert=str) - uid = attr.ib(convert=str, default="", cmp=False, hash=False) - scrypt_N = attr.ib(convert=int, default=4096, cmp=False, hash=False) - scrypt_r = attr.ib(convert=int, default=16, cmp=False, hash=False) - scrypt_p = attr.ib(convert=int, default=1, cmp=False, hash=False) + currency = attr.ib(converter=str) + pubkey = attr.ib(converter=str) + uid = attr.ib(converter=str, default="", cmp=False, hash=False) + scrypt_N = attr.ib(converter=int, default=4096, cmp=False, hash=False) + scrypt_r = attr.ib(converter=int, default=16, cmp=False, hash=False) + scrypt_p = attr.ib(converter=int, default=1, cmp=False, hash=False) blockstamp = attr.ib( - convert=block_uid, default=BlockUID.empty(), cmp=False, hash=False + converter=block_uid, default=BlockUID.empty(), cmp=False, hash=False ) - salt = attr.ib(convert=str, init=False, default="", cmp=False, hash=False) - password = attr.ib(init=False, convert=str, default="", cmp=False, hash=False) + salt = attr.ib(converter=str, init=False, default="", cmp=False, hash=False) + password = attr.ib(init=False, converter=str, default="", cmp=False, hash=False) def is_identity(self): return self.uid is not "" diff --git a/src/sakia/data/entities/contact.py b/src/sakia/data/entities/contact.py index 06152ee16a7664c9aaff253b5ffddfe5d24a8d9b..9d6e294c18165a4dc046906a8a70aefa8a8c4a0f 100644 --- a/src/sakia/data/entities/contact.py +++ b/src/sakia/data/entities/contact.py @@ -11,11 +11,11 @@ class Contact: re_displayed_text = re.compile("([\w\s\d]+) < ((?![OIl])[1-9A-Za-z]{42,45}) >") - currency = attr.ib(convert=str) - name = attr.ib(convert=str) - pubkey = attr.ib(convert=str) - fields = attr.ib(convert=attrs_tuple_of_str, default="") - contact_id = attr.ib(convert=int, default=-1) + currency = attr.ib(converter=str) + name = attr.ib(converter=str) + pubkey = attr.ib(converter=str) + fields = attr.ib(converter=attrs_tuple_of_str, default="") + contact_id = attr.ib(converter=int, default=-1) def displayed_text(self): return self.name + " < " + self.pubkey + " > " diff --git a/src/sakia/data/entities/dividend.py b/src/sakia/data/entities/dividend.py index 9aa7f6d43d238af61bd0c0c6567dc8e5f3d006f7..020f8da73ac32c09f51e3ef736f203e1de04962d 100644 --- a/src/sakia/data/entities/dividend.py +++ b/src/sakia/data/entities/dividend.py @@ -3,9 +3,9 @@ import attr @attr.s(hash=True) class Dividend: - currency = attr.ib(convert=str, cmp=True, hash=True) - pubkey = attr.ib(convert=str, cmp=True, hash=True) - block_number = attr.ib(convert=int, cmp=True, hash=True) - timestamp = attr.ib(convert=int) - amount = attr.ib(convert=int, cmp=False, hash=False) - base = attr.ib(convert=int, cmp=False, hash=False) + currency = attr.ib(converter=str, cmp=True, hash=True) + pubkey = attr.ib(converter=str, cmp=True, hash=True) + block_number = attr.ib(converter=int, cmp=True, hash=True) + timestamp = attr.ib(converter=int) + amount = attr.ib(converter=int, cmp=False, hash=False) + base = attr.ib(converter=int, cmp=False, hash=False) diff --git a/src/sakia/data/entities/identity.py b/src/sakia/data/entities/identity.py index e14bdb267fabc82d70c5f6c04e91ce4749320d46..d42b341088ef16b4c1282d7cd649bb8debb63fca 100644 --- a/src/sakia/data/entities/identity.py +++ b/src/sakia/data/entities/identity.py @@ -5,16 +5,16 @@ from duniterpy.documents import Identity as IdentityDoc @attr.s(hash=True) class Identity: - currency = attr.ib(convert=str) - pubkey = attr.ib(convert=str) - uid = attr.ib(convert=str, default="") - blockstamp = attr.ib(convert=block_uid, default=BlockUID.empty()) - signature = attr.ib(convert=str, default="", cmp=False, hash=False) + currency = attr.ib(converter=str) + pubkey = attr.ib(converter=str) + uid = attr.ib(converter=str, default="") + blockstamp = attr.ib(converter=block_uid, default=BlockUID.empty()) + signature = attr.ib(converter=str, default="", cmp=False, hash=False) # Mediantime of the block referenced by blockstamp - timestamp = attr.ib(convert=int, default=0, cmp=False, hash=False) - written = attr.ib(convert=bool, default=False, cmp=False, hash=False) - revoked_on = attr.ib(convert=int, default=0, cmp=False, hash=False) - outdistanced = attr.ib(convert=bool, default=True, cmp=False, hash=False) + timestamp = attr.ib(converter=int, default=0, cmp=False, hash=False) + written = attr.ib(converter=bool, default=False, cmp=False, hash=False) + revoked_on = attr.ib(converter=int, default=0, cmp=False, hash=False) + outdistanced = attr.ib(converter=bool, default=True, cmp=False, hash=False) member = attr.ib( validator=attr.validators.instance_of(bool), default=False, @@ -22,18 +22,18 @@ class Identity: hash=False, ) membership_buid = attr.ib( - convert=block_uid, default=BlockUID.empty(), cmp=False, hash=False + converter=block_uid, default=BlockUID.empty(), cmp=False, hash=False ) - membership_timestamp = attr.ib(convert=int, default=0, cmp=False, hash=False) + membership_timestamp = attr.ib(converter=int, default=0, cmp=False, hash=False) membership_type = attr.ib( - convert=str, + converter=str, default="", validator=lambda s, a, t: t in ("", "IN", "OUT"), cmp=False, hash=False, ) - membership_written_on = attr.ib(convert=int, default=0, cmp=False, hash=False) - sentry = attr.ib(convert=bool, default=False, cmp=False, hash=False) + membership_written_on = attr.ib(converter=int, default=0, cmp=False, hash=False) + sentry = attr.ib(converter=bool, default=False, cmp=False, hash=False) def document(self): """ diff --git a/src/sakia/data/entities/node.py b/src/sakia/data/entities/node.py index 779a9f0a1c2fa5adb1a3e3a2fb32432d02048e06..aae5c01e04a30b75c683056f0d0e9b8cb6e102db 100644 --- a/src/sakia/data/entities/node.py +++ b/src/sakia/data/entities/node.py @@ -42,38 +42,38 @@ class Node: return self.state <= Node.FAILURE_THRESHOLD # The currency handled by this node - currency = attr.ib(convert=str) + currency = attr.ib(converter=str) # The pubkey of the node - pubkey = attr.ib(convert=str) + pubkey = attr.ib(converter=str) # The endpoints of the node, in a list of Endpoint objects format - endpoints = attr.ib(convert=_tuple_of_endpoints, cmp=False, hash=False) + endpoints = attr.ib(converter=_tuple_of_endpoints, cmp=False, hash=False) # The previous block uid in /blockchain/current - peer_blockstamp = attr.ib(convert=block_uid, cmp=False, hash=False) + peer_blockstamp = attr.ib(converter=block_uid, cmp=False, hash=False) # The uid of the owner of node - uid = attr.ib(convert=str, cmp=False, default="", hash=False) + uid = attr.ib(converter=str, cmp=False, default="", hash=False) # The current block uid in /blockchain/current - current_buid = attr.ib(convert=block_uid, cmp=False, default=None, hash=False) + current_buid = attr.ib(converter=block_uid, cmp=False, default=None, hash=False) # The current block time in /blockchain/current - current_ts = attr.ib(convert=int, cmp=False, default=0, hash=False) + current_ts = attr.ib(converter=int, cmp=False, default=0, hash=False) # The previous block uid in /blockchain/current - previous_buid = attr.ib(convert=block_uid, cmp=False, default=None, hash=False) + previous_buid = attr.ib(converter=block_uid, cmp=False, default=None, hash=False) # The state of the node in Sakia - state = attr.ib(convert=int, cmp=False, default=0, hash=False) + state = attr.ib(converter=int, cmp=False, default=0, hash=False) # The version of the software in /node/summary - software = attr.ib(convert=str, cmp=False, default="", hash=False) + software = attr.ib(converter=str, cmp=False, default="", hash=False) # The version of the software in /node/summary - version = attr.ib(convert=str, cmp=False, default="", hash=False) + version = attr.ib(converter=str, cmp=False, default="", hash=False) # Root of the merkle peers tree, default = sha256 of empty string merkle_peers_root = attr.ib( - convert=str, cmp=False, default=MERKLE_EMPTY_ROOT, hash=False + converter=str, cmp=False, default=MERKLE_EMPTY_ROOT, hash=False ) # Leaves of the merkle peers tree merkle_peers_leaves = attr.ib( - convert=attrs_tuple_of_str, cmp=False, default=tuple(), hash=False + converter=attrs_tuple_of_str, cmp=False, default=tuple(), hash=False ) # Define if this node is a root node in Sakia - root = attr.ib(convert=bool, cmp=False, default=False, hash=False) + root = attr.ib(converter=bool, cmp=False, default=False, hash=False) # If this node is a member or not - member = attr.ib(convert=bool, cmp=False, default=False, hash=False) + member = attr.ib(converter=bool, cmp=False, default=False, hash=False) # If this node is a member or not - last_state_change = attr.ib(convert=int, cmp=False, default=False, hash=False) + last_state_change = attr.ib(converter=int, cmp=False, default=False, hash=False) diff --git a/src/sakia/data/entities/source.py b/src/sakia/data/entities/source.py index 4c06f0e0f4e8b4a50fb4886fc7347a81f3268c97..f8b0cab1062e73a8e83a8ee80e50d5be7270a299 100644 --- a/src/sakia/data/entities/source.py +++ b/src/sakia/data/entities/source.py @@ -3,10 +3,10 @@ import attr @attr.s(hash=True) class Source: - currency = attr.ib(convert=str) - pubkey = attr.ib(convert=str) - identifier = attr.ib(convert=str) - noffset = attr.ib(convert=int) - type = attr.ib(convert=str, validator=lambda i, a, s: s == "T" or s == "D") - amount = attr.ib(convert=int, hash=False) - base = attr.ib(convert=int, hash=False) + currency = attr.ib(converter=str) + pubkey = attr.ib(converter=str) + identifier = attr.ib(converter=str) + noffset = attr.ib(converter=int) + type = attr.ib(converter=str, validator=lambda i, a, s: s == "T" or s == "D") + amount = attr.ib(converter=int, hash=False) + base = attr.ib(converter=int, hash=False) diff --git a/src/sakia/data/entities/transaction.py b/src/sakia/data/entities/transaction.py index ccffccc113e31a60548e5b207254f999cc7eb2bc..0fdf0e59f591899444a0efb3f7f2e480f5701839 100644 --- a/src/sakia/data/entities/transaction.py +++ b/src/sakia/data/entities/transaction.py @@ -131,22 +131,22 @@ class Transaction: REFUSED = 8 DROPPED = 16 - currency = attr.ib(convert=str, cmp=True, hash=True) - pubkey = attr.ib(convert=str, cmp=True, hash=True) - sha_hash = attr.ib(convert=str, cmp=True, hash=True) - written_block = attr.ib(convert=int, cmp=False) - blockstamp = attr.ib(convert=block_uid, cmp=False) - timestamp = attr.ib(convert=int, cmp=False) - signatures = attr.ib(convert=attrs_tuple_of_str, cmp=False) - issuers = attr.ib(convert=attrs_tuple_of_str, cmp=False) - receivers = attr.ib(convert=attrs_tuple_of_str, cmp=False) - amount = attr.ib(convert=int, cmp=False) - amount_base = attr.ib(convert=int, cmp=False) - comment = attr.ib(convert=str, cmp=False) - txid = attr.ib(convert=int, cmp=False) - state = attr.ib(convert=int, cmp=False) - local = attr.ib(convert=bool, cmp=False, default=False) - raw = attr.ib(convert=str, cmp=False, default="") + currency = attr.ib(converter=str, cmp=True, hash=True) + pubkey = attr.ib(converter=str, cmp=True, hash=True) + sha_hash = attr.ib(converter=str, cmp=True, hash=True) + written_block = attr.ib(converter=int, cmp=False) + blockstamp = attr.ib(converter=block_uid, cmp=False) + timestamp = attr.ib(converter=int, cmp=False) + signatures = attr.ib(converter=attrs_tuple_of_str, cmp=False) + issuers = attr.ib(converter=attrs_tuple_of_str, cmp=False) + receivers = attr.ib(converter=attrs_tuple_of_str, cmp=False) + amount = attr.ib(converter=int, cmp=False) + amount_base = attr.ib(converter=int, cmp=False) + comment = attr.ib(converter=str, cmp=False) + txid = attr.ib(converter=int, cmp=False) + state = attr.ib(converter=int, cmp=False) + local = attr.ib(converter=bool, cmp=False, default=False) + raw = attr.ib(converter=str, cmp=False, default="") def txdoc(self): """ diff --git a/src/sakia/data/entities/user_parameters.py b/src/sakia/data/entities/user_parameters.py index ee72a98643b4e27c355964bc5aa12e7a203c1f64..44415832d4fd7001630d1c10384d955391932d3e 100644 --- a/src/sakia/data/entities/user_parameters.py +++ b/src/sakia/data/entities/user_parameters.py @@ -7,20 +7,20 @@ class UserParameters: The user parameters entity """ - profile_name = attr.ib(convert=str, default="Default Profile") - lang = attr.ib(convert=str, default="en") - referential = attr.ib(convert=int, default=0) - expert_mode = attr.ib(convert=bool, default=False) - digits_after_comma = attr.ib(convert=int, default=2) - maximized = attr.ib(convert=bool, default=False) - notifications = attr.ib(convert=bool, default=True) - enable_proxy = attr.ib(convert=bool, default=False) - proxy_type = attr.ib(convert=int, default=0) - proxy_address = attr.ib(convert=str, default="") - proxy_port = attr.ib(convert=int, default=8080) - proxy_user = attr.ib(convert=str, default="") - proxy_password = attr.ib(convert=str, default="") - dark_theme = attr.ib(convert=bool, default=False) + profile_name = attr.ib(converter=str, default="Default Profile") + lang = attr.ib(converter=str, default="en") + referential = attr.ib(converter=int, default=0) + expert_mode = attr.ib(converter=bool, default=False) + digits_after_comma = attr.ib(converter=int, default=2) + maximized = attr.ib(converter=bool, default=False) + notifications = attr.ib(converter=bool, default=True) + enable_proxy = attr.ib(converter=bool, default=False) + proxy_type = attr.ib(converter=int, default=0) + proxy_address = attr.ib(converter=str, default="") + proxy_port = attr.ib(converter=int, default=8080) + proxy_user = attr.ib(converter=str, default="") + proxy_password = attr.ib(converter=str, default="") + dark_theme = attr.ib(converter=bool, default=False) def proxy(self): if self.enable_proxy is True: