Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

cosmos v0.44 support #28

Closed
wants to merge 6 commits into from
Closed

cosmos v0.44 support #28

wants to merge 6 commits into from

Conversation

ctrl-Felix
Copy link

add cosmos v0.44 support

Copy link

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed pushing txs to the new endpoint, tysm for this

@czarcas7ic
Copy link

But also to note, I had to change one line under get_pushable command

        return json.dumps(
           # {"jsonrpc": "2.0", "id": 1, "method": self._sync_mode, "params": {"tx": tx_b64}}
           { "tx_bytes": tx_b64, "mode": "BROADCAST_MODE_SYNC"}

@ctrl-Felix
Copy link
Author

I had to change one line under get_pushable command

Wasn't it working like it was there? Because I submitted transactions like this

Copy link
Owner

@hukkin hukkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

I'm not yet able to have a good look unfortunately but here's my first drive-by review.

A couple questions:

  • where did you get the .proto files?
  • are all the .proto files strictly needed? Is this the smallest set that works?
  • what command did you run to generate .py files from the .proto files?

rpc_url = "https://rpc.cosmos.network/"

# Method 1
r = tx.broadcast(url=rpc_url)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want this API or the requests dependency. Cosmospy is not a networking library.

import requests

pushable_tx = tx.get_pushable()
r = requests.post(rpc_url, data=pushable_tx)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to httpx here.

@@ -27,6 +27,10 @@ dependencies = [
"mnemonic >=0.19",
"hdwallets >=0.1.0",
"typing-extensions >=3.7.4; python_version < '3.8'",
"requests==2.26.0",
"protobuf >= 3.19.1",
"google >= 3.0.0",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is google dependency used? Do we really need it?


from cosmospy._typing import SyncMode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing module should remain public API. (no underscore prefix)


def _get_pubkey(self):
pubkey_bytes = privkey_to_pubkey(self._privkey)
_pubkey = pubkey.PubKey()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be a reason to use private variables inside the function scope (applies to other methods too)

@@ -1,14 +1,15 @@
import sys

print(sys.version_info)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed

if sys.version_info < (3, 8):
from typing_extensions import Literal, TypedDict
else:
from typing import Literal, TypedDict


# Valid transaction broadcast modes for the `POST /txs` endpoint of the
# Valid transaction broadcast modes for the TX endpoint of the
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST /cosmos/tx/v1beta1/txs endpoint

@hukkin
Copy link
Owner

hukkin commented Dec 25, 2021

I had to change one line under get_pushable command

Wasn't it working like it was there? Because I submitted transactions like this

I'm fairly sure @czarcas7ic is correct here. Based on swagger docs of the POST /cosmos/tx/v1beta1/txs endpoint.

@czarcas7ic
Copy link

I had to change one line under get_pushable command

Wasn't it working like it was there? Because I submitted transactions like this

Also see https://docs.cosmos.network/master/core/proto-docs.html#cosmos-tx-v1beta1-service-proto

@ctrl-Felix
Copy link
Author

ctrl-Felix commented Dec 26, 2021

I had to change one line under get_pushable command

Wasn't it working like it was there? Because I submitted transactions like this

I'm fairly sure @czarcas7ic is correct here. Based on swagger docs of the POST /cosmos/tx/v1beta1/txs endpoint.

I think it just depends if you use the API or RPC. If you want to use it with the RPC endpoint it works. That's why I changed the endpoint to https://rpc.cosmos.network and not the api endpoint.

If you want to submit it to the API you need the change @czarcas7ic made.

It would be interesting to know if there is a performance difference

@ctrl-Felix
Copy link
Author

ctrl-Felix commented Dec 26, 2021

Thanks a lot!

I'm not yet able to have a good look unfortunately but here's my first drive-by review.

A couple questions:

* where did you get the `.proto` files?

* are all the `.proto` files strictly needed? Is this the smallest set that works?

* what command did you run to generate `.py` files from the `.proto` files?

I took the proto files from cyberpy but I think those are the sames they also used in their js library. I will check if they are all needed. This version is just a really fast adaption because I wanted to provide a fix for everyone using cosmospy (also for me I wasn't able to vroadcast transactions in python anymore)

I took the generated python files also from cybai but you can generate those files with tools like https://github.com/dropbox/mypy-protobuf, I will setup a proper way to generate them also in case of changements.

Regarding the google dep it is needed as everything relies on google.protobuf and if google or protobuf aren't installed you get the error ModuleNotFoundError: No module named 'google.protobuf'

Also the current tests will need to be recreated to work with the new update.

@hukkin
Copy link
Owner

hukkin commented Dec 26, 2021

I took the proto files from cyberpy but I think those are the sames they also used in their js library. I will check if they are all needed.

Thanks. Would be good to know what is cyberpys source for these files instead of blindly copying them.

Regarding the google dep it is needed as everything relies on google.protobuf and if google or protobuf aren't installed you get the error ModuleNotFoundError: No module named 'google.protobuf'

The google.protobuf namespace should be available solely from protobuf package. See https://github.com/protocolbuffers/protobuf/tree/master/python where the source code is under google/protobuf/.

@ctrl-Felix
Copy link
Author

Okay, I have some news regarding the proto files

The proto files are coming from cosmos (ex: https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/base/v1beta1/coin.proto => https://github.com/ctrl-Felix/cosmospy/blob/sdkv0.44/src/cosmospy/proto/coin.proto)

There are then cli utilities to migrate those protos to python code.

I saw some proto files have been updated on cosmos or have more content. I will update them on my repo too.

@ctrl-Felix
Copy link
Author

The google.protobuf namespace should be available solely from protobuf package. See https://github.com/protocolbuffers/protobuf/tree/master/python where the source code is under google/protobuf/.

I am confused too but it needs both. Check out this thread: https://stackoverflow.com/questions/38680593/importerror-no-module-named-google-protobuf

There is no explanation to this

@hukkin
Copy link
Owner

hukkin commented Jan 15, 2022

I am confused too but it needs both. Check out this thread: https://stackoverflow.com/questions/38680593/importerror-no-module-named-google-protobuf

Did you try removing the google dependency? We don't do import google, the autogenerated files do from google.protobuf import *. I don't think we need the dependency.

@hukkin
Copy link
Owner

hukkin commented Jan 15, 2022

Okay, I have some news regarding the proto files

I think this may be the best source for the proto files https://buf.build/cosmos/cosmos-sdk/tree

What we need is

  • the minimal set of proto files that we need for cosmospy to work (downloaded from the resource above)
  • the command to autogenerate Python

I cannot accept a PR with autogenerated files that I can not verify/reproduce myself.

@ctrl-Felix
Copy link
Author

I will close the pr anyways and redo it with a new version where the protos are generated from the official ones. This PR is probbaly more a dirty quick fix.

@ctrl-Felix
Copy link
Author

I am confused too but it needs both. Check out this thread: https://stackoverflow.com/questions/38680593/importerror-no-module-named-google-protobuf

Did you try removing the google dependency? We don't do import google, the autogenerated files do from google.protobuf import *. I don't think we need the dependency.

ah yeah, you're right. Google is the one which isn't needed.

@hukkin
Copy link
Owner

hukkin commented Jan 15, 2022

BTW, here's the docs for compiling Python from .proto https://developers.google.com/protocol-buffers/docs/pythontutorial#compiling-your-protocol-buffers

Here's a link to download the (currently) latest protoc binaries https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.3

@ctrl-Felix
Copy link
Author

I have some problems with converting the proto files to python files. AS Example:
Coin.proto looks like this on cyberpy https://github.com/SaveTheAles/cyberpy/blob/master/cyberpy/interfaces/coin_pb2.py
My converted version looks like this https://github.com/ctrl-Felix/cosmospy/blob/master/src/cosmospy/generated/coin_pb2.py

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants