-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0278b2b
commit 5ad8760
Showing
10 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from mospy import Account, Transaction | ||
from mospy.clients import HTTPClient | ||
|
||
account = Account( | ||
seed_phrase="", | ||
hrp='elys' | ||
) | ||
tx = Transaction( | ||
account=account, | ||
chain_id='elystestnet-1', | ||
gas=800000, | ||
) | ||
|
||
|
||
msg = { | ||
"creator": account.address, | ||
"amount": "1000" | ||
} | ||
|
||
|
||
tx.add_dict_msg(msg, type_url="/elys.stablestake.MsgBond") | ||
|
||
client = HTTPClient( | ||
api="https://api.testnet.elys.network" | ||
) | ||
|
||
tx.set_fee( | ||
amount=100, | ||
denom="uelys" | ||
) | ||
|
||
client.load_account_data(account=account) | ||
response = client.broadcast_transaction(transaction=tx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build" | |
|
||
[project] | ||
name = "mospy-wallet" | ||
version = "0.5.5" | ||
version = "0.6.0" | ||
description = "This package is a fork of cosmospy and is a light framework for the cosmos ecosystem" | ||
authors = [ | ||
{ name = "ctrl-felix", email = "[email protected]" }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from google.protobuf import descriptor_pb2, descriptor_pool, message_factory, any_pb2 | ||
from google.protobuf.json_format import ParseDict | ||
import json | ||
|
||
class GenericProtobuf: | ||
def __init__(self): | ||
self.pool = descriptor_pool.Default() | ||
self.factory = message_factory.MessageFactory() | ||
|
||
def create_message_type(self, type_url, fields): | ||
# Create a DescriptorProto for the message type | ||
type_name = type_url.split('.')[-1] | ||
|
||
# Check if the type is already existing in the pool | ||
try: | ||
self.pool.FindMessageTypeByName(type_name) | ||
except KeyError: | ||
pass | ||
else: | ||
return | ||
|
||
descriptor_proto = descriptor_pb2.DescriptorProto() | ||
descriptor_proto.name = type_name | ||
|
||
# Add key - value pairs as fields to the Descriptor | ||
for idx, (field_name, field_value) in enumerate(fields.items(), start=1): | ||
field_descriptor = descriptor_proto.field.add() | ||
field_descriptor.name = field_name | ||
field_descriptor.number = idx | ||
|
||
if isinstance(field_value, int): | ||
field_descriptor.type = descriptor_pb2.FieldDescriptorProto.TYPE_INT32 | ||
elif isinstance(field_value, float): | ||
field_descriptor.type = descriptor_pb2.FieldDescriptorProto.TYPE_FLOAT | ||
elif isinstance(field_value, bool): | ||
field_descriptor.type = descriptor_pb2.FieldDescriptorProto.TYPE_BOOL | ||
elif isinstance(field_value, list): | ||
nested_type_name = f"{type_name}_{field_name}" | ||
self.create_message_type(nested_type_name, field_value[0]) | ||
field_descriptor.type = descriptor_pb2.FieldDescriptorProto.TYPE_MESSAGE | ||
field_descriptor.type_name = f"{nested_type_name}" | ||
field_descriptor.label = descriptor_pb2.FieldDescriptorProto.LABEL_REPEATED | ||
elif isinstance(field_value, dict): | ||
nested_type_name = f"{type_name}_{field_name}" | ||
self.create_message_type(nested_type_name, field_value[0]) | ||
field_descriptor.type = descriptor_pb2.FieldDescriptorProto.TYPE_MESSAGE | ||
field_descriptor.type_name = f"{nested_type_name}" | ||
|
||
else: | ||
field_descriptor.type = descriptor_pb2.FieldDescriptorProto.TYPE_STRING | ||
|
||
# Create a FileDescriptorProto for the new descriptor | ||
file_descriptor_proto = descriptor_pb2.FileDescriptorProto() | ||
file_descriptor_proto.name = f'{type_name}.proto' | ||
file_descriptor_proto.message_type.add().MergeFrom(descriptor_proto) | ||
|
||
# Add the file descriptor | ||
self.pool.Add(file_descriptor_proto) | ||
|
||
def get_message_class(self, type_name): | ||
message_descriptor = self.pool.FindMessageTypeByName(type_name.split('.')[-1]) | ||
return self.factory.GetPrototype(message_descriptor) | ||
|
||
def create_any_message(self, msg_dict, type_url): | ||
type_name = type_url.split('/')[-1] | ||
|
||
self.create_message_type(type_name, msg_dict) | ||
|
||
message_class = self.get_message_class(type_name) | ||
|
||
message_instance = message_class() | ||
ParseDict(msg_dict, message_instance) | ||
|
||
msg_any = any_pb2.Any() | ||
msg_any.Pack(message_instance) | ||
msg_any.type_url = type_url | ||
|
||
return msg_any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters