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

Tx generic signing & Tx module (the first take) #12

Merged
merged 20 commits into from
Jul 21, 2021
Merged

Conversation

pbukva
Copy link
Contributor

@pbukva pbukva commented Jul 19, 2021

No description provided.

@pbukva pbukva self-assigned this Jul 19, 2021
@pbukva pbukva changed the base branch from master to feat/canonical_lower-s_form_signature July 19, 2021 07:38
src/cosm/tx/__init__.py Outdated Show resolved Hide resolved
def Simulate(self, request: SimulateRequest) -> SimulateResponse:
json_request = MessageToDict(request)
response = self.rest_api.post(
f"/cosmos/tx/v1beta1/simulate",
Copy link
Member

Choose a reason for hiding this comment

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

Define this as a constant.

Copy link
Member

Choose a reason for hiding this comment

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

Use across (below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This URL path is changing, and in general it is different per each call.

Though, in this prticular case, following 3 calls below share the same URL path (note: it is still different than un this first call).

Copy link
Member

Choose a reason for hiding this comment

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

I mean the /cosmos/tx/v1beta1/ part.

Base automatically changed from feat/canonical_lower-s_form_signature to master July 20, 2021 07:58
"FETCHD_GRPC_URL" not in os.environ, "Just for testing with local fetchd node"
)
def test_tx_broadcast(self):
# from_pk = PrivateKey(bytes.fromhex("8bdfbd2eaad5dc4324d19fabed72882709dc080b39e61044d51b91a6e38f6871"))
Copy link
Member

@5A11 5A11 Jul 20, 2021

Choose a reason for hiding this comment

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

Remove unwanted code (also below).


tx_body = TxBody()
tx_body.memo = "very first tx"
# tx_body.timeout_height = 0xffffffffffffffff
Copy link
Member

Choose a reason for hiding this comment

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

see above


from_pub_key_packed = Any()
from_pub_key_packed.Pack(from_pub_key_pb) # , type_url_prefix="/")
# signer_info.public_key = from_pub_key_packed
Copy link
Member

Choose a reason for hiding this comment

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

see above

fee=Fee(amount=[Coin(amount="0", denom="afet")], gas_limit=200000),
)

# sd = SignDoc()
Copy link
Member

Choose a reason for hiding this comment

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

see above


class RPCInterface(ABC):
# Simulate simulates executing a transaction for estimating gas usage.
def Simulate(self, request: svc.SimulateRequest) -> svc.SimulateResponse:
Copy link
Member

@5A11 5A11 Jul 20, 2021

Choose a reason for hiding this comment

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

The best approach for abstract methods in python is to add @abstractmethod above the method, add docstring for the methods and have nothing in the body (remove ...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ... (or pass) must be left there, otherwise the it is syntactic error when removed.

Regarding @abstractmethod decorator, good catch, I just forgot to put the decorator on top of methods.

@MissingNO57 MissingNO57 mentioned this pull request Jul 21, 2021
@@ -1,27 +1,30 @@
import urllib.error
import urllib.request
import requests
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you reverted my changes.

Suggested change
import requests
import urllib.error
from urllib.request import Request, urlopen
class QueryRestClient:
def __init__(self, rest_address: str):
self.rest_address = rest_address
def get(self, request: str) -> str:
url = self.rest_address + request
try:
with urllib.request.urlopen(url) as f:
response = f.read().decode("utf-8")
return response
except urllib.error.HTTPError as e:
raise RuntimeError(
f"HTTPError when sending a get request.\n Request: {request}\n Response: {e.code}, {str(e.read().decode('utf-8'))})"
)
except urllib.error.URLError as e:
raise RuntimeError(
f"URLError when sending a get request.\n Request: {request}, Exception: {e})"
)
except Exception as e:
raise RuntimeError(
f"Exception during sending a get request.\n Request: {request}, Exception: {e})"
)
def post(self, url_path, json_request: dict) -> str:
try:
req = Request(self.rest_address + url_path)
req.add_header("Content-type", "application/json")
req.add_header("Accept", "application/json")
response = (
urlopen(req, data=str(json_request).encode("utf-8"))
.read()
.decode("utf-8")
)
return response
except urllib.error.HTTPError as e:
raise RuntimeError(
f"HTTPError when sending a get request.\n Request: {url_path}, with json data: {json_request}\n Response: {e.code}, {str(e.read().decode('utf-8'))})"
)
except urllib.error.URLError as e:
raise RuntimeError(
f"URLError when sending a get request.\n Request: {url_path}, with json data: {json_request}, Exception: {e})"
)
except Exception as e:
raise RuntimeError(
f"Exception during sending a get request.\n Request: {url_path}, with json data: {json_request}, Exception: {e})"
)

@pbukva pbukva merged commit cc4698f into master Jul 21, 2021
@pbukva pbukva deleted the feat/tx_signing branch July 21, 2021 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants