def _deserialize_header_data(self, json_data: dict): hash_ = Hash32.fromhex(json_data["hash"]) prev_hash = json_data.get('prevHash') prev_hash = Hash32.fromhex(prev_hash) if prev_hash else None peer_id = json_data.get('leader') peer_id = ExternalAddress.fromhex(peer_id) if peer_id else None signature = json_data.get('signature') signature = Signature.from_base64str(signature) if signature else None next_leader = json_data.get("nextLeader") next_leader = ExternalAddress.fromhex( next_leader) if next_leader else None transactions_hash = json_data["transactionsHash"] transactions_hash = Hash32.fromhex(transactions_hash) receipts_hash = json_data["receiptsHash"] receipts_hash = Hash32.fromhex(receipts_hash) state_hash = json_data["stateHash"] state_hash = Hash32.fromhex(state_hash) reps_hash = json_data["repsHash"] reps_hash = Hash32.fromhex(reps_hash) next_reps_hash = json_data["nextRepsHash"] next_reps_hash = Hash32.fromhex(next_reps_hash) leader_votes_hash = json_data["leaderVotesHash"] leader_votes_hash = Hash32.fromhex(leader_votes_hash) prev_votes_hash = json_data["prevVotesHash"] prev_votes_hash = Hash32.fromhex(prev_votes_hash) height = json_data["height"] height = int(height, 16) timestamp = json_data["timestamp"] timestamp = int(timestamp, 16) return { "hash": hash_, "prev_hash": prev_hash, "height": height, "timestamp": timestamp, "peer_id": peer_id, "signature": signature, "next_leader": next_leader, "transactions_hash": transactions_hash, "receipts_hash": receipts_hash, "state_hash": state_hash, "reps_hash": reps_hash, "next_reps_hash": next_reps_hash, "leader_votes_hash": leader_votes_hash, "prev_votes_hash": prev_votes_hash, "logs_bloom": BloomFilter.fromhex(json_data["logsBloom"]) }
def from_(self, tx_data: dict) -> 'Transaction': tx_data_copied = dict(tx_data) tx_data_copied.pop('method', None) hash = tx_data_copied.pop('tx_hash', None) signature = tx_data_copied.pop('signature', None) timestamp = tx_data_copied.pop('timestamp', None) from_address = tx_data_copied.pop('from', None) to_address = tx_data_copied.pop('to', None) value = tx_data_copied.pop('value', None) fee = tx_data_copied.pop('fee', None) nonce = tx_data_copied.pop('nonce', None) extra = tx_data_copied value = int_fromhex(value) fee = int_fromhex(fee) if nonce is not None: nonce = int_fromstr(nonce) return Transaction( raw_data=tx_data, hash=Hash32.fromhex(hash, ignore_prefix=True, allow_malformed=False), signature=Signature.from_base64str(signature), timestamp=int(timestamp) if timestamp is not None else None, from_address=ExternalAddress.fromhex(from_address, ignore_prefix=False, allow_malformed=True), to_address=ExternalAddress.fromhex(to_address, ignore_prefix=False, allow_malformed=True), value=value, fee=fee, nonce=nonce, extra=extra, )
def _deserialize_header_data(self, json_data: dict): prev_hash = json_data.get('prev_block_hash') prev_hash = Hash32.fromhex(prev_hash, ignore_prefix=True) if prev_hash else None peer_id = json_data.get('peer_id') peer_id = ExternalAddress.fromhex(peer_id) if peer_id else None signature = json_data.get('signature') signature = Signature.from_base64str(signature) if signature else None next_leader = json_data.get("next_leader") next_leader = ExternalAddress.fromhex(next_leader) if next_leader else None return { "hash": Hash32.fromhex(json_data["block_hash"], ignore_prefix=True), "prev_hash": prev_hash, "height": json_data["height"], "timestamp": json_data["time_stamp"], "peer_id": peer_id, "signature": signature, "next_leader": next_leader, "merkle_tree_root_hash": Hash32.fromhex(json_data["merkle_tree_root_hash"], ignore_prefix=True), "commit_state": json_data["commit_state"] }
def _deserialize(cls, data: dict): return { "rep": ExternalAddress.fromhex_address(data["rep"]), "timestamp": int(data["timestamp"], 16), "signature": Signature.from_base64str(data["signature"]) }