From 52d92cb1c4b4740c20102609203024d0340c5ff7 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Mon, 18 Dec 2023 01:56:50 +0800 Subject: [PATCH] feat: adding python module to get validator information --- .gitignore | 3 +- python/address.py | 66 +++++ python/bech32m.py | 137 ++++++++++ python/main.py | 61 +++++ python/network_pb2.py | 52 ++++ python/network_pb2_grpc.py | 99 +++++++ python/pactus/blockchain_pb2.py | 81 ++++++ python/pactus/blockchain_pb2_grpc.py | 363 ++++++++++++++++++++++++++ python/pactus/network_pb2.py | 52 ++++ python/pactus/network_pb2_grpc.py | 99 +++++++ python/pactus/transaction_pb2.py | 64 +++++ python/pactus/transaction_pb2_grpc.py | 264 +++++++++++++++++++ python/pactus/wallet_pb2.py | 46 ++++ python/pactus/wallet_pb2_grpc.py | 198 ++++++++++++++ python/public_key.py | 50 ++++ python/test.py | 15 ++ python/utils.py | 15 ++ 17 files changed, 1664 insertions(+), 1 deletion(-) create mode 100644 python/address.py create mode 100644 python/bech32m.py create mode 100644 python/main.py create mode 100644 python/network_pb2.py create mode 100644 python/network_pb2_grpc.py create mode 100644 python/pactus/blockchain_pb2.py create mode 100644 python/pactus/blockchain_pb2_grpc.py create mode 100644 python/pactus/network_pb2.py create mode 100644 python/pactus/network_pb2_grpc.py create mode 100644 python/pactus/transaction_pb2.py create mode 100644 python/pactus/transaction_pb2_grpc.py create mode 100644 python/pactus/wallet_pb2.py create mode 100644 python/pactus/wallet_pb2_grpc.py create mode 100644 python/public_key.py create mode 100644 python/test.py create mode 100644 python/utils.py diff --git a/.gitignore b/.gitignore index faacc4b2..155658dd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ pactus-* cmd/data/wallet.json cmd/data/config.json cmd/data/validators.json -cmd/bin \ No newline at end of file +cmd/bin +__pycache__ \ No newline at end of file diff --git a/python/address.py b/python/address.py new file mode 100644 index 00000000..8e9c0755 --- /dev/null +++ b/python/address.py @@ -0,0 +1,66 @@ +import io +from enum import Enum +import utils + +# Address format: hrp + `1` + type + data + checksum + + +class AddressType(Enum): + Treasury = 0 + Validator = 1 + BLSAccount = 2 + + +AddressSize = 21 +TreasuryAddressString = "000000000000000000000000000000000000000000" +AddressHRP = "tpc" + + +class Address: + def __init__(self, address_type, data): + if len(data) != AddressSize - 1: + raise ValueError("Data must be 21 bytes long") + + self.data = bytearray() + self.data.append(address_type.value) + self.data.extend(data) + + @classmethod + def from_string(cls, text): + if text == TreasuryAddressString: + return bytes([0]) + + hrp, typ, data = utils.decode_to_base256_with_type(text) + if hrp != AddressHRP: + raise ValueError(f"Invalid HRP: {hrp}") + + typ = AddressType(typ) + if typ in (AddressType.Validator, AddressType.BLSAccount): + if len(data) != 20: + raise ValueError(f"Invalid length: {len(data) + 1}") + else: + raise ValueError(f"Invalid address type: {typ}") + + return cls(typ, data) + + def bytes(self): + return bytes(self.data) + + def string(self): + if self.data == bytes([0]): + return TreasuryAddressString + + return utils.encode_from_base256_with_type(AddressHRP, self.data[0], self.data[1:]) + + def address_type(self): + return AddressType(self.data[0]) + + def is_treasury_address(self): + return self.address_type() == AddressType.Treasury + + def is_account_address(self): + t = self.address_type() + return t in (AddressType.Treasury, AddressType.BLSAccount) + + def is_validator_address(self): + return self.address_type() == AddressType.Validator diff --git a/python/bech32m.py b/python/bech32m.py new file mode 100644 index 00000000..5efb63ef --- /dev/null +++ b/python/bech32m.py @@ -0,0 +1,137 @@ +# Copyright (c) 2017, 2020 Pieter Wuille +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +"""Reference implementation for Bech32/Bech32m and segwit addresses.""" + + +from enum import Enum + +class Encoding(Enum): + """Enumeration type to list the various supported encodings.""" + BECH32 = 1 + BECH32M = 2 + +CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" +BECH32M_CONST = 0x2bc830a3 + +def bech32_polymod(values): + """Internal function that computes the Bech32 checksum.""" + generator = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3] + chk = 1 + for value in values: + top = chk >> 25 + chk = (chk & 0x1ffffff) << 5 ^ value + for i in range(5): + chk ^= generator[i] if ((top >> i) & 1) else 0 + return chk + + +def bech32_hrp_expand(hrp): + """Expand the HRP into values for checksum computation.""" + return [ord(x) >> 5 for x in hrp] + [0] + [ord(x) & 31 for x in hrp] + + +def bech32_verify_checksum(hrp, data): + """Verify a checksum given HRP and converted data characters.""" + const = bech32_polymod(bech32_hrp_expand(hrp) + data) + if const == 1: + return Encoding.BECH32 + if const == BECH32M_CONST: + return Encoding.BECH32M + return None + +def bech32_create_checksum(hrp, data, spec): + """Compute the checksum values given HRP and data.""" + values = bech32_hrp_expand(hrp) + data + const = BECH32M_CONST if spec == Encoding.BECH32M else 1 + polymod = bech32_polymod(values + [0, 0, 0, 0, 0, 0]) ^ const + return [(polymod >> 5 * (5 - i)) & 31 for i in range(6)] + + +def bech32_encode(hrp, data, spec): + """Compute a Bech32 string given HRP and data values.""" + combined = data + bech32_create_checksum(hrp, data, spec) + return hrp + '1' + ''.join([CHARSET[d] for d in combined]) + +def bech32_decode(bech): + """Validate a Bech32/Bech32m string, and determine HRP and data.""" + if ((any(ord(x) < 33 or ord(x) > 126 for x in bech)) or + (bech.lower() != bech and bech.upper() != bech)): + return (None, None, None) + bech = bech.lower() + pos = bech.rfind('1') + if pos < 1 or pos + 7 > len(bech): + return (None, None, None) + if not all(x in CHARSET for x in bech[pos+1:]): + return (None, None, None) + hrp = bech[:pos] + data = [CHARSET.find(x) for x in bech[pos+1:]] + spec = bech32_verify_checksum(hrp, data) + if spec is None: + return (None, None, None) + return (hrp, data[:-6], spec) + +def convertbits(data, frombits, tobits, pad=True): + """General power-of-2 base conversion.""" + acc = 0 + bits = 0 + ret = [] + maxv = (1 << tobits) - 1 + max_acc = (1 << (frombits + tobits - 1)) - 1 + for value in data: + if value < 0 or (value >> frombits): + return None + acc = ((acc << frombits) | value) & max_acc + bits += frombits + while bits >= tobits: + bits -= tobits + ret.append((acc >> bits) & maxv) + if pad: + if bits: + ret.append((acc << (tobits - bits)) & maxv) + elif bits >= frombits or ((acc << (tobits - bits)) & maxv): + return None + return ret + + +def decode(hrp, addr): + """Decode a segwit address.""" + hrpgot, data, spec = bech32_decode(addr) + if hrpgot != hrp: + return (None, None) + decoded = convertbits(data[1:], 5, 8, False) + if decoded is None or len(decoded) < 2 or len(decoded) > 40: + return (None, None) + if data[0] > 16: + return (None, None) + if data[0] == 0 and len(decoded) != 20 and len(decoded) != 32: + return (None, None) + if data[0] == 0 and spec != Encoding.BECH32 or data[0] != 0 and spec != Encoding.BECH32M: + return (None, None) + return (data[0], decoded) + + +def encode(hrp, witver, witprog): + """Encode a segwit address.""" + spec = Encoding.BECH32 if witver == 0 else Encoding.BECH32M + ret = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5), spec) + if decode(hrp, ret) == (None, None): + return None + return ret \ No newline at end of file diff --git a/python/main.py b/python/main.py new file mode 100644 index 00000000..dcc3bfc9 --- /dev/null +++ b/python/main.py @@ -0,0 +1,61 @@ +import grpc +import sys +import json +# Why can't?? +# from pactus import network_pb2 +# from pactus import network_pb2_grpc + +import public_key +import network_pb2 +import network_pb2_grpc + + +def load_json_file(file_path): + try: + with open(file_path, 'r') as file: + data = json.load(file) + return data + except FileNotFoundError: + print(f"File not found: {file_path}") + return None + except json.JSONDecodeError as e: + print(f"Error decoding JSON: {e}") + return None + + +def update_validator_map(url, valMap): + channel = grpc.insecure_channel(url) + stub = network_pb2_grpc.NetworkStub(channel) + req = network_pb2.GetNetworkInfoRequest() + info = stub.GetNetworkInfo(req) + + for peer in info.peers: + for i, key in enumerate(peer.consensus_keys): + pub = public_key.PublicKey.from_string(key) + valAddr = pub.validator_address().string() + valMap[valAddr] = i + +if __name__ == '__main__': + if len(sys.argv) != 2: + print("Usage: python main.py ") + else: + file_path = sys.argv[1] + json_data = load_json_file(file_path) + + valMap = {} + update_validator_map('172.104.46.145:50052', valMap) + update_validator_map('94.101.184.118:50052', valMap) + update_validator_map('51.158.118.181:50052', valMap) + update_validator_map('172.232.108.191:50052', valMap) + + for key, value in json_data.items(): + userValAddr = value['validator_address'] + index = valMap.get(userValAddr, None) + if index is not None: + if index != 0: + print("user {} staked in wrong validator. index: {}".format( + value['discord_name'], index)) + else: + print("unable to find validator {} information for user {}".format( + value['validator_address'], + value['discord_name'])) diff --git a/python/network_pb2.py b/python/network_pb2.py new file mode 100644 index 00000000..f582ac64 --- /dev/null +++ b/python/network_pb2.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: network.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rnetwork.proto\x12\x06pactus\"\x17\n\x15GetNetworkInfoRequest\"\xe3\x03\n\x16GetNetworkInfoResponse\x12(\n\x10total_sent_bytes\x18\x01 \x01(\x05R\x0etotalSentBytes\x12\x30\n\x14total_received_bytes\x18\x02 \x01(\x05R\x12totalReceivedBytes\x12\x1d\n\nstarted_at\x18\x03 \x01(\x03R\tstartedAt\x12&\n\x05peers\x18\x04 \x03(\x0b\x32\x10.pactus.PeerInfoR\x05peers\x12L\n\nsent_bytes\x18\x05 \x03(\x0b\x32-.pactus.GetNetworkInfoResponse.SentBytesEntryR\tsentBytes\x12X\n\x0ereceived_bytes\x18\x06 \x03(\x0b\x32\x31.pactus.GetNetworkInfoResponse.ReceivedBytesEntryR\rreceivedBytes\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\"\x14\n\x12GetNodeInfoRequest\"\x98\x01\n\x13GetNodeInfoResponse\x12\x18\n\x07moniker\x18\x01 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x02 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x03 \x01(\x0cR\x06peerId\x12\"\n\x0creachability\x18\x04 \x01(\tR\x0creachability\x12\x14\n\x05\x61\x64\x64rs\x18\x05 \x03(\tR\x05\x61\x64\x64rs\"\xc0\x06\n\x08PeerInfo\x12\x16\n\x06status\x18\x01 \x01(\x05R\x06status\x12\x18\n\x07moniker\x18\x02 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x03 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x04 \x01(\x0cR\x06peerId\x12%\n\x0e\x63onsensus_keys\x18\x05 \x03(\tR\rconsensusKeys\x12\x1a\n\x08services\x18\x06 \x01(\rR\x08services\x12&\n\x0flast_block_hash\x18\x07 \x01(\x0cR\rlastBlockHash\x12\x16\n\x06height\x18\x08 \x01(\rR\x06height\x12+\n\x11received_messages\x18\t \x01(\x05R\x10receivedMessages\x12)\n\x10invalid_messages\x18\n \x01(\x05R\x0finvalidMessages\x12\x1b\n\tlast_sent\x18\x0b \x01(\x03R\x08lastSent\x12#\n\rlast_received\x18\x0c \x01(\x03R\x0clastReceived\x12>\n\nsent_bytes\x18\r \x03(\x0b\x32\x1f.pactus.PeerInfo.SentBytesEntryR\tsentBytes\x12J\n\x0ereceived_bytes\x18\x0e \x03(\x0b\x32#.pactus.PeerInfo.ReceivedBytesEntryR\rreceivedBytes\x12\x18\n\x07\x61\x64\x64ress\x18\x0f \x01(\tR\x07\x61\x64\x64ress\x12\x1c\n\tdirection\x18\x10 \x01(\tR\tdirection\x12\x1c\n\tprotocols\x18\x11 \x03(\tR\tprotocols\x12%\n\x0etotal_sessions\x18\x12 \x01(\x05R\rtotalSessions\x12-\n\x12\x63ompleted_sessions\x18\x13 \x01(\x05R\x11\x63ompletedSessions\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x32\xa2\x01\n\x07Network\x12O\n\x0eGetNetworkInfo\x12\x1d.pactus.GetNetworkInfoRequest\x1a\x1e.pactus.GetNetworkInfoResponse\x12\x46\n\x0bGetNodeInfo\x12\x1a.pactus.GetNodeInfoRequest\x1a\x1b.pactus.GetNodeInfoResponseBB\n\x0epactus.networkZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'network_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\016pactus.networkZ0github.com/pactus-project/pactus/www/grpc/pactus' + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._options = None + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._serialized_options = b'8\001' + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._options = None + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._serialized_options = b'8\001' + _PEERINFO_SENTBYTESENTRY._options = None + _PEERINFO_SENTBYTESENTRY._serialized_options = b'8\001' + _PEERINFO_RECEIVEDBYTESENTRY._options = None + _PEERINFO_RECEIVEDBYTESENTRY._serialized_options = b'8\001' + _GETNETWORKINFOREQUEST._serialized_start=25 + _GETNETWORKINFOREQUEST._serialized_end=48 + _GETNETWORKINFORESPONSE._serialized_start=51 + _GETNETWORKINFORESPONSE._serialized_end=534 + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._serialized_start=408 + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._serialized_end=468 + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._serialized_start=470 + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._serialized_end=534 + _GETNODEINFOREQUEST._serialized_start=536 + _GETNODEINFOREQUEST._serialized_end=556 + _GETNODEINFORESPONSE._serialized_start=559 + _GETNODEINFORESPONSE._serialized_end=711 + _PEERINFO._serialized_start=714 + _PEERINFO._serialized_end=1546 + _PEERINFO_SENTBYTESENTRY._serialized_start=408 + _PEERINFO_SENTBYTESENTRY._serialized_end=468 + _PEERINFO_RECEIVEDBYTESENTRY._serialized_start=470 + _PEERINFO_RECEIVEDBYTESENTRY._serialized_end=534 + _NETWORK._serialized_start=1549 + _NETWORK._serialized_end=1711 +# @@protoc_insertion_point(module_scope) diff --git a/python/network_pb2_grpc.py b/python/network_pb2_grpc.py new file mode 100644 index 00000000..8c1ac8ca --- /dev/null +++ b/python/network_pb2_grpc.py @@ -0,0 +1,99 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import network_pb2 as network__pb2 + + +class NetworkStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.GetNetworkInfo = channel.unary_unary( + '/pactus.Network/GetNetworkInfo', + request_serializer=network__pb2.GetNetworkInfoRequest.SerializeToString, + response_deserializer=network__pb2.GetNetworkInfoResponse.FromString, + ) + self.GetNodeInfo = channel.unary_unary( + '/pactus.Network/GetNodeInfo', + request_serializer=network__pb2.GetNodeInfoRequest.SerializeToString, + response_deserializer=network__pb2.GetNodeInfoResponse.FromString, + ) + + +class NetworkServicer(object): + """Missing associated documentation comment in .proto file.""" + + def GetNetworkInfo(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetNodeInfo(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_NetworkServicer_to_server(servicer, server): + rpc_method_handlers = { + 'GetNetworkInfo': grpc.unary_unary_rpc_method_handler( + servicer.GetNetworkInfo, + request_deserializer=network__pb2.GetNetworkInfoRequest.FromString, + response_serializer=network__pb2.GetNetworkInfoResponse.SerializeToString, + ), + 'GetNodeInfo': grpc.unary_unary_rpc_method_handler( + servicer.GetNodeInfo, + request_deserializer=network__pb2.GetNodeInfoRequest.FromString, + response_serializer=network__pb2.GetNodeInfoResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'pactus.Network', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Network(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def GetNetworkInfo(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Network/GetNetworkInfo', + network__pb2.GetNetworkInfoRequest.SerializeToString, + network__pb2.GetNetworkInfoResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetNodeInfo(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Network/GetNodeInfo', + network__pb2.GetNodeInfoRequest.SerializeToString, + network__pb2.GetNodeInfoResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/python/pactus/blockchain_pb2.py b/python/pactus/blockchain_pb2.py new file mode 100644 index 00000000..8c4d2c01 --- /dev/null +++ b/python/pactus/blockchain_pb2.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: blockchain.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +import transaction_pb2 as transaction__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10\x62lockchain.proto\x12\x06pactus\x1a\x11transaction.proto\"-\n\x11GetAccountRequest\x12\x18\n\x07\x61\x64\x64ress\x18\x01 \x01(\tR\x07\x61\x64\x64ress\"C\n\x12GetAccountResponse\x12-\n\x07\x61\x63\x63ount\x18\x01 \x01(\x0b\x32\x13.pactus.AccountInfoR\x07\x61\x63\x63ount\"\x1e\n\x1cGetValidatorAddressesRequest\"=\n\x1dGetValidatorAddressesResponse\x12\x1c\n\taddresses\x18\x01 \x03(\tR\taddresses\"/\n\x13GetValidatorRequest\x12\x18\n\x07\x61\x64\x64ress\x18\x01 \x01(\tR\x07\x61\x64\x64ress\"5\n\x1bGetValidatorByNumberRequest\x12\x16\n\x06number\x18\x01 \x01(\x05R\x06number\"K\n\x14GetValidatorResponse\x12\x33\n\tvalidator\x18\x01 \x01(\x0b\x32\x15.pactus.ValidatorInfoR\tvalidator\"/\n\x13GetPublicKeyRequest\x12\x18\n\x07\x61\x64\x64ress\x18\x01 \x01(\tR\x07\x61\x64\x64ress\"5\n\x14GetPublicKeyResponse\x12\x1d\n\npublic_key\x18\x01 \x01(\tR\tpublicKey\"_\n\x0fGetBlockRequest\x12\x16\n\x06height\x18\x01 \x01(\rR\x06height\x12\x34\n\tverbosity\x18\x02 \x01(\x0e\x32\x16.pactus.BlockVerbosityR\tverbosity\"\x83\x02\n\x10GetBlockResponse\x12\x16\n\x06height\x18\x01 \x01(\rR\x06height\x12\x12\n\x04hash\x18\x02 \x01(\x0cR\x04hash\x12\x12\n\x04\x64\x61ta\x18\x03 \x01(\x0cR\x04\x64\x61ta\x12\x1d\n\nblock_time\x18\x04 \x01(\rR\tblockTime\x12/\n\x06header\x18\x05 \x01(\x0b\x32\x17.pactus.BlockHeaderInfoR\x06header\x12\x34\n\tprev_cert\x18\x06 \x01(\x0b\x32\x17.pactus.CertificateInfoR\x08prevCert\x12)\n\x03txs\x18\x07 \x03(\x0b\x32\x17.pactus.TransactionInfoR\x03txs\"-\n\x13GetBlockHashRequest\x12\x16\n\x06height\x18\x01 \x01(\rR\x06height\"*\n\x14GetBlockHashResponse\x12\x12\n\x04hash\x18\x01 \x01(\x0cR\x04hash\"+\n\x15GetBlockHeightRequest\x12\x12\n\x04hash\x18\x01 \x01(\x0cR\x04hash\"0\n\x16GetBlockHeightResponse\x12\x16\n\x06height\x18\x01 \x01(\rR\x06height\"\x1a\n\x18GetBlockchainInfoRequest\"\xd5\x02\n\x19GetBlockchainInfoResponse\x12*\n\x11last_block_height\x18\x01 \x01(\rR\x0flastBlockHeight\x12&\n\x0flast_block_hash\x18\x02 \x01(\x0cR\rlastBlockHash\x12%\n\x0etotal_accounts\x18\x03 \x01(\x05R\rtotalAccounts\x12)\n\x10total_validators\x18\x04 \x01(\x05R\x0ftotalValidators\x12\x1f\n\x0btotal_power\x18\x05 \x01(\x03R\ntotalPower\x12\'\n\x0f\x63ommittee_power\x18\x06 \x01(\x03R\x0e\x63ommitteePower\x12H\n\x14\x63ommittee_validators\x18\x07 \x03(\x0b\x32\x15.pactus.ValidatorInfoR\x13\x63ommitteeValidators\"\x19\n\x17GetConsensusInfoRequest\"O\n\x18GetConsensusInfoResponse\x12\x33\n\tinstances\x18\x01 \x03(\x0b\x32\x15.pactus.ConsensusInfoR\tinstances\"\xad\x02\n\rValidatorInfo\x12\x12\n\x04hash\x18\x01 \x01(\x0cR\x04hash\x12\x12\n\x04\x64\x61ta\x18\x02 \x01(\x0cR\x04\x64\x61ta\x12\x1d\n\npublic_key\x18\x03 \x01(\tR\tpublicKey\x12\x16\n\x06number\x18\x04 \x01(\x05R\x06number\x12\x14\n\x05stake\x18\x05 \x01(\x03R\x05stake\x12.\n\x13last_bonding_height\x18\x06 \x01(\rR\x11lastBondingHeight\x12\x32\n\x15last_sortition_height\x18\x07 \x01(\rR\x13lastSortitionHeight\x12)\n\x10unbonding_height\x18\x08 \x01(\rR\x0funbondingHeight\x12\x18\n\x07\x61\x64\x64ress\x18\t \x01(\tR\x07\x61\x64\x64ress\"\x81\x01\n\x0b\x41\x63\x63ountInfo\x12\x12\n\x04hash\x18\x01 \x01(\x0cR\x04hash\x12\x12\n\x04\x64\x61ta\x18\x02 \x01(\x0cR\x04\x64\x61ta\x12\x16\n\x06number\x18\x03 \x01(\x05R\x06number\x12\x18\n\x07\x62\x61lance\x18\x04 \x01(\x03R\x07\x62\x61lance\x12\x18\n\x07\x61\x64\x64ress\x18\x05 \x01(\tR\x07\x61\x64\x64ress\"\xc4\x01\n\x0f\x42lockHeaderInfo\x12\x18\n\x07version\x18\x01 \x01(\x05R\x07version\x12&\n\x0fprev_block_hash\x18\x02 \x01(\x0cR\rprevBlockHash\x12\x1d\n\nstate_root\x18\x03 \x01(\x0cR\tstateRoot\x12%\n\x0esortition_seed\x18\x04 \x01(\x0cR\rsortitionSeed\x12)\n\x10proposer_address\x18\x05 \x01(\tR\x0fproposerAddress\"\x97\x01\n\x0f\x43\x65rtificateInfo\x12\x12\n\x04hash\x18\x01 \x01(\x0cR\x04hash\x12\x14\n\x05round\x18\x02 \x01(\x05R\x05round\x12\x1e\n\ncommitters\x18\x03 \x03(\x05R\ncommitters\x12\x1c\n\tabsentees\x18\x04 \x03(\x05R\tabsentees\x12\x1c\n\tsignature\x18\x05 \x01(\x0cR\tsignature\"{\n\x08VoteInfo\x12$\n\x04type\x18\x01 \x01(\x0e\x32\x10.pactus.VoteTypeR\x04type\x12\x14\n\x05voter\x18\x02 \x01(\tR\x05voter\x12\x1d\n\nblock_hash\x18\x03 \x01(\x0cR\tblockHash\x12\x14\n\x05round\x18\x04 \x01(\x05R\x05round\"\x97\x01\n\rConsensusInfo\x12\x18\n\x07\x61\x64\x64ress\x18\x01 \x01(\tR\x07\x61\x64\x64ress\x12\x16\n\x06\x41\x63tive\x18\x02 \x01(\x08R\x06\x41\x63tive\x12\x16\n\x06height\x18\x03 \x01(\rR\x06height\x12\x14\n\x05round\x18\x04 \x01(\x05R\x05round\x12&\n\x05votes\x18\x05 \x03(\x0b\x32\x10.pactus.VoteInfoR\x05votes*H\n\x0e\x42lockVerbosity\x12\x0e\n\nBLOCK_DATA\x10\x00\x12\x0e\n\nBLOCK_INFO\x10\x01\x12\x16\n\x12\x42LOCK_TRANSACTIONS\x10\x02*\\\n\x08VoteType\x12\x10\n\x0cVOTE_UNKNOWN\x10\x00\x12\x10\n\x0cVOTE_PREPARE\x10\x01\x12\x12\n\x0eVOTE_PRECOMMIT\x10\x02\x12\x18\n\x14VOTE_CHANGE_PROPOSER\x10\x03\x32\xb4\x06\n\nBlockchain\x12=\n\x08GetBlock\x12\x17.pactus.GetBlockRequest\x1a\x18.pactus.GetBlockResponse\x12I\n\x0cGetBlockHash\x12\x1b.pactus.GetBlockHashRequest\x1a\x1c.pactus.GetBlockHashResponse\x12O\n\x0eGetBlockHeight\x12\x1d.pactus.GetBlockHeightRequest\x1a\x1e.pactus.GetBlockHeightResponse\x12X\n\x11GetBlockchainInfo\x12 .pactus.GetBlockchainInfoRequest\x1a!.pactus.GetBlockchainInfoResponse\x12U\n\x10GetConsensusInfo\x12\x1f.pactus.GetConsensusInfoRequest\x1a .pactus.GetConsensusInfoResponse\x12\x43\n\nGetAccount\x12\x19.pactus.GetAccountRequest\x1a\x1a.pactus.GetAccountResponse\x12I\n\x0cGetValidator\x12\x1b.pactus.GetValidatorRequest\x1a\x1c.pactus.GetValidatorResponse\x12Y\n\x14GetValidatorByNumber\x12#.pactus.GetValidatorByNumberRequest\x1a\x1c.pactus.GetValidatorResponse\x12\x64\n\x15GetValidatorAddresses\x12$.pactus.GetValidatorAddressesRequest\x1a%.pactus.GetValidatorAddressesResponse\x12I\n\x0cGetPublicKey\x12\x1b.pactus.GetPublicKeyRequest\x1a\x1c.pactus.GetPublicKeyResponseBE\n\x11pactus.blockchainZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'blockchain_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\021pactus.blockchainZ0github.com/pactus-project/pactus/www/grpc/pactus' + _BLOCKVERBOSITY._serialized_start=2636 + _BLOCKVERBOSITY._serialized_end=2708 + _VOTETYPE._serialized_start=2710 + _VOTETYPE._serialized_end=2802 + _GETACCOUNTREQUEST._serialized_start=47 + _GETACCOUNTREQUEST._serialized_end=92 + _GETACCOUNTRESPONSE._serialized_start=94 + _GETACCOUNTRESPONSE._serialized_end=161 + _GETVALIDATORADDRESSESREQUEST._serialized_start=163 + _GETVALIDATORADDRESSESREQUEST._serialized_end=193 + _GETVALIDATORADDRESSESRESPONSE._serialized_start=195 + _GETVALIDATORADDRESSESRESPONSE._serialized_end=256 + _GETVALIDATORREQUEST._serialized_start=258 + _GETVALIDATORREQUEST._serialized_end=305 + _GETVALIDATORBYNUMBERREQUEST._serialized_start=307 + _GETVALIDATORBYNUMBERREQUEST._serialized_end=360 + _GETVALIDATORRESPONSE._serialized_start=362 + _GETVALIDATORRESPONSE._serialized_end=437 + _GETPUBLICKEYREQUEST._serialized_start=439 + _GETPUBLICKEYREQUEST._serialized_end=486 + _GETPUBLICKEYRESPONSE._serialized_start=488 + _GETPUBLICKEYRESPONSE._serialized_end=541 + _GETBLOCKREQUEST._serialized_start=543 + _GETBLOCKREQUEST._serialized_end=638 + _GETBLOCKRESPONSE._serialized_start=641 + _GETBLOCKRESPONSE._serialized_end=900 + _GETBLOCKHASHREQUEST._serialized_start=902 + _GETBLOCKHASHREQUEST._serialized_end=947 + _GETBLOCKHASHRESPONSE._serialized_start=949 + _GETBLOCKHASHRESPONSE._serialized_end=991 + _GETBLOCKHEIGHTREQUEST._serialized_start=993 + _GETBLOCKHEIGHTREQUEST._serialized_end=1036 + _GETBLOCKHEIGHTRESPONSE._serialized_start=1038 + _GETBLOCKHEIGHTRESPONSE._serialized_end=1086 + _GETBLOCKCHAININFOREQUEST._serialized_start=1088 + _GETBLOCKCHAININFOREQUEST._serialized_end=1114 + _GETBLOCKCHAININFORESPONSE._serialized_start=1117 + _GETBLOCKCHAININFORESPONSE._serialized_end=1458 + _GETCONSENSUSINFOREQUEST._serialized_start=1460 + _GETCONSENSUSINFOREQUEST._serialized_end=1485 + _GETCONSENSUSINFORESPONSE._serialized_start=1487 + _GETCONSENSUSINFORESPONSE._serialized_end=1566 + _VALIDATORINFO._serialized_start=1569 + _VALIDATORINFO._serialized_end=1870 + _ACCOUNTINFO._serialized_start=1873 + _ACCOUNTINFO._serialized_end=2002 + _BLOCKHEADERINFO._serialized_start=2005 + _BLOCKHEADERINFO._serialized_end=2201 + _CERTIFICATEINFO._serialized_start=2204 + _CERTIFICATEINFO._serialized_end=2355 + _VOTEINFO._serialized_start=2357 + _VOTEINFO._serialized_end=2480 + _CONSENSUSINFO._serialized_start=2483 + _CONSENSUSINFO._serialized_end=2634 + _BLOCKCHAIN._serialized_start=2805 + _BLOCKCHAIN._serialized_end=3625 +# @@protoc_insertion_point(module_scope) diff --git a/python/pactus/blockchain_pb2_grpc.py b/python/pactus/blockchain_pb2_grpc.py new file mode 100644 index 00000000..16f0e3c1 --- /dev/null +++ b/python/pactus/blockchain_pb2_grpc.py @@ -0,0 +1,363 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import blockchain_pb2 as blockchain__pb2 + + +class BlockchainStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.GetBlock = channel.unary_unary( + '/pactus.Blockchain/GetBlock', + request_serializer=blockchain__pb2.GetBlockRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetBlockResponse.FromString, + ) + self.GetBlockHash = channel.unary_unary( + '/pactus.Blockchain/GetBlockHash', + request_serializer=blockchain__pb2.GetBlockHashRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetBlockHashResponse.FromString, + ) + self.GetBlockHeight = channel.unary_unary( + '/pactus.Blockchain/GetBlockHeight', + request_serializer=blockchain__pb2.GetBlockHeightRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetBlockHeightResponse.FromString, + ) + self.GetBlockchainInfo = channel.unary_unary( + '/pactus.Blockchain/GetBlockchainInfo', + request_serializer=blockchain__pb2.GetBlockchainInfoRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetBlockchainInfoResponse.FromString, + ) + self.GetConsensusInfo = channel.unary_unary( + '/pactus.Blockchain/GetConsensusInfo', + request_serializer=blockchain__pb2.GetConsensusInfoRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetConsensusInfoResponse.FromString, + ) + self.GetAccount = channel.unary_unary( + '/pactus.Blockchain/GetAccount', + request_serializer=blockchain__pb2.GetAccountRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetAccountResponse.FromString, + ) + self.GetValidator = channel.unary_unary( + '/pactus.Blockchain/GetValidator', + request_serializer=blockchain__pb2.GetValidatorRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetValidatorResponse.FromString, + ) + self.GetValidatorByNumber = channel.unary_unary( + '/pactus.Blockchain/GetValidatorByNumber', + request_serializer=blockchain__pb2.GetValidatorByNumberRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetValidatorResponse.FromString, + ) + self.GetValidatorAddresses = channel.unary_unary( + '/pactus.Blockchain/GetValidatorAddresses', + request_serializer=blockchain__pb2.GetValidatorAddressesRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetValidatorAddressesResponse.FromString, + ) + self.GetPublicKey = channel.unary_unary( + '/pactus.Blockchain/GetPublicKey', + request_serializer=blockchain__pb2.GetPublicKeyRequest.SerializeToString, + response_deserializer=blockchain__pb2.GetPublicKeyResponse.FromString, + ) + + +class BlockchainServicer(object): + """Missing associated documentation comment in .proto file.""" + + def GetBlock(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetBlockHash(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetBlockHeight(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetBlockchainInfo(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetConsensusInfo(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetAccount(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetValidator(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetValidatorByNumber(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetValidatorAddresses(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetPublicKey(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_BlockchainServicer_to_server(servicer, server): + rpc_method_handlers = { + 'GetBlock': grpc.unary_unary_rpc_method_handler( + servicer.GetBlock, + request_deserializer=blockchain__pb2.GetBlockRequest.FromString, + response_serializer=blockchain__pb2.GetBlockResponse.SerializeToString, + ), + 'GetBlockHash': grpc.unary_unary_rpc_method_handler( + servicer.GetBlockHash, + request_deserializer=blockchain__pb2.GetBlockHashRequest.FromString, + response_serializer=blockchain__pb2.GetBlockHashResponse.SerializeToString, + ), + 'GetBlockHeight': grpc.unary_unary_rpc_method_handler( + servicer.GetBlockHeight, + request_deserializer=blockchain__pb2.GetBlockHeightRequest.FromString, + response_serializer=blockchain__pb2.GetBlockHeightResponse.SerializeToString, + ), + 'GetBlockchainInfo': grpc.unary_unary_rpc_method_handler( + servicer.GetBlockchainInfo, + request_deserializer=blockchain__pb2.GetBlockchainInfoRequest.FromString, + response_serializer=blockchain__pb2.GetBlockchainInfoResponse.SerializeToString, + ), + 'GetConsensusInfo': grpc.unary_unary_rpc_method_handler( + servicer.GetConsensusInfo, + request_deserializer=blockchain__pb2.GetConsensusInfoRequest.FromString, + response_serializer=blockchain__pb2.GetConsensusInfoResponse.SerializeToString, + ), + 'GetAccount': grpc.unary_unary_rpc_method_handler( + servicer.GetAccount, + request_deserializer=blockchain__pb2.GetAccountRequest.FromString, + response_serializer=blockchain__pb2.GetAccountResponse.SerializeToString, + ), + 'GetValidator': grpc.unary_unary_rpc_method_handler( + servicer.GetValidator, + request_deserializer=blockchain__pb2.GetValidatorRequest.FromString, + response_serializer=blockchain__pb2.GetValidatorResponse.SerializeToString, + ), + 'GetValidatorByNumber': grpc.unary_unary_rpc_method_handler( + servicer.GetValidatorByNumber, + request_deserializer=blockchain__pb2.GetValidatorByNumberRequest.FromString, + response_serializer=blockchain__pb2.GetValidatorResponse.SerializeToString, + ), + 'GetValidatorAddresses': grpc.unary_unary_rpc_method_handler( + servicer.GetValidatorAddresses, + request_deserializer=blockchain__pb2.GetValidatorAddressesRequest.FromString, + response_serializer=blockchain__pb2.GetValidatorAddressesResponse.SerializeToString, + ), + 'GetPublicKey': grpc.unary_unary_rpc_method_handler( + servicer.GetPublicKey, + request_deserializer=blockchain__pb2.GetPublicKeyRequest.FromString, + response_serializer=blockchain__pb2.GetPublicKeyResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'pactus.Blockchain', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Blockchain(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def GetBlock(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetBlock', + blockchain__pb2.GetBlockRequest.SerializeToString, + blockchain__pb2.GetBlockResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetBlockHash(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetBlockHash', + blockchain__pb2.GetBlockHashRequest.SerializeToString, + blockchain__pb2.GetBlockHashResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetBlockHeight(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetBlockHeight', + blockchain__pb2.GetBlockHeightRequest.SerializeToString, + blockchain__pb2.GetBlockHeightResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetBlockchainInfo(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetBlockchainInfo', + blockchain__pb2.GetBlockchainInfoRequest.SerializeToString, + blockchain__pb2.GetBlockchainInfoResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetConsensusInfo(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetConsensusInfo', + blockchain__pb2.GetConsensusInfoRequest.SerializeToString, + blockchain__pb2.GetConsensusInfoResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetAccount(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetAccount', + blockchain__pb2.GetAccountRequest.SerializeToString, + blockchain__pb2.GetAccountResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetValidator(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetValidator', + blockchain__pb2.GetValidatorRequest.SerializeToString, + blockchain__pb2.GetValidatorResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetValidatorByNumber(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetValidatorByNumber', + blockchain__pb2.GetValidatorByNumberRequest.SerializeToString, + blockchain__pb2.GetValidatorResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetValidatorAddresses(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetValidatorAddresses', + blockchain__pb2.GetValidatorAddressesRequest.SerializeToString, + blockchain__pb2.GetValidatorAddressesResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetPublicKey(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Blockchain/GetPublicKey', + blockchain__pb2.GetPublicKeyRequest.SerializeToString, + blockchain__pb2.GetPublicKeyResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/python/pactus/network_pb2.py b/python/pactus/network_pb2.py new file mode 100644 index 00000000..f582ac64 --- /dev/null +++ b/python/pactus/network_pb2.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: network.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rnetwork.proto\x12\x06pactus\"\x17\n\x15GetNetworkInfoRequest\"\xe3\x03\n\x16GetNetworkInfoResponse\x12(\n\x10total_sent_bytes\x18\x01 \x01(\x05R\x0etotalSentBytes\x12\x30\n\x14total_received_bytes\x18\x02 \x01(\x05R\x12totalReceivedBytes\x12\x1d\n\nstarted_at\x18\x03 \x01(\x03R\tstartedAt\x12&\n\x05peers\x18\x04 \x03(\x0b\x32\x10.pactus.PeerInfoR\x05peers\x12L\n\nsent_bytes\x18\x05 \x03(\x0b\x32-.pactus.GetNetworkInfoResponse.SentBytesEntryR\tsentBytes\x12X\n\x0ereceived_bytes\x18\x06 \x03(\x0b\x32\x31.pactus.GetNetworkInfoResponse.ReceivedBytesEntryR\rreceivedBytes\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\"\x14\n\x12GetNodeInfoRequest\"\x98\x01\n\x13GetNodeInfoResponse\x12\x18\n\x07moniker\x18\x01 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x02 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x03 \x01(\x0cR\x06peerId\x12\"\n\x0creachability\x18\x04 \x01(\tR\x0creachability\x12\x14\n\x05\x61\x64\x64rs\x18\x05 \x03(\tR\x05\x61\x64\x64rs\"\xc0\x06\n\x08PeerInfo\x12\x16\n\x06status\x18\x01 \x01(\x05R\x06status\x12\x18\n\x07moniker\x18\x02 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x03 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x04 \x01(\x0cR\x06peerId\x12%\n\x0e\x63onsensus_keys\x18\x05 \x03(\tR\rconsensusKeys\x12\x1a\n\x08services\x18\x06 \x01(\rR\x08services\x12&\n\x0flast_block_hash\x18\x07 \x01(\x0cR\rlastBlockHash\x12\x16\n\x06height\x18\x08 \x01(\rR\x06height\x12+\n\x11received_messages\x18\t \x01(\x05R\x10receivedMessages\x12)\n\x10invalid_messages\x18\n \x01(\x05R\x0finvalidMessages\x12\x1b\n\tlast_sent\x18\x0b \x01(\x03R\x08lastSent\x12#\n\rlast_received\x18\x0c \x01(\x03R\x0clastReceived\x12>\n\nsent_bytes\x18\r \x03(\x0b\x32\x1f.pactus.PeerInfo.SentBytesEntryR\tsentBytes\x12J\n\x0ereceived_bytes\x18\x0e \x03(\x0b\x32#.pactus.PeerInfo.ReceivedBytesEntryR\rreceivedBytes\x12\x18\n\x07\x61\x64\x64ress\x18\x0f \x01(\tR\x07\x61\x64\x64ress\x12\x1c\n\tdirection\x18\x10 \x01(\tR\tdirection\x12\x1c\n\tprotocols\x18\x11 \x03(\tR\tprotocols\x12%\n\x0etotal_sessions\x18\x12 \x01(\x05R\rtotalSessions\x12-\n\x12\x63ompleted_sessions\x18\x13 \x01(\x05R\x11\x63ompletedSessions\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x32\xa2\x01\n\x07Network\x12O\n\x0eGetNetworkInfo\x12\x1d.pactus.GetNetworkInfoRequest\x1a\x1e.pactus.GetNetworkInfoResponse\x12\x46\n\x0bGetNodeInfo\x12\x1a.pactus.GetNodeInfoRequest\x1a\x1b.pactus.GetNodeInfoResponseBB\n\x0epactus.networkZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'network_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\016pactus.networkZ0github.com/pactus-project/pactus/www/grpc/pactus' + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._options = None + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._serialized_options = b'8\001' + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._options = None + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._serialized_options = b'8\001' + _PEERINFO_SENTBYTESENTRY._options = None + _PEERINFO_SENTBYTESENTRY._serialized_options = b'8\001' + _PEERINFO_RECEIVEDBYTESENTRY._options = None + _PEERINFO_RECEIVEDBYTESENTRY._serialized_options = b'8\001' + _GETNETWORKINFOREQUEST._serialized_start=25 + _GETNETWORKINFOREQUEST._serialized_end=48 + _GETNETWORKINFORESPONSE._serialized_start=51 + _GETNETWORKINFORESPONSE._serialized_end=534 + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._serialized_start=408 + _GETNETWORKINFORESPONSE_SENTBYTESENTRY._serialized_end=468 + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._serialized_start=470 + _GETNETWORKINFORESPONSE_RECEIVEDBYTESENTRY._serialized_end=534 + _GETNODEINFOREQUEST._serialized_start=536 + _GETNODEINFOREQUEST._serialized_end=556 + _GETNODEINFORESPONSE._serialized_start=559 + _GETNODEINFORESPONSE._serialized_end=711 + _PEERINFO._serialized_start=714 + _PEERINFO._serialized_end=1546 + _PEERINFO_SENTBYTESENTRY._serialized_start=408 + _PEERINFO_SENTBYTESENTRY._serialized_end=468 + _PEERINFO_RECEIVEDBYTESENTRY._serialized_start=470 + _PEERINFO_RECEIVEDBYTESENTRY._serialized_end=534 + _NETWORK._serialized_start=1549 + _NETWORK._serialized_end=1711 +# @@protoc_insertion_point(module_scope) diff --git a/python/pactus/network_pb2_grpc.py b/python/pactus/network_pb2_grpc.py new file mode 100644 index 00000000..8c1ac8ca --- /dev/null +++ b/python/pactus/network_pb2_grpc.py @@ -0,0 +1,99 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import network_pb2 as network__pb2 + + +class NetworkStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.GetNetworkInfo = channel.unary_unary( + '/pactus.Network/GetNetworkInfo', + request_serializer=network__pb2.GetNetworkInfoRequest.SerializeToString, + response_deserializer=network__pb2.GetNetworkInfoResponse.FromString, + ) + self.GetNodeInfo = channel.unary_unary( + '/pactus.Network/GetNodeInfo', + request_serializer=network__pb2.GetNodeInfoRequest.SerializeToString, + response_deserializer=network__pb2.GetNodeInfoResponse.FromString, + ) + + +class NetworkServicer(object): + """Missing associated documentation comment in .proto file.""" + + def GetNetworkInfo(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetNodeInfo(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_NetworkServicer_to_server(servicer, server): + rpc_method_handlers = { + 'GetNetworkInfo': grpc.unary_unary_rpc_method_handler( + servicer.GetNetworkInfo, + request_deserializer=network__pb2.GetNetworkInfoRequest.FromString, + response_serializer=network__pb2.GetNetworkInfoResponse.SerializeToString, + ), + 'GetNodeInfo': grpc.unary_unary_rpc_method_handler( + servicer.GetNodeInfo, + request_deserializer=network__pb2.GetNodeInfoRequest.FromString, + response_serializer=network__pb2.GetNodeInfoResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'pactus.Network', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Network(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def GetNetworkInfo(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Network/GetNetworkInfo', + network__pb2.GetNetworkInfoRequest.SerializeToString, + network__pb2.GetNetworkInfoResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetNodeInfo(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Network/GetNodeInfo', + network__pb2.GetNodeInfoRequest.SerializeToString, + network__pb2.GetNodeInfoResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/python/pactus/transaction_pb2.py b/python/pactus/transaction_pb2.py new file mode 100644 index 00000000..7e45136e --- /dev/null +++ b/python/pactus/transaction_pb2.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: transaction.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11transaction.proto\x12\x06pactus\"c\n\x15GetTransactionRequest\x12\x0e\n\x02id\x18\x01 \x01(\x0cR\x02id\x12:\n\tverbosity\x18\x02 \x01(\x0e\x32\x1c.pactus.TransactionVerbosityR\tverbosity\"\x95\x01\n\x16GetTransactionResponse\x12!\n\x0c\x62lock_height\x18\x0c \x01(\rR\x0b\x62lockHeight\x12\x1d\n\nblock_time\x18\r \x01(\rR\tblockTime\x12\x39\n\x0btransaction\x18\x03 \x01(\x0b\x32\x17.pactus.TransactionInfoR\x0btransaction\"d\n\x13\x43\x61lculateFeeRequest\x12\x16\n\x06\x61mount\x18\x01 \x01(\x03R\x06\x61mount\x12\x35\n\x0bpayloadType\x18\x02 \x01(\x0e\x32\x13.pactus.PayloadTypeR\x0bpayloadType\"(\n\x14\x43\x61lculateFeeResponse\x12\x10\n\x03\x66\x65\x65\x18\x01 \x01(\x03R\x03\x66\x65\x65\"/\n\x19SendRawTransactionRequest\x12\x12\n\x04\x64\x61ta\x18\x01 \x01(\x0cR\x04\x64\x61ta\",\n\x1aSendRawTransactionResponse\x12\x0e\n\x02id\x18\x02 \x01(\x0cR\x02id\"\xb1\x01\n GetRawTransferTransactionRequest\x12\x1b\n\tlock_time\x18\x01 \x01(\rR\x08lockTime\x12\x16\n\x06sender\x18\x02 \x01(\tR\x06sender\x12\x1a\n\x08receiver\x18\x03 \x01(\tR\x08receiver\x12\x16\n\x06\x61mount\x18\x04 \x01(\x03R\x06\x61mount\x12\x10\n\x03\x66\x65\x65\x18\x05 \x01(\x03R\x03\x66\x65\x65\x12\x12\n\x04memo\x18\x06 \x01(\tR\x04memo\"\xca\x01\n\x1cGetRawBondTransactionRequest\x12\x1b\n\tlock_time\x18\x01 \x01(\rR\x08lockTime\x12\x16\n\x06sender\x18\x02 \x01(\tR\x06sender\x12\x1a\n\x08receiver\x18\x03 \x01(\tR\x08receiver\x12\x14\n\x05stake\x18\x04 \x01(\x03R\x05stake\x12\x1d\n\npublic_key\x18\x05 \x01(\tR\tpublicKey\x12\x10\n\x03\x66\x65\x65\x18\x06 \x01(\x03R\x03\x66\x65\x65\x12\x12\n\x04memo\x18\x07 \x01(\tR\x04memo\"~\n\x1eGetRawUnBondTransactionRequest\x12\x1b\n\tlock_time\x18\x01 \x01(\rR\x08lockTime\x12+\n\x11validator_address\x18\x03 \x01(\tR\x10validatorAddress\x12\x12\n\x04memo\x18\x04 \x01(\tR\x04memo\"\xd3\x01\n GetRawWithdrawTransactionRequest\x12\x1b\n\tlock_time\x18\x01 \x01(\rR\x08lockTime\x12+\n\x11validator_address\x18\x03 \x01(\tR\x10validatorAddress\x12\'\n\x0f\x61\x63\x63ount_address\x18\x04 \x01(\tR\x0e\x61\x63\x63ountAddress\x12\x10\n\x03\x66\x65\x65\x18\x05 \x01(\x03R\x03\x66\x65\x65\x12\x16\n\x06\x61mount\x18\x06 \x01(\x03R\x06\x61mount\x12\x12\n\x04memo\x18\x07 \x01(\tR\x04memo\"D\n\x19GetRawTransactionResponse\x12\'\n\x0fraw_transaction\x18\x01 \x01(\x0cR\x0erawTransaction\"]\n\x0fPayloadTransfer\x12\x16\n\x06sender\x18\x01 \x01(\tR\x06sender\x12\x1a\n\x08receiver\x18\x02 \x01(\tR\x08receiver\x12\x16\n\x06\x61mount\x18\x03 \x01(\x03R\x06\x61mount\"W\n\x0bPayloadBond\x12\x16\n\x06sender\x18\x01 \x01(\tR\x06sender\x12\x1a\n\x08receiver\x18\x02 \x01(\tR\x08receiver\x12\x14\n\x05stake\x18\x03 \x01(\x03R\x05stake\"B\n\x10PayloadSortition\x12\x18\n\x07\x61\x64\x64ress\x18\x01 \x01(\tR\x07\x61\x64\x64ress\x12\x14\n\x05proof\x18\x02 \x01(\x0cR\x05proof\"-\n\rPayloadUnbond\x12\x1c\n\tvalidator\x18\x01 \x01(\tR\tvalidator\"M\n\x0fPayloadWithdraw\x12\x12\n\x04\x66rom\x18\x01 \x01(\tR\x04\x66rom\x12\x0e\n\x02to\x18\x02 \x01(\tR\x02to\x12\x16\n\x06\x61mount\x18\x03 \x01(\x03R\x06\x61mount\"\xab\x04\n\x0fTransactionInfo\x12\x0e\n\x02id\x18\x01 \x01(\x0cR\x02id\x12\x12\n\x04\x64\x61ta\x18\x02 \x01(\x0cR\x04\x64\x61ta\x12\x18\n\x07version\x18\x03 \x01(\x05R\x07version\x12\x1b\n\tlock_time\x18\x04 \x01(\rR\x08lockTime\x12\x14\n\x05value\x18\x05 \x01(\x03R\x05value\x12\x10\n\x03\x66\x65\x65\x18\x06 \x01(\x03R\x03\x66\x65\x65\x12\x35\n\x0bpayloadType\x18\x07 \x01(\x0e\x32\x13.pactus.PayloadTypeR\x0bpayloadType\x12\x35\n\x08transfer\x18\x1e \x01(\x0b\x32\x17.pactus.PayloadTransferH\x00R\x08transfer\x12)\n\x04\x62ond\x18\x1f \x01(\x0b\x32\x13.pactus.PayloadBondH\x00R\x04\x62ond\x12\x38\n\tsortition\x18 \x01(\x0b\x32\x18.pactus.PayloadSortitionH\x00R\tsortition\x12/\n\x06unbond\x18! \x01(\x0b\x32\x15.pactus.PayloadUnbondH\x00R\x06unbond\x12\x35\n\x08withdraw\x18\" \x01(\x0b\x32\x17.pactus.PayloadWithdrawH\x00R\x08withdraw\x12\x12\n\x04memo\x18\x08 \x01(\tR\x04memo\x12\x1d\n\npublic_key\x18\t \x01(\tR\tpublicKey\x12\x1c\n\tsignature\x18\n \x01(\x0cR\tsignatureB\t\n\x07payload*\x83\x01\n\x0bPayloadType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x14\n\x10TRANSFER_PAYLOAD\x10\x01\x12\x10\n\x0c\x42OND_PAYLOAD\x10\x02\x12\x15\n\x11SORTITION_PAYLOAD\x10\x03\x12\x12\n\x0eUNBOND_PAYLOAD\x10\x04\x12\x14\n\x10WITHDRAW_PAYLOAD\x10\x05*B\n\x14TransactionVerbosity\x12\x14\n\x10TRANSACTION_DATA\x10\x00\x12\x14\n\x10TRANSACTION_INFO\x10\x01\x32\xa2\x05\n\x0bTransaction\x12O\n\x0eGetTransaction\x12\x1d.pactus.GetTransactionRequest\x1a\x1e.pactus.GetTransactionResponse\x12I\n\x0c\x43\x61lculateFee\x12\x1b.pactus.CalculateFeeRequest\x1a\x1c.pactus.CalculateFeeResponse\x12[\n\x12SendRawTransaction\x12!.pactus.SendRawTransactionRequest\x1a\".pactus.SendRawTransactionResponse\x12h\n\x19GetRawTransferTransaction\x12(.pactus.GetRawTransferTransactionRequest\x1a!.pactus.GetRawTransactionResponse\x12`\n\x15GetRawBondTransaction\x12$.pactus.GetRawBondTransactionRequest\x1a!.pactus.GetRawTransactionResponse\x12\x64\n\x17GetRawUnBondTransaction\x12&.pactus.GetRawUnBondTransactionRequest\x1a!.pactus.GetRawTransactionResponse\x12h\n\x19GetRawWithdrawTransaction\x12(.pactus.GetRawWithdrawTransactionRequest\x1a!.pactus.GetRawTransactionResponseBF\n\x12pactus.transactionZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'transaction_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\022pactus.transactionZ0github.com/pactus-project/pactus/www/grpc/pactus' + _PAYLOADTYPE._serialized_start=2255 + _PAYLOADTYPE._serialized_end=2386 + _TRANSACTIONVERBOSITY._serialized_start=2388 + _TRANSACTIONVERBOSITY._serialized_end=2454 + _GETTRANSACTIONREQUEST._serialized_start=29 + _GETTRANSACTIONREQUEST._serialized_end=128 + _GETTRANSACTIONRESPONSE._serialized_start=131 + _GETTRANSACTIONRESPONSE._serialized_end=280 + _CALCULATEFEEREQUEST._serialized_start=282 + _CALCULATEFEEREQUEST._serialized_end=382 + _CALCULATEFEERESPONSE._serialized_start=384 + _CALCULATEFEERESPONSE._serialized_end=424 + _SENDRAWTRANSACTIONREQUEST._serialized_start=426 + _SENDRAWTRANSACTIONREQUEST._serialized_end=473 + _SENDRAWTRANSACTIONRESPONSE._serialized_start=475 + _SENDRAWTRANSACTIONRESPONSE._serialized_end=519 + _GETRAWTRANSFERTRANSACTIONREQUEST._serialized_start=522 + _GETRAWTRANSFERTRANSACTIONREQUEST._serialized_end=699 + _GETRAWBONDTRANSACTIONREQUEST._serialized_start=702 + _GETRAWBONDTRANSACTIONREQUEST._serialized_end=904 + _GETRAWUNBONDTRANSACTIONREQUEST._serialized_start=906 + _GETRAWUNBONDTRANSACTIONREQUEST._serialized_end=1032 + _GETRAWWITHDRAWTRANSACTIONREQUEST._serialized_start=1035 + _GETRAWWITHDRAWTRANSACTIONREQUEST._serialized_end=1246 + _GETRAWTRANSACTIONRESPONSE._serialized_start=1248 + _GETRAWTRANSACTIONRESPONSE._serialized_end=1316 + _PAYLOADTRANSFER._serialized_start=1318 + _PAYLOADTRANSFER._serialized_end=1411 + _PAYLOADBOND._serialized_start=1413 + _PAYLOADBOND._serialized_end=1500 + _PAYLOADSORTITION._serialized_start=1502 + _PAYLOADSORTITION._serialized_end=1568 + _PAYLOADUNBOND._serialized_start=1570 + _PAYLOADUNBOND._serialized_end=1615 + _PAYLOADWITHDRAW._serialized_start=1617 + _PAYLOADWITHDRAW._serialized_end=1694 + _TRANSACTIONINFO._serialized_start=1697 + _TRANSACTIONINFO._serialized_end=2252 + _TRANSACTION._serialized_start=2457 + _TRANSACTION._serialized_end=3131 +# @@protoc_insertion_point(module_scope) diff --git a/python/pactus/transaction_pb2_grpc.py b/python/pactus/transaction_pb2_grpc.py new file mode 100644 index 00000000..7ba156e2 --- /dev/null +++ b/python/pactus/transaction_pb2_grpc.py @@ -0,0 +1,264 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import transaction_pb2 as transaction__pb2 + + +class TransactionStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.GetTransaction = channel.unary_unary( + '/pactus.Transaction/GetTransaction', + request_serializer=transaction__pb2.GetTransactionRequest.SerializeToString, + response_deserializer=transaction__pb2.GetTransactionResponse.FromString, + ) + self.CalculateFee = channel.unary_unary( + '/pactus.Transaction/CalculateFee', + request_serializer=transaction__pb2.CalculateFeeRequest.SerializeToString, + response_deserializer=transaction__pb2.CalculateFeeResponse.FromString, + ) + self.SendRawTransaction = channel.unary_unary( + '/pactus.Transaction/SendRawTransaction', + request_serializer=transaction__pb2.SendRawTransactionRequest.SerializeToString, + response_deserializer=transaction__pb2.SendRawTransactionResponse.FromString, + ) + self.GetRawTransferTransaction = channel.unary_unary( + '/pactus.Transaction/GetRawTransferTransaction', + request_serializer=transaction__pb2.GetRawTransferTransactionRequest.SerializeToString, + response_deserializer=transaction__pb2.GetRawTransactionResponse.FromString, + ) + self.GetRawBondTransaction = channel.unary_unary( + '/pactus.Transaction/GetRawBondTransaction', + request_serializer=transaction__pb2.GetRawBondTransactionRequest.SerializeToString, + response_deserializer=transaction__pb2.GetRawTransactionResponse.FromString, + ) + self.GetRawUnBondTransaction = channel.unary_unary( + '/pactus.Transaction/GetRawUnBondTransaction', + request_serializer=transaction__pb2.GetRawUnBondTransactionRequest.SerializeToString, + response_deserializer=transaction__pb2.GetRawTransactionResponse.FromString, + ) + self.GetRawWithdrawTransaction = channel.unary_unary( + '/pactus.Transaction/GetRawWithdrawTransaction', + request_serializer=transaction__pb2.GetRawWithdrawTransactionRequest.SerializeToString, + response_deserializer=transaction__pb2.GetRawTransactionResponse.FromString, + ) + + +class TransactionServicer(object): + """Missing associated documentation comment in .proto file.""" + + def GetTransaction(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def CalculateFee(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def SendRawTransaction(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetRawTransferTransaction(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetRawBondTransaction(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetRawUnBondTransaction(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetRawWithdrawTransaction(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_TransactionServicer_to_server(servicer, server): + rpc_method_handlers = { + 'GetTransaction': grpc.unary_unary_rpc_method_handler( + servicer.GetTransaction, + request_deserializer=transaction__pb2.GetTransactionRequest.FromString, + response_serializer=transaction__pb2.GetTransactionResponse.SerializeToString, + ), + 'CalculateFee': grpc.unary_unary_rpc_method_handler( + servicer.CalculateFee, + request_deserializer=transaction__pb2.CalculateFeeRequest.FromString, + response_serializer=transaction__pb2.CalculateFeeResponse.SerializeToString, + ), + 'SendRawTransaction': grpc.unary_unary_rpc_method_handler( + servicer.SendRawTransaction, + request_deserializer=transaction__pb2.SendRawTransactionRequest.FromString, + response_serializer=transaction__pb2.SendRawTransactionResponse.SerializeToString, + ), + 'GetRawTransferTransaction': grpc.unary_unary_rpc_method_handler( + servicer.GetRawTransferTransaction, + request_deserializer=transaction__pb2.GetRawTransferTransactionRequest.FromString, + response_serializer=transaction__pb2.GetRawTransactionResponse.SerializeToString, + ), + 'GetRawBondTransaction': grpc.unary_unary_rpc_method_handler( + servicer.GetRawBondTransaction, + request_deserializer=transaction__pb2.GetRawBondTransactionRequest.FromString, + response_serializer=transaction__pb2.GetRawTransactionResponse.SerializeToString, + ), + 'GetRawUnBondTransaction': grpc.unary_unary_rpc_method_handler( + servicer.GetRawUnBondTransaction, + request_deserializer=transaction__pb2.GetRawUnBondTransactionRequest.FromString, + response_serializer=transaction__pb2.GetRawTransactionResponse.SerializeToString, + ), + 'GetRawWithdrawTransaction': grpc.unary_unary_rpc_method_handler( + servicer.GetRawWithdrawTransaction, + request_deserializer=transaction__pb2.GetRawWithdrawTransactionRequest.FromString, + response_serializer=transaction__pb2.GetRawTransactionResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'pactus.Transaction', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Transaction(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def GetTransaction(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/GetTransaction', + transaction__pb2.GetTransactionRequest.SerializeToString, + transaction__pb2.GetTransactionResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def CalculateFee(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/CalculateFee', + transaction__pb2.CalculateFeeRequest.SerializeToString, + transaction__pb2.CalculateFeeResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def SendRawTransaction(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/SendRawTransaction', + transaction__pb2.SendRawTransactionRequest.SerializeToString, + transaction__pb2.SendRawTransactionResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetRawTransferTransaction(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/GetRawTransferTransaction', + transaction__pb2.GetRawTransferTransactionRequest.SerializeToString, + transaction__pb2.GetRawTransactionResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetRawBondTransaction(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/GetRawBondTransaction', + transaction__pb2.GetRawBondTransactionRequest.SerializeToString, + transaction__pb2.GetRawTransactionResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetRawUnBondTransaction(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/GetRawUnBondTransaction', + transaction__pb2.GetRawUnBondTransactionRequest.SerializeToString, + transaction__pb2.GetRawTransactionResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def GetRawWithdrawTransaction(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Transaction/GetRawWithdrawTransaction', + transaction__pb2.GetRawWithdrawTransactionRequest.SerializeToString, + transaction__pb2.GetRawTransactionResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/python/pactus/wallet_pb2.py b/python/pactus/wallet_pb2.py new file mode 100644 index 00000000..6738928f --- /dev/null +++ b/python/pactus/wallet_pb2.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: wallet.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cwallet.proto\x12\x06pactus\"}\n\x13\x43reateWalletRequest\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\x1a\n\x08mnemonic\x18\x02 \x01(\tR\x08mnemonic\x12\x1a\n\x08language\x18\x03 \x01(\tR\x08language\x12\x1a\n\x08password\x18\x04 \x01(\tR\x08password\"\x16\n\x14\x43reateWalletResponse\"\'\n\x11LoadWalletRequest\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\"(\n\x12LoadWalletResponse\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\")\n\x13UnloadWalletRequest\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\"*\n\x14UnloadWalletResponse\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\"I\n\x11LockWalletRequest\x12\x1a\n\x08password\x18\x01 \x01(\tR\x08password\x12\x18\n\x07timeout\x18\x02 \x01(\x05R\x07timeout\"\x14\n\x12LockWalletResponse\"K\n\x13UnlockWalletRequest\x12\x1a\n\x08password\x18\x01 \x01(\tR\x08password\x12\x18\n\x07timeout\x18\x02 \x01(\x05R\x07timeout\"\x16\n\x14UnlockWalletResponse2\xf3\x02\n\x06Wallet\x12I\n\x0c\x43reateWallet\x12\x1b.pactus.CreateWalletRequest\x1a\x1c.pactus.CreateWalletResponse\x12\x43\n\nLoadWallet\x12\x19.pactus.LoadWalletRequest\x1a\x1a.pactus.LoadWalletResponse\x12I\n\x0cUnloadWallet\x12\x1b.pactus.UnloadWalletRequest\x1a\x1c.pactus.UnloadWalletResponse\x12\x43\n\nLockWallet\x12\x19.pactus.LockWalletRequest\x1a\x1a.pactus.LockWalletResponse\x12I\n\x0cUnlockWallet\x12\x1b.pactus.UnlockWalletRequest\x1a\x1c.pactus.UnlockWalletResponseBA\n\rpactus.walletZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'wallet_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\rpactus.walletZ0github.com/pactus-project/pactus/www/grpc/pactus' + _CREATEWALLETREQUEST._serialized_start=24 + _CREATEWALLETREQUEST._serialized_end=149 + _CREATEWALLETRESPONSE._serialized_start=151 + _CREATEWALLETRESPONSE._serialized_end=173 + _LOADWALLETREQUEST._serialized_start=175 + _LOADWALLETREQUEST._serialized_end=214 + _LOADWALLETRESPONSE._serialized_start=216 + _LOADWALLETRESPONSE._serialized_end=256 + _UNLOADWALLETREQUEST._serialized_start=258 + _UNLOADWALLETREQUEST._serialized_end=299 + _UNLOADWALLETRESPONSE._serialized_start=301 + _UNLOADWALLETRESPONSE._serialized_end=343 + _LOCKWALLETREQUEST._serialized_start=345 + _LOCKWALLETREQUEST._serialized_end=418 + _LOCKWALLETRESPONSE._serialized_start=420 + _LOCKWALLETRESPONSE._serialized_end=440 + _UNLOCKWALLETREQUEST._serialized_start=442 + _UNLOCKWALLETREQUEST._serialized_end=517 + _UNLOCKWALLETRESPONSE._serialized_start=519 + _UNLOCKWALLETRESPONSE._serialized_end=541 + _WALLET._serialized_start=544 + _WALLET._serialized_end=915 +# @@protoc_insertion_point(module_scope) diff --git a/python/pactus/wallet_pb2_grpc.py b/python/pactus/wallet_pb2_grpc.py new file mode 100644 index 00000000..ca0d05e1 --- /dev/null +++ b/python/pactus/wallet_pb2_grpc.py @@ -0,0 +1,198 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import wallet_pb2 as wallet__pb2 + + +class WalletStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.CreateWallet = channel.unary_unary( + '/pactus.Wallet/CreateWallet', + request_serializer=wallet__pb2.CreateWalletRequest.SerializeToString, + response_deserializer=wallet__pb2.CreateWalletResponse.FromString, + ) + self.LoadWallet = channel.unary_unary( + '/pactus.Wallet/LoadWallet', + request_serializer=wallet__pb2.LoadWalletRequest.SerializeToString, + response_deserializer=wallet__pb2.LoadWalletResponse.FromString, + ) + self.UnloadWallet = channel.unary_unary( + '/pactus.Wallet/UnloadWallet', + request_serializer=wallet__pb2.UnloadWalletRequest.SerializeToString, + response_deserializer=wallet__pb2.UnloadWalletResponse.FromString, + ) + self.LockWallet = channel.unary_unary( + '/pactus.Wallet/LockWallet', + request_serializer=wallet__pb2.LockWalletRequest.SerializeToString, + response_deserializer=wallet__pb2.LockWalletResponse.FromString, + ) + self.UnlockWallet = channel.unary_unary( + '/pactus.Wallet/UnlockWallet', + request_serializer=wallet__pb2.UnlockWalletRequest.SerializeToString, + response_deserializer=wallet__pb2.UnlockWalletResponse.FromString, + ) + + +class WalletServicer(object): + """Missing associated documentation comment in .proto file.""" + + def CreateWallet(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def LoadWallet(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def UnloadWallet(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def LockWallet(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def UnlockWallet(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_WalletServicer_to_server(servicer, server): + rpc_method_handlers = { + 'CreateWallet': grpc.unary_unary_rpc_method_handler( + servicer.CreateWallet, + request_deserializer=wallet__pb2.CreateWalletRequest.FromString, + response_serializer=wallet__pb2.CreateWalletResponse.SerializeToString, + ), + 'LoadWallet': grpc.unary_unary_rpc_method_handler( + servicer.LoadWallet, + request_deserializer=wallet__pb2.LoadWalletRequest.FromString, + response_serializer=wallet__pb2.LoadWalletResponse.SerializeToString, + ), + 'UnloadWallet': grpc.unary_unary_rpc_method_handler( + servicer.UnloadWallet, + request_deserializer=wallet__pb2.UnloadWalletRequest.FromString, + response_serializer=wallet__pb2.UnloadWalletResponse.SerializeToString, + ), + 'LockWallet': grpc.unary_unary_rpc_method_handler( + servicer.LockWallet, + request_deserializer=wallet__pb2.LockWalletRequest.FromString, + response_serializer=wallet__pb2.LockWalletResponse.SerializeToString, + ), + 'UnlockWallet': grpc.unary_unary_rpc_method_handler( + servicer.UnlockWallet, + request_deserializer=wallet__pb2.UnlockWalletRequest.FromString, + response_serializer=wallet__pb2.UnlockWalletResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'pactus.Wallet', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Wallet(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def CreateWallet(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Wallet/CreateWallet', + wallet__pb2.CreateWalletRequest.SerializeToString, + wallet__pb2.CreateWalletResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def LoadWallet(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Wallet/LoadWallet', + wallet__pb2.LoadWalletRequest.SerializeToString, + wallet__pb2.LoadWalletResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def UnloadWallet(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Wallet/UnloadWallet', + wallet__pb2.UnloadWalletRequest.SerializeToString, + wallet__pb2.UnloadWalletResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def LockWallet(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Wallet/LockWallet', + wallet__pb2.LockWalletRequest.SerializeToString, + wallet__pb2.LockWalletResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def UnlockWallet(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pactus.Wallet/UnlockWallet', + wallet__pb2.UnlockWalletRequest.SerializeToString, + wallet__pb2.UnlockWalletResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/python/public_key.py b/python/public_key.py new file mode 100644 index 00000000..e34aa29b --- /dev/null +++ b/python/public_key.py @@ -0,0 +1,50 @@ +import hashlib +from ripemd.ripemd160 import ripemd160 +import address +import utils + +PublicKeySize = 96 +PublicKeyHRP = "tpublic" +PublicKeyTypeBLS = 1 + + +class PublicKey: + def __init__(self, data=None): + if data is None: + self.data = bytearray(PublicKeySize) + else: + if len(data) != PublicKeySize: + raise ValueError("Public key data must be 96 bytes long") + self.data = bytearray(data) + + @classmethod + def from_string(cls, text): + hrp, typ, data = utils.decode_to_base256_with_type(text) + + if hrp != PublicKeyHRP: + raise ValueError(f"Invalid hrp: {hrp}") + + if typ != PublicKeyTypeBLS: + raise ValueError(f"Invalid public key type: {typ}") + + return cls(data) + + def bytes(self): + return self.data + + def string(self): + return utils.encode_from_base256_with_type(PublicKeyHRP, PublicKeyTypeBLS, self.data) + + def account_address(self): + return self._make_address(address.AddressType.BLSAccount) + + def validator_address(self): + return self._make_address(address.AddressType.Validator) + + def _make_address(self, address_type): + blake2b = hashlib.blake2b(digest_size=32) + blake2b.update(self.data) + hash_256 = blake2b.digest() + hash_160 = ripemd160(hash_256) + addr = address.Address(address_type, hash_160) + return addr diff --git a/python/test.py b/python/test.py new file mode 100644 index 00000000..f708a1d2 --- /dev/null +++ b/python/test.py @@ -0,0 +1,15 @@ +import unittest +import public_key + +class TestPublicKey(unittest.TestCase): + def test_from_string(self): + pubStr = "tpublic1pj2aecual5gul3p6epxw0pyulnpxtek3x20r2w5wkguxshfjqx7ecuzmgu0s9g2zkfz3hchasn0u6srwcvprweg20zjy9u5ehj8798lh3jakflaap77u8xqznpkgftg6emkxmg7g3v8052kfjjvtuasqsty299nxn" + addrAccStr = "tpc1zwmd7fr9muntueu9u0unduy8ycymzgthvu8tgyx" + addrValStr = "tpc1pwmd7fr9muntueu9u0unduy8ycymzgthvpvm4nm" + + pub = public_key.PublicKey.from_string(pubStr) + self.assertEqual(pub.account_address().string(), addrAccStr) + self.assertEqual(pub.validator_address().string(), addrValStr) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/python/utils.py b/python/utils.py new file mode 100644 index 00000000..3419841c --- /dev/null +++ b/python/utils.py @@ -0,0 +1,15 @@ +import bech32m +import hashlib +from ripemd.ripemd160 import ripemd160 + +def decode_to_base256_with_type(text): + (hrp, data, spec) = bech32m.bech32_decode(text) + assert spec == bech32m.Encoding.BECH32M + + regrouped = bech32m.convertbits(data[1:], 5, 8, False) + return (hrp, data[0], regrouped) + +def encode_from_base256_with_type(hrp, typ, data): + converted = bech32m.convertbits(list(data), 8, 5, True) + converted = [typ] + converted + return bech32m.bech32_encode(hrp, converted, bech32m.Encoding.BECH32M) \ No newline at end of file