def process_spend(self, spend_block: PlexusBlock) -> None: # Store spend in the database spend_tx = decode_raw(spend_block.transaction) spender = spend_block.public_key self.verify_spend(spender, spend_tx) chain_id = spend_block.com_id spend_dot = spend_block.com_dot pers_links = spend_block.links prev_spend_links = spend_tx.get(b"prev_pairwise_link") value = Decimal(spend_tx.get(b"value"), self.context) to_peer = spend_tx.get(b"to_peer") seq_num = spend_dot[0] self.state_db.apply_spend( chain_id, prev_spend_links, pers_links, spend_dot, spender, to_peer, value, self.should_store_store_update(chain_id, seq_num), ) # Is this block related to my peer? if to_peer == self.my_pub_key_bin: self.tracked_blocks[spend_block.com_id][ spend_block.com_dot] = spend_block self.add_block_to_response_processing(spend_block)
def from_bytes(cls, bytes_frontier: bytes): front_dict = decode_raw(bytes_frontier) return cls( front_dict.get(b"t"), front_dict.get(b"h"), front_dict.get(b"i"), )
def test_decimal(): new_con = getcontext() new_con.prec = 4 t = Decimal(2.191, new_con) t2 = Decimal(2.11, new_con) l = encode_raw({b"value": float(t2)}) p = decode_raw(l) assert p.get(b"value") == float(t2)
def test_val(self): val = Decimal(10, self.con) l = encode_raw({b"123": float(val)}) d = decode_raw(l) print(d) l = cachetools.LRUCache(10) l[1] = "v" int_max = 9999 k = 4 try: v = min(l.keys(), key=lambda x: abs(x - k) if x >= k else int_max) if v < k: # No data yet: pass except ValueError: print("No data for the chain")
def process_mint(self, mint_blk: PlexusBlock) -> None: """Process received mint transaction""" minter = mint_blk.public_key mint_tx = decode_raw(mint_blk.transaction) chain_id = mint_blk.com_id mint_dot = mint_blk.com_dot prev_links = mint_blk.links self.verify_mint(chain_id, minter, mint_tx) seq_num = mint_dot[0] self.state_db.apply_mint( chain_id, mint_dot, prev_links, minter, Decimal(mint_tx.get(b"value"), self.context), self.should_store_store_update(chain_id, seq_num), )
def unpack_audit_blob(self, audit_blob: bytes) -> Any: """ Returns: decoded audit transaction """ return decode_raw(audit_blob)
def received_block_in_order(self, block: PlexusBlock) -> None: print(block.transaction) decoded_tx = decode_raw(block.transaction) if decoded_tx.get(b"to_peer", None) == self.my_peer.public_key.key_to_bin(): self.add_block_to_response_processing(block)
def confirm_tx_extra_data(self, block: PlexusBlock) -> Dict: return {b"value": decode_raw(block.transaction).get(b"value")}
def from_bytes(cls, bytes_frontier: bytes): val_dict = decode_raw(bytes_frontier) return cls(val_dict.get(b"m"), val_dict.get(b"c"))
def received_peer_subs(self, peer: Peer, payload: SubscriptionsPayload) -> None: subcoms = decode_raw(payload.subcoms) self.process_peer_subscriptions(peer, subcoms)
def introduction_request_callback(self, peer, dist, payload): subcoms = decode_raw(payload.extra_bytes) self.process_peer_subscriptions(peer, subcoms) # TODO: add subscription strategy if self.settings.track_neighbours_chains: self.subscribe_to_subcom(peer.public_key.key_to_bin())
def test_encode_decode_bytelist(): vals = {b"1", b"2", b"3", b"4", b"100", b"10", b"21", b"5"} assert set(decode_raw(encode_raw(list(vals)))) == vals
def test_encode_decode_raw(): vals = {b"id": 42} assert decode_raw(encode_raw(vals))[b"id"] == 42
def process_reject(self, block: PlexusBlock) -> None: reject_tx = decode_raw(block.transaction) self.verify_reject_tx(block.public_key, reject_tx) self.apply_reject_tx(block, reject_tx)
def process_confirm(self, block: PlexusBlock) -> None: confirm_tx = decode_raw(block.transaction) self.verify_confirm_tx(block.public_key, confirm_tx) self.apply_confirm_tx(block, confirm_tx)