Skip to main content

This package contains a compiled python version of all sentinel protobuf files with their dependencies

Project description

Cosmos Protobuf

This repository compains the whole cosmos protobuf files compiled for python and ready to use with grpc. Please use the according .proto file as documentation for each python file.

Installation

You can install this package directly from the repository by using:

python -m pip install sentinel-protobuf

Usage

The following code snippet will query the balances for the address osmo15hzhcvgs2ljfng6unghvr5l32prwqdyq4aguxn. The according query.proto file in the bank subdirectory contains the Request and the Response for this request. The details for the response are defined in QueryAllBalancesResponse. It contains the balances and pagination attribute which can be accessed as shown in the example below.

import grpc
import cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2_grpc as query_pb2_grpc
import cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2 as query_pb2

host = "osmosis.strange.love"
port = "9090"

c = grpc.insecure_channel(f'{host}:{port}')
stub = query_pb2_grpc.QueryStub(c)

r = stub.AllBalances(query_pb2.QueryAllBalancesRequest(address="osmo15hzhcvgs2ljfng6unghvr5l32prwqdyq4aguxn"))
print(r.balances)

Sentinel example

The following code snippet will query all the subscription for sentnode123

import grpc
from sentinel_protobuf.sentinel.subscription.v2.subscription_pb2 import NodeSubscription
from sentinel_protobuf.sentinel.subscription.v2.querier_pb2 import QuerySubscriptionsForNodeRequest
from sentinel_protobuf.sentinel.subscription.v2.querier_pb2_grpc import QueryServiceStub

# channel = grpc.secure_channel("host:port", grpc.ssl_channel_credentials())
channel = grpc.insecure_channel("grpc.sentinel.co:9090")
stub = QueryServiceStub(channel)

response = stub.QuerySubscriptionsForNode(QuerySubscriptionsForNodeRequest(address="sentnode123"))
for subscription in response.subscriptions:
    print(NodeSubscription.FromString(subscription.value))

Build yourself

There are two scripts helping you to fork this repository to work with any cosmos based coin.

Addititional Requirements:

  1. grpcio-tools
  2. GitPython
  3. protoletariat

Steps:

  1. Create a config in configs and take a existing one as example
  2. Run the aggregate.py file with your filename without .json (Example python aggregate.py cosmos)
  3. Run the compile.py to compile all your files to protobuf
  4. Build your package. You're done!

Protobuf compilation

The files are compiled using the grpc_tools.protoc command from the grpcio-tools library. To compile a .proto file manually use following command:

python -m grpc_tools.protoc -I <absolute path to project root> --python_out=. --grpc_python_out=. <absolute path to .proto file>

After compiling all the files with protoc you need to fix the imports by using protoletariat

Note:

  • The --grpc_python_out=. is only needed when compiling a query.proto file as these define the actual grpc query
  • To compile the whole project it is favorable to match all proto files by using *.proto instead of each individual file. You can also match the whole folders to compile multiple folders at the same time. Not that the folders might contain sub-folders.

Other Cosmos based coins

Currently following coins are maintained by me:

  • Cosmos (this branch)
  • Evmos (branch: chain/evmos, package name: evmos-protobuf)
  • Osmosis (branch: chain/osmosis, package name: osmosis-protobuf)
  • Stargaze (branch: chain/stargaze, package name: stargaze-protobuf)
  • Sentinel (branch: chain/sentinel, package name sentinel-protobuf)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentinel_protobuf-0.5.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sentinel_protobuf-0.5.0-py2.py3-none-any.whl (1.5 MB view details)

Uploaded Python 2Python 3

File details

Details for the file sentinel_protobuf-0.5.0.tar.gz.

File metadata

  • Download URL: sentinel_protobuf-0.5.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for sentinel_protobuf-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ee0e31805de2fe1c6ece591b53935ad2751a7f895baf381f8590eca5532b4f7a
MD5 132d231102bc5dedcc62847b253f69d6
BLAKE2b-256 e320e713edce1a64722f469e17ee0a139694ce4f56fe075c96e7a38bb3bf8933

See more details on using hashes here.

File details

Details for the file sentinel_protobuf-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sentinel_protobuf-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 79aa559ea47f43400df995481e88432f2ccffff959e7bc043536bf8d2de0326c
MD5 1898488baa2b3c359a4e238a5f899d8f
BLAKE2b-256 9df2d1586acb3e9d5d6264c4f120ebfefa1fdbc6c6417ee74c916aadca7c2a20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page