Skip to content

Commit facef24

Browse files
committed
create examples folder and first example
1 parent 25a20d9 commit facef24

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

examples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Examples
2+
Here you'll find examples on how to use python with protobuf and grpc and it's a great starting point to get started with grpc and cosmos in general.
3+
4+
## Contributing
5+
If you are already using cosmospy_protobuf we would appreciate any contribution to the examples! This is not bound to a coin and can be an example for any coin.

examples/query_bonded_tokens.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import cosmospy_protobuf.cosmos.staking.v1beta1.query_pb2 as query_pb2
2+
import cosmospy_protobuf.cosmos.staking.v1beta1.query_pb2_grpc as query_pb2_grpc
3+
import grpc
4+
5+
host = "osmosis.strange.love"
6+
port = 9090
7+
8+
9+
class Staking:
10+
def __init__(self, c: grpc.Channel = grpc.insecure_channel(f"{host}:{port}")):
11+
self.stub = query_pb2_grpc.QueryStub(c)
12+
self._assets = {}
13+
14+
@property
15+
def bonded(self):
16+
"""Return bonded and unbonded funds"""
17+
r = self.stub.Pool(query_pb2.QueryPoolRequest())
18+
return {
19+
'bonded': int(r.pool.bonded_tokens),
20+
'unbonded': int(r.pool.not_bonded_tokens)
21+
}
22+
23+
24+
print(Staking().bonded)

0 commit comments

Comments
 (0)