Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grpc): adding pyi files for python generated files #1479

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions scripts/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def update_metadata_file(snapshot_path, snapshot_metadata):
"name": snapshot_metadata["name"],
"created_at": snapshot_metadata["created_at"],
"compress": snapshot_metadata["compress"],
"data": snapshot_metadata["data"]
"data": snapshot_metadata["data"],
}

metadata.append(formatted_metadata)
Expand Down Expand Up @@ -107,11 +107,13 @@ def create_snapshot_json(data_dir, snapshot_subdir):
for filename in filenames:
file_path = os.path.join(root, filename)
rel_path = os.path.relpath(file_path, data_dir)
snapshot_rel_path = os.path.join(snapshot_subdir, rel_path).replace('\\', '/')
snapshot_rel_path = os.path.join(snapshot_subdir, rel_path).replace(
"\\", "/"
)
file_info = {
"name": filename,
"path": snapshot_rel_path,
"sha": Metadata.sha256(file_path)
"sha": Metadata.sha256(file_path),
}
files.append(file_info)

Expand Down Expand Up @@ -207,30 +209,34 @@ def create_snapshot(self):
logging.info(f"Creating snapshot directory '{snapshot_dir}'")
os.makedirs(snapshot_dir, exist_ok=True)

data_dir = os.path.join(snapshot_dir, 'data')
if self.args.compress == 'none':
data_dir = os.path.join(snapshot_dir, "data")
if self.args.compress == "none":
logging.info(f"Copying data from '{self.args.data_path}' to '{data_dir}'")
shutil.copytree(self.args.data_path, data_dir)
snapshot_metadata = Metadata.create_snapshot_json(data_dir, timestamp_str)
elif self.args.compress == 'zip':
zip_file = os.path.join(snapshot_dir, 'data.zip')
elif self.args.compress == "zip":
zip_file = os.path.join(snapshot_dir, "data.zip")
rel = os.path.relpath(zip_file, snapshot_dir)
meta_path = os.path.join(timestamp_str, rel)
logging.info(f"Creating ZIP archive '{zip_file}'")
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
with zipfile.ZipFile(zip_file, "w", zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(self.args.data_path):
for file in files:
full_path = os.path.join(root, file)
rel_path = os.path.relpath(full_path, self.args.data_path)
zipf.write(full_path, os.path.join('data', rel_path))
snapshot_metadata = Metadata.create_compressed_snapshot_json(zip_file, meta_path)
elif self.args.compress == 'tar':
tar_file = os.path.join(snapshot_dir, 'data.tar.gz')
zipf.write(full_path, os.path.join("data", rel_path))
snapshot_metadata = Metadata.create_compressed_snapshot_json(
zip_file, meta_path
)
elif self.args.compress == "tar":
tar_file = os.path.join(snapshot_dir, "data.tar.gz")
rel = os.path.relpath(tar_file, snapshot_dir)
meta_path = os.path.join(timestamp_str, rel)
logging.info(f"Creating TAR.GZ archive '{tar_file}'")
subprocess.run(['tar', '-czvf', tar_file, '-C', self.args.data_path, '.'])
snapshot_metadata = Metadata.create_compressed_snapshot_json(tar_file, meta_path)
subprocess.run(["tar", "-czvf", tar_file, "-C", self.args.data_path, "."])
snapshot_metadata = Metadata.create_compressed_snapshot_json(
tar_file, meta_path
)

snapshot_metadata["name"] = timestamp_str
snapshot_metadata["created_at"] = get_current_time_iso()
Expand Down Expand Up @@ -313,14 +319,27 @@ def run(self):

def parse_args():
user_home = os.path.expanduser("~")
default_data_path = os.path.join(user_home, 'pactus')

parser = argparse.ArgumentParser(description='Pactus Blockchain Snapshot Tool')
parser.add_argument('--service_path', required=True, help='Path to pactus systemctl service')
parser.add_argument('--data_path', default=default_data_path, help='Path to data directory')
parser.add_argument('--compress', choices=['none', 'zip', 'tar'], default='none', help='Compression type')
parser.add_argument('--retention', type=int, default=3, help='Number of snapshots to retain')
parser.add_argument('--snapshot_path', default=os.getcwd(), help='Path to store snapshots')
default_data_path = os.path.join(user_home, "pactus")

parser = argparse.ArgumentParser(description="Pactus Blockchain Snapshot Tool")
parser.add_argument(
"--service_path", required=True, help="Path to pactus systemctl service"
)
parser.add_argument(
"--data_path", default=default_data_path, help="Path to data directory"
)
parser.add_argument(
"--compress",
choices=["none", "zip", "tar"],
default="none",
help="Compression type",
)
parser.add_argument(
"--retention", type=int, default=3, help="Number of snapshots to retain"
)
parser.add_argument(
"--snapshot_path", default=os.getcwd(), help="Path to store snapshots"
)

return parser.parse_args()

Expand Down
2 changes: 2 additions & 0 deletions www/grpc/buf/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ plugins:
out: ../gen/python
- plugin: buf.build/grpc/python:v1.50.0
out: ../gen/python
- plugin: buf.build/protocolbuffers/pyi:v27.2
out: ../gen/python
# Rust code gen:
# https://github.com/neoeinstein/protoc-gen-prost?tab=readme-ov-file#example-bufgenyaml
- plugin: buf.build/community/neoeinstein-prost:v0.2.3
Expand Down
276 changes: 276 additions & 0 deletions www/grpc/gen/python/blockchain_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
import transaction_pb2 as _transaction_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union

DESCRIPTOR: _descriptor.FileDescriptor

class BlockVerbosity(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
BLOCK_DATA: _ClassVar[BlockVerbosity]
BLOCK_INFO: _ClassVar[BlockVerbosity]
BLOCK_TRANSACTIONS: _ClassVar[BlockVerbosity]

class VoteType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
VOTE_UNKNOWN: _ClassVar[VoteType]
VOTE_PREPARE: _ClassVar[VoteType]
VOTE_PRECOMMIT: _ClassVar[VoteType]
VOTE_CHANGE_PROPOSER: _ClassVar[VoteType]
BLOCK_DATA: BlockVerbosity
BLOCK_INFO: BlockVerbosity
BLOCK_TRANSACTIONS: BlockVerbosity
VOTE_UNKNOWN: VoteType
VOTE_PREPARE: VoteType
VOTE_PRECOMMIT: VoteType
VOTE_CHANGE_PROPOSER: VoteType

class GetAccountRequest(_message.Message):
__slots__ = ("address",)
ADDRESS_FIELD_NUMBER: _ClassVar[int]
address: str
def __init__(self, address: _Optional[str] = ...) -> None: ...

class GetAccountResponse(_message.Message):
__slots__ = ("account",)
ACCOUNT_FIELD_NUMBER: _ClassVar[int]
account: AccountInfo
def __init__(self, account: _Optional[_Union[AccountInfo, _Mapping]] = ...) -> None: ...

class GetValidatorAddressesRequest(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...

class GetValidatorAddressesResponse(_message.Message):
__slots__ = ("addresses",)
ADDRESSES_FIELD_NUMBER: _ClassVar[int]
addresses: _containers.RepeatedScalarFieldContainer[str]
def __init__(self, addresses: _Optional[_Iterable[str]] = ...) -> None: ...

class GetValidatorRequest(_message.Message):
__slots__ = ("address",)
ADDRESS_FIELD_NUMBER: _ClassVar[int]
address: str
def __init__(self, address: _Optional[str] = ...) -> None: ...

class GetValidatorByNumberRequest(_message.Message):
__slots__ = ("number",)
NUMBER_FIELD_NUMBER: _ClassVar[int]
number: int
def __init__(self, number: _Optional[int] = ...) -> None: ...

class GetValidatorResponse(_message.Message):
__slots__ = ("validator",)
VALIDATOR_FIELD_NUMBER: _ClassVar[int]
validator: ValidatorInfo
def __init__(self, validator: _Optional[_Union[ValidatorInfo, _Mapping]] = ...) -> None: ...

class GetPublicKeyRequest(_message.Message):
__slots__ = ("address",)
ADDRESS_FIELD_NUMBER: _ClassVar[int]
address: str
def __init__(self, address: _Optional[str] = ...) -> None: ...

class GetPublicKeyResponse(_message.Message):
__slots__ = ("public_key",)
PUBLIC_KEY_FIELD_NUMBER: _ClassVar[int]
public_key: str
def __init__(self, public_key: _Optional[str] = ...) -> None: ...

class GetBlockRequest(_message.Message):
__slots__ = ("height", "verbosity")
HEIGHT_FIELD_NUMBER: _ClassVar[int]
VERBOSITY_FIELD_NUMBER: _ClassVar[int]
height: int
verbosity: BlockVerbosity
def __init__(self, height: _Optional[int] = ..., verbosity: _Optional[_Union[BlockVerbosity, str]] = ...) -> None: ...

class GetBlockResponse(_message.Message):
__slots__ = ("height", "hash", "data", "block_time", "header", "prev_cert", "txs")
HEIGHT_FIELD_NUMBER: _ClassVar[int]
HASH_FIELD_NUMBER: _ClassVar[int]
DATA_FIELD_NUMBER: _ClassVar[int]
BLOCK_TIME_FIELD_NUMBER: _ClassVar[int]
HEADER_FIELD_NUMBER: _ClassVar[int]
PREV_CERT_FIELD_NUMBER: _ClassVar[int]
TXS_FIELD_NUMBER: _ClassVar[int]
height: int
hash: str
data: str
block_time: int
header: BlockHeaderInfo
prev_cert: CertificateInfo
txs: _containers.RepeatedCompositeFieldContainer[_transaction_pb2.TransactionInfo]
def __init__(self, height: _Optional[int] = ..., hash: _Optional[str] = ..., data: _Optional[str] = ..., block_time: _Optional[int] = ..., header: _Optional[_Union[BlockHeaderInfo, _Mapping]] = ..., prev_cert: _Optional[_Union[CertificateInfo, _Mapping]] = ..., txs: _Optional[_Iterable[_Union[_transaction_pb2.TransactionInfo, _Mapping]]] = ...) -> None: ...

class GetBlockHashRequest(_message.Message):
__slots__ = ("height",)
HEIGHT_FIELD_NUMBER: _ClassVar[int]
height: int
def __init__(self, height: _Optional[int] = ...) -> None: ...

class GetBlockHashResponse(_message.Message):
__slots__ = ("hash",)
HASH_FIELD_NUMBER: _ClassVar[int]
hash: str
def __init__(self, hash: _Optional[str] = ...) -> None: ...

class GetBlockHeightRequest(_message.Message):
__slots__ = ("hash",)
HASH_FIELD_NUMBER: _ClassVar[int]
hash: str
def __init__(self, hash: _Optional[str] = ...) -> None: ...

class GetBlockHeightResponse(_message.Message):
__slots__ = ("height",)
HEIGHT_FIELD_NUMBER: _ClassVar[int]
height: int
def __init__(self, height: _Optional[int] = ...) -> None: ...

class GetBlockchainInfoRequest(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...

class GetBlockchainInfoResponse(_message.Message):
__slots__ = ("last_block_height", "last_block_hash", "total_accounts", "total_validators", "total_power", "committee_power", "committee_validators", "is_pruned", "pruning_height", "last_block_time")
LAST_BLOCK_HEIGHT_FIELD_NUMBER: _ClassVar[int]
LAST_BLOCK_HASH_FIELD_NUMBER: _ClassVar[int]
TOTAL_ACCOUNTS_FIELD_NUMBER: _ClassVar[int]
TOTAL_VALIDATORS_FIELD_NUMBER: _ClassVar[int]
TOTAL_POWER_FIELD_NUMBER: _ClassVar[int]
COMMITTEE_POWER_FIELD_NUMBER: _ClassVar[int]
COMMITTEE_VALIDATORS_FIELD_NUMBER: _ClassVar[int]
IS_PRUNED_FIELD_NUMBER: _ClassVar[int]
PRUNING_HEIGHT_FIELD_NUMBER: _ClassVar[int]
LAST_BLOCK_TIME_FIELD_NUMBER: _ClassVar[int]
last_block_height: int
last_block_hash: str
total_accounts: int
total_validators: int
total_power: int
committee_power: int
committee_validators: _containers.RepeatedCompositeFieldContainer[ValidatorInfo]
is_pruned: bool
pruning_height: int
last_block_time: int
def __init__(self, last_block_height: _Optional[int] = ..., last_block_hash: _Optional[str] = ..., total_accounts: _Optional[int] = ..., total_validators: _Optional[int] = ..., total_power: _Optional[int] = ..., committee_power: _Optional[int] = ..., committee_validators: _Optional[_Iterable[_Union[ValidatorInfo, _Mapping]]] = ..., is_pruned: bool = ..., pruning_height: _Optional[int] = ..., last_block_time: _Optional[int] = ...) -> None: ...

class GetConsensusInfoRequest(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...

class GetConsensusInfoResponse(_message.Message):
__slots__ = ("instances",)
INSTANCES_FIELD_NUMBER: _ClassVar[int]
instances: _containers.RepeatedCompositeFieldContainer[ConsensusInfo]
def __init__(self, instances: _Optional[_Iterable[_Union[ConsensusInfo, _Mapping]]] = ...) -> None: ...

class GetTxPoolContentRequest(_message.Message):
__slots__ = ("payload_type",)
PAYLOAD_TYPE_FIELD_NUMBER: _ClassVar[int]
payload_type: _transaction_pb2.PayloadType
def __init__(self, payload_type: _Optional[_Union[_transaction_pb2.PayloadType, str]] = ...) -> None: ...

class GetTxPoolContentResponse(_message.Message):
__slots__ = ("txs",)
TXS_FIELD_NUMBER: _ClassVar[int]
txs: _containers.RepeatedCompositeFieldContainer[_transaction_pb2.TransactionInfo]
def __init__(self, txs: _Optional[_Iterable[_Union[_transaction_pb2.TransactionInfo, _Mapping]]] = ...) -> None: ...

class ValidatorInfo(_message.Message):
__slots__ = ("hash", "data", "public_key", "number", "stake", "last_bonding_height", "last_sortition_height", "unbonding_height", "address", "availability_score")
HASH_FIELD_NUMBER: _ClassVar[int]
DATA_FIELD_NUMBER: _ClassVar[int]
PUBLIC_KEY_FIELD_NUMBER: _ClassVar[int]
NUMBER_FIELD_NUMBER: _ClassVar[int]
STAKE_FIELD_NUMBER: _ClassVar[int]
LAST_BONDING_HEIGHT_FIELD_NUMBER: _ClassVar[int]
LAST_SORTITION_HEIGHT_FIELD_NUMBER: _ClassVar[int]
UNBONDING_HEIGHT_FIELD_NUMBER: _ClassVar[int]
ADDRESS_FIELD_NUMBER: _ClassVar[int]
AVAILABILITY_SCORE_FIELD_NUMBER: _ClassVar[int]
hash: str
data: str
public_key: str
number: int
stake: int
last_bonding_height: int
last_sortition_height: int
unbonding_height: int
address: str
availability_score: float
def __init__(self, hash: _Optional[str] = ..., data: _Optional[str] = ..., public_key: _Optional[str] = ..., number: _Optional[int] = ..., stake: _Optional[int] = ..., last_bonding_height: _Optional[int] = ..., last_sortition_height: _Optional[int] = ..., unbonding_height: _Optional[int] = ..., address: _Optional[str] = ..., availability_score: _Optional[float] = ...) -> None: ...

class AccountInfo(_message.Message):
__slots__ = ("hash", "data", "number", "balance", "address")
HASH_FIELD_NUMBER: _ClassVar[int]
DATA_FIELD_NUMBER: _ClassVar[int]
NUMBER_FIELD_NUMBER: _ClassVar[int]
BALANCE_FIELD_NUMBER: _ClassVar[int]
ADDRESS_FIELD_NUMBER: _ClassVar[int]
hash: str
data: str
number: int
balance: int
address: str
def __init__(self, hash: _Optional[str] = ..., data: _Optional[str] = ..., number: _Optional[int] = ..., balance: _Optional[int] = ..., address: _Optional[str] = ...) -> None: ...

class BlockHeaderInfo(_message.Message):
__slots__ = ("version", "prev_block_hash", "state_root", "sortition_seed", "proposer_address")
VERSION_FIELD_NUMBER: _ClassVar[int]
PREV_BLOCK_HASH_FIELD_NUMBER: _ClassVar[int]
STATE_ROOT_FIELD_NUMBER: _ClassVar[int]
SORTITION_SEED_FIELD_NUMBER: _ClassVar[int]
PROPOSER_ADDRESS_FIELD_NUMBER: _ClassVar[int]
version: int
prev_block_hash: str
state_root: str
sortition_seed: str
proposer_address: str
def __init__(self, version: _Optional[int] = ..., prev_block_hash: _Optional[str] = ..., state_root: _Optional[str] = ..., sortition_seed: _Optional[str] = ..., proposer_address: _Optional[str] = ...) -> None: ...

class CertificateInfo(_message.Message):
__slots__ = ("hash", "round", "committers", "absentees", "signature")
HASH_FIELD_NUMBER: _ClassVar[int]
ROUND_FIELD_NUMBER: _ClassVar[int]
COMMITTERS_FIELD_NUMBER: _ClassVar[int]
ABSENTEES_FIELD_NUMBER: _ClassVar[int]
SIGNATURE_FIELD_NUMBER: _ClassVar[int]
hash: str
round: int
committers: _containers.RepeatedScalarFieldContainer[int]
absentees: _containers.RepeatedScalarFieldContainer[int]
signature: str
def __init__(self, hash: _Optional[str] = ..., round: _Optional[int] = ..., committers: _Optional[_Iterable[int]] = ..., absentees: _Optional[_Iterable[int]] = ..., signature: _Optional[str] = ...) -> None: ...

class VoteInfo(_message.Message):
__slots__ = ("type", "voter", "block_hash", "round", "cp_round", "cp_value")
TYPE_FIELD_NUMBER: _ClassVar[int]
VOTER_FIELD_NUMBER: _ClassVar[int]
BLOCK_HASH_FIELD_NUMBER: _ClassVar[int]
ROUND_FIELD_NUMBER: _ClassVar[int]
CP_ROUND_FIELD_NUMBER: _ClassVar[int]
CP_VALUE_FIELD_NUMBER: _ClassVar[int]
type: VoteType
voter: str
block_hash: str
round: int
cp_round: int
cp_value: int
def __init__(self, type: _Optional[_Union[VoteType, str]] = ..., voter: _Optional[str] = ..., block_hash: _Optional[str] = ..., round: _Optional[int] = ..., cp_round: _Optional[int] = ..., cp_value: _Optional[int] = ...) -> None: ...

class ConsensusInfo(_message.Message):
__slots__ = ("address", "active", "height", "round", "votes")
ADDRESS_FIELD_NUMBER: _ClassVar[int]
ACTIVE_FIELD_NUMBER: _ClassVar[int]
HEIGHT_FIELD_NUMBER: _ClassVar[int]
ROUND_FIELD_NUMBER: _ClassVar[int]
VOTES_FIELD_NUMBER: _ClassVar[int]
address: str
active: bool
height: int
round: int
votes: _containers.RepeatedCompositeFieldContainer[VoteInfo]
def __init__(self, address: _Optional[str] = ..., active: bool = ..., height: _Optional[int] = ..., round: _Optional[int] = ..., votes: _Optional[_Iterable[_Union[VoteInfo, _Mapping]]] = ...) -> None: ...
Loading
Loading