Code Monkey home page Code Monkey logo

cosmpy's People

Contributors

5a11 avatar alejandro-morales avatar angrybayblade avatar bryanchriswhite avatar daemon63 avatar ejfitzgerald avatar galadrin avatar jonathan6620 avatar jrriehl avatar missingno57 avatar panasevychol avatar pbukva avatar solarw avatar teasel-github avatar teasel-ian avatar uravgdeveloper avatar vijaysharma815 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cosmpy's Issues

Evaluate GH workflows

Prerequisites

Expected Behavior

Have up-to-date and efficient GH workflow

Current Behavior

Not sure if our GH workflow is up-to-date and efficient

To Reproduce

No response

Context

All

Failure Logs

No response

Problematic DEFAULT_DEPLOY_GAS_LIMIT value

This default value is currently above the max_gas set in Fetch.ai mainnet, which is known to cause some weird behavior when trying to broadcast txs (broadcast succeed, but receipt never get produced).

Given that cosmpy is network independent, might be great instead of hardcoding a value to query for the max_gas value when nothing is user-specified, ie from https://rest-fetchhub.fetch.ai/cosmos/params/v1beta1/params?subspace=baseapp&key=BlockParams for example.

Feature request: Add StakingAuthorization

Prerequisites

  • I checked the documentation and made sure this feature does not already exist.
  • I checked the existing issues to make sure this feature has not already been requested.
  • I have read the code of conduct before creating this issue.

Problem

No response

Feature / Solution

Add StakingAuthorization and possibly other more specific types of authorization.

Alternatives

No response

Additional Context

No response

documentation problem

Hi
when I use make generate-docs got this error:
make: *** No rule to make target 'generate-docs'. Stop.

CI Tests

Enable integration tests for windows.

ripemd160 support deprecated in OpenSSL v3 / Ubuntu 22:04

Issue:
The OpenSSL v3.0 library, which ships with eg Ubuntu 22.04 LTS, does not support ripemd160 by default. (The legacy provider would need to be explicitly enabled in openssl.cnf by the user)

Minimal Example:
Dockerfile:

FROM ubuntu:22.04
RUN apt-get update
RUN apt-get install -y python3 pip
RUN pip install cosmpy
WORKDIR /app
COPY test.py /app
CMD [ "python3", "./test.py"]

test.py:

from cosmpy.aerial.wallet import LocalWallet
from cosmpy.crypto.keypairs import PrivateKey

alice = LocalWallet(PrivateKey("T7w1yHq1QIcQiSqV27YSwk+i1i+Y4JMKhkpawCQIh6s="))
print(f"Alice Address: {alice.address()}")

Fails here with...

Traceback (most recent call last):
  File "/usr/lib/python3.10/hashlib.py", line 160, in __hash_new
    return _hashlib.new(name, data, **kwargs)
ValueError: [digital envelope routines] unsupported

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/./test.py", line 5, in <module>
    print(f"Alice Address: {alice.address()}")
  File "/usr/local/lib/python3.10/dist-packages/cosmpy/aerial/wallet.py", line 50, in address
    return Address(self._private_key)
  File "/usr/local/lib/python3.10/dist-packages/cosmpy/crypto/address.py", line 76, in __init__
    self._address = ripemd160(sha256(value.public_key_bytes))
  File "/usr/local/lib/python3.10/dist-packages/cosmpy/crypto/hashfuncs.py", line 52, in ripemd160
    h: HASH = hashlib.new("ripemd160")
  File "/usr/lib/python3.10/hashlib.py", line 166, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/usr/lib/python3.10/hashlib.py", line 123, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type ripemd160

...whereas change the Dockerfile to a linux distro still on OpenSSL v1.1, eg ubuntu:20.04 and it gives the expected output...

Alice Address: fetch17x574akd6kt8y7tqz5p2cft605ns7t826zpavy

Possible solutions

Other crypto projects have worked around this by falling back to a pure python ripemd160 when hashlib fails to deliver, (eg bitcoin-core, electrum )

Clean makefile

Cleanup make file commands. Currently when using any of the commands, e.g. make black-check, you'd get:

(pycosm) bash-3.2$ make black-check
/bin/sh: line 0: cd: cosmos-sdk-proto-schema: No such file or directory
black --check --verbose pycosm tests examples setup.py
...

The line /bin/sh: line 0: cd: cosmos-sdk-proto-schema: No such file or directory gets printed each time any makefile command is used because some of the non-developer-tools related commands (those for generating and compiling protocol schema files) are always run.

Remove this unnecessary execution of the makefile commands on each run.

Aerial: Gas Estimation Strategy API

The current version of the Aerial API assumes some hard coded values or user specified values.

These are two extremes that we don't want. Instead we want to introduce a gas estimation api which can be added to the LedgerClient object. We would provide the following two strategy:

  • Simulation Based - an online version calling the nodes simulation endpoint and allowing the user to specify a gas adjustment
  • Table Based - an offline version where the value is looked up in a table based on the type and number of messages that are present

This common interface would also allow users of the library to make their own strategies

Aerial Tx events parsing removes attributes

_parse_tx_response removes duplicate keys like _contract_address, action. This usually happens when we execute one contract from another.

Example:

[events {
  type: "execute"
  attributes {
    key: "_contract_address"
    value: "fetch1k62phyzy5c6fzzkl47q2ervqxgja8rphcrmqt9"
  }
  attributes {
    key: "_contract_address"
    value: "fetch1hn95ntrss6n9zrxf4r8uu776m8p9fxgdggyw5s"
  }
}
events {
  type: "message"
  attributes {
    key: "action"
    value: "execute"
  }
  attributes {
    key: "module"
    value: "wasm"
  }
  attributes {
    key: "sender"
    value: "fetch17x574akd6kt8y7tqz5p2cft605ns7t826zpavy"
  }
}
events {
  type: "wasm"
  attributes {
    key: "_contract_address"
    value: "fetch1k62phyzy5c6fzzkl47q2ervqxgja8rphcrmqt9"
  }
  attributes {
    key: "action"
    value: "first_foo"
  }
  attributes {
    key: "bar"
    value: "123"
  }
  attributes {
    key: "_contract_address"
    value: "fetch1hn95ntrss6n9zrxf4r8uu776m8p9fxgdggyw5s"
  }
  attributes {
    key: "action"
    value: "second_foo"
  }
  attributes {
    key: "bar_plus_one"
    value: "125"
  }
}
]

Gets interpreted as

{'execute': {'_contract_address': 'fetch1hn95ntrss6n9zrxf4r8uu776m8p9fxgdggyw5s'}, 'message': {'action': 'execute', 'module': 'wasm', 'sender': 'fetch17x574akd6kt8y7tqz5p2cft605ns7t826zpavy'}, 'wasm': {'_contract_address': 'fetch1hn95ntrss6n9zrxf4r8uu776m8p9fxgdggyw5s', 'action': 'second_foo', 'bar': '123', 'bar_plus_one': '125'}}

Refactor modules and names

We need to refine module names, module structure (e.g. how many, which class in which module), module locations, and class names in order to to utilise the most intuitive names and locations for types which will be used by users the most.

Example for Bank modules:

Modules:
bank.py --> Bank class (abstract methods)
bank_h.py --> BankWrapper class (user facing methods)
bank_rest.py --> BankRest class (Rest implementation of abstract Bank's methods)
(later) bank_pb2_grpc.py --> (gRPC implementation of abstract Bank's methods) (autogenerated by protoc)

broadcast_tx poll and timeout ?

Currently, broadcast_tx is auto-fetching the tx receipt after some configurable sleep time and this seems to raise some issues:

  • the sleep time can't be 0 or anything below the avg block time or tx will just be reported as failed
  • the sleep time value is dependent on the network activity. On a quiet day, tx will land on the first block and 10 seconds will do, on a busier day it might take a couple of blocks before being included

Might improve things to have either:

  • a poll & timeout strategy here similar to cosmjs so that it retries to pull the receipt every 3 seconds or so, and timeout if it didn't succeed after 60 seconds. This might also be some settings great to have exposed on higher-level API / client parameters as defaults are quite a network dependant?
  • let broadcast_tx return the tx hash and have another endpoint to poll for receipt (I'm thinking of uses cases where we don't really care about the receipt and just need to fire txs fast)

Also worth noting that the tx receipt might also include another error code field, which might be non-zero if the tx failed (even if broadcast reported a code = 0 earlier), maybe we'll want to test this out as well and raise on error, rather than leaving it to the user?

Additional developer tools and CI checks

Add the following tools to CI and validate existing code with them:

Round 1:

  • Security Check (bandit)
  • Safety Check (safety)
  • Import Sorting (isort)
  • Docstring check (darglint)
  • Unused code check (vulture)
  • PyLint
  • Check spelling(spell_check)

Round 2:

  • License Check(liccheck) [add license to files]
  • Copyright Check(copyright_check) [add copyright]

Docs:

  • Generate Documentation(docs) [consider adding live docs building setup]
  • Check Docs links (check_doc_links)
  • Check API Docs updated (check_api_docs)

Round 3:

  • flake8-bugbear: finds design problems
  • flake8-eradicate: remove commented out code
  • flake8-docstrings: together with pydocstyle, style docstrings
  • pydocstyle

Aerial: Code deployment exceptions

Switch out the RuntimeError exceptions with custom exceptions which contain the tx logs. This will make it easier to debug issues in the future

Evaluate dependencies

Prerequisites

Expected Behavior

Have correct, up-to-date dependencies

Current Behavior

Not sure if we need all dependencies and whether they are of correct version and whether they should be pinned to a specific version, a range, or unspecified.

To Reproduce

No response

Context

All

Failure Logs

No response

Support mnemonic

Add support for mnemonic (e.g. mnemonic to private key and vice versa conversion)

Feature request: Make passing address to contracts easier

Prerequisites

  • I checked the documentation and made sure this feature does not already exist.
  • I checked the existing issues to make sure this feature has not already been requested.
  • I have read the code of conduct before creating this issue.

Problem

When passing addresses of either wallets or contracts to contracts, it is very verbose. e.g.

    cc.agbp.execute(
        {
            "mint": {
                "recipient": str(acc_borrower.address()),
                "amount": str(5 * cc.one_unit)
            }
        }, acc_admin).wait_to_complete()

Feature / Solution

str(acc_borrower.address()), should just be acc_borrower

Similarly when passing in address of contracts:
str(cc.atomix_mint.address)

Alternatives

No response

Additional Context

No response

Unify tests

Move all tests under /tests/... in the top level location of the repo.

Define common constants and operations under tests/conftest.py and tests/common.py.

Replace manual wallet to automatic new wallet in examples

Prerequisites

  • I checked the documentation and made sure this feature does not already exist.
  • I checked the existing issues to make sure this feature has not already been requested.
  • I have read the code of conduct before creating this issue.

Problem

No response

Feature / Solution

Now that the FaucetAPI is in, we can replace the logic in examples where we have wallets hardcoded. We could replace this with random wallets, get funds for them and carry on the logic.

Alternatives

No response

Additional Context

No response

getting start example problem

start to test getting start example as follow

from cosmpy.clients.signing_cosmwasm_client import SigningCosmWasmClient
from cosmpy.common.rest_client import RestClient
from cosmpy.crypto.address import Address
from cosmpy.crypto.keypairs import PrivateKey
from cosmpy.protos.cosmos.base.v1beta1.coin_pb2 import Coin

rest_endpoint_address = "http://198.50.215.1:3327"
alice_private_key = PrivateKey(bytes.fromhex("<private_key_in_hex_format>"))
chain_id = "vega-testnet"
denom = "UATOM"
channel = RestClient(rest_endpoint_address)
client = SigningCosmWasmClient(alice_private_key, channel, chain_id)
res = client.get_balance(client.address, denom)

got this error:
Response: 400, b'{\n "code": 3,\n "message": "invalid Bech32 prefix; expected cosmos, got fetch: invalid request",\n "details": [\n ]\n}')

Fixes for Examples

Running for the first time

Running examples/atomic_swap_contract... or tx_native_tokens_.... (either rest or gRPC versions) for the first time raises an exception. The following output is from running the former for the first time:

(pycosm) bash-3.2$ python examples/atomic_swap_contract_grpc_example.py 
Traceback (most recent call last):
  File "/Users/ali/Projects/pycosm/examples/atomic_swap_contract_grpc_example.py", line 57, in <module>
    bob_client = SigningCosmWasmClient(BOB_PK, channel, CHAIN_ID)
  File "/Users/ali/Projects/pycosm/src/cosm/clients/signing_cosmwasm_client.py", line 90, in __init__
    account = self.query_account_data(self.address)
  File "/Users/ali/Projects/pycosm/src/cosm/clients/cosmwasm_client.py", line 88, in query_account_data
    account_response = self.auth_client.Account(
  File "/Users/ali/.local/share/virtualenvs/pycosm-4ld-36k-/lib/python3.9/site-packages/grpc/_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/Users/ali/.local/share/virtualenvs/pycosm-4ld-36k-/lib/python3.9/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.NOT_FOUND
	details = "rpc error: code = NotFound desc = account fetch128r83uvcxns82535d3da5wmfvhc2e5mut922dw not found: key not found"
	debug_error_string = "{"created":"@1628684719.832792000","description":"Error received from peer ipv6:[::1]:9090","file":"src/core/lib/surface/call.cc","file_line":1070,"grpc_message":"rpc error: code = NotFound desc = account fetch128r83uvcxns82535d3da5wmfvhc2e5mut922dw not found: key not found","grpc_status":5}"
>

Running any of the examples mentioned above after running examples/tx_send... produces the correct output.


tx_native_tokens_atomic_swap_grpc_example.py

Running this example does not seem to have any effect. Output:

(pycosm) bash-3.2$ python examples/tx_native_tokens_atomic_swap_grpc_example.py 
Before transaction
Validator has 89999999999999999999999 stake and 0 atestfet
Bob has 1 stake and 0 atestfet
After transaction
Validator has 89999999999999999999999 stake and 0 atestfet
Bob has 1 stake and 0 atestfet

Bug report: Cannot query balance on custom network

Prerequisites

Expected Behavior

When setting up a custom network configation (i.e. a non fetch_ai network such as juno, osmosis or even local wasmd) I am unable to perform any of the examples such as querying a balance.

I can successfully use cosmjs to perform the same task so I am certain that it is not the node or account.

See example below:

    cfg = NetworkConfig(
        chain_id="osmosis-1",
        url="grpc+https://rpc.osmosis.zone",
        fee_minimum_gas_price=5000000000,
        fee_denomination="osmo",
        staking_denomination="osmo",
    )
     
    address = Address("osmo143fxw9gqsh9sherur9jurms0qjcu52hcpc56pv")

    print(address)

    client = LedgerClient(cfg)

    balance = client.query_validators()

Current Behavior

I see error:

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "Stream removed"
	debug_error_string = "{"created":"@1653486249.711707942","description":"Error received from peer ipv6:[2606:4700::6812:af2]:443","file":"src/core/lib/surface/call.cc","file_line":952,"grpc_message":"Stream removed","grpc_status":2}"

To Reproduce

Run snippet above.

Context

Ubuntu 22.04
cosmpy 0.4.1
Python 3.9.7

Failure Logs

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNKNOWN
details = "Stream removed"
debug_error_string = "{"created":"@1653486249.711707942","description":"Error received from peer ipv6:[2606:4700::6812:af2]:443","file":"src/core/lib/surface/call.cc","file_line":952,"grpc_message":"Stream removed","grpc_status":2}"

Makefile options

Add the following options to Makefile:

  • clean: clean the local file tree (remove all unnecessary temp files, e.g. egg, build, diet, pycach, .DS_Store, .pyc, .pyo, .tox/*, coverage related, logs, ...)
  • create a new environment: cleans, creates a new venv, install the package

tx event query syntax

I apologize for asking a beginner question here. I'm not sure of the best place. I'm having a hard time making tx event queries.

Based on response I receive from the server, the format should be {eventType}.{eventAttribute}={value} but when I use that format, I get an error: "grpc_message":"\nparse error near equal (line 1 symbol 20 - line 1 symbol 21):\n"="\n. This seems to indicate failure on parsing the =. I'm not sure the correct format since the format recommended by the service is not being accepted.

from cosmpy.protos.cosmos.tx.v1beta1.service_pb2_grpc import ServiceStub
from cosmpy.protos.cosmos.tx.v1beta1.service_pb2 import GetTxsEventRequest

tx = ServiceStub(channel)
event_request = GetTxsEventRequest(
    events=["delegate.validator=osmovaloper1md9f5524vtmrn64lyv2pdfn7cnkjkklf44vtjz"]
)
tx.GetTxsEvent(event_request)

Error message:

---------------------------------------------------------------------------
_InactiveRpcError                         Traceback (most recent call last)
Input In [69], in <module>
----> 1 tx.GetTxsEvent(event_request)

File ~/.local/lib/python3.10/site-packages/grpc/_channel.py:946, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    937 def __call__(self,
    938              request,
    939              timeout=None,
   (...)
    942              wait_for_ready=None,
    943              compression=None):
    944     state, call, = self._blocking(request, timeout, metadata, credentials,
    945                                   wait_for_ready, compression)
--> 946     return _end_unary_response_blocking(state, call, False, None)

File ~/.local/lib/python3.10/site-packages/grpc/_channel.py:849, in _end_unary_response_blocking(state, call, with_call, deadline)
    847         return state.response
    848 else:
--> 849     raise _InactiveRpcError(state)

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "
parse error near equal (line 1 symbol 20 - line 1 symbol 21):
"="
"
        debug_error_string = "{"created":"@1647842437.170417548","description":"Error received from peer ipv4:65.21.x.x:9090","file":"src/core/lib/surface/call.cc","file_line":903,"grpc_message":"\nparse error near equal (line 1 symbol 20 - line 1 symbol 21):\n"="\n","grpc_status":2}"
>

Refactor rest rpc module clients to use rest client as input

Right now all REST RPC module clients receive URL as input when instantiated, what means every time module rest client intantiate, it will also create new instance of generic rest client (RestClient from src/cosm/query/rest_client.py) what is not alright since it prevents reusing/sharing common instance of generic rest client(session).

As the solution, each rest rpc module client shall receive instance of generic rest client as input to the constructor instead of URL.

Add missing docstrings

This is a tracking issue for missing docstrings in CosmPy. We need to prioritise the Aerial package which upon completion unblocks #225. The following error codes are disabled. One by one we should enable and fix the issues:

  • DAR401: Missing exception(s) in Raises section in docstrings
  • D202: 1 blank line required between summary line and description in docstrings
  • D205: No blank lines allowed after function docstring in docstrings
  • D400: First line should end with a period in docstrings
  • D401: First line should be in imperative mood in docstrings
  • D403: First word of the first line should be properly capitalized in docstrings

Aerial: Binary contract encoding helper

In some cases contract parameters need to be encoded using Binary format (which is base64 encoded JSON). Add a helper to the library to allow users to do something on the form:

contract.execute({
    "send": {
         "msg": Binary({"send": {"id": "1"}})
    }
}, sender)

Integration tests for REST API

Implement integration tests, excersising rest client API of all modules against real instance of Tenderming & Cosmos-SDK based node(for example fetchd) runnig locally (preferably in docker container).

The main goal is to verify, that modules rest API scorrectly implemented in end-to-end sesne = all requests created & submitedt by modules rest API are actually successfully processed by blockchain node, and API is a able to successfully deserialise resposses.

NOTE: This is primarily focused on modules REST API, but tests can be also run using auto-generated gRPC API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.