fetchai / cosmpy Goto Github PK
View Code? Open in Web Editor NEWA Python client library for interacting with blockchains based on the Cosmos-SDK
License: Apache License 2.0
A Python client library for interacting with blockchains based on the Cosmos-SDK
License: Apache License 2.0
Have up-to-date and efficient GH workflow
Not sure if our GH workflow is up-to-date and efficient
No response
All
No response
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.
No response
Add StakingAuthorization and possibly other more specific types of authorization.
No response
No response
Have automated documentation and api creation (for example using sphinx).
Hi
when I use make generate-docs
got this error:
make: *** No rule to make target 'generate-docs'. Stop.
Enable integration tests for windows.
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 )
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.
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:
This common interface would also allow users of the library to make their own strategies
_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'}}
Allow the ability for the use to manually specify a account and sequence numbers when building transactions
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
)
Currently, broadcast_tx
is auto-fetching the tx receipt after some configurable sleep
time and this seems to raise some issues:
Might improve things to have either:
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?
If the account query fails the generated exception should provide more information for the user to use
Add the following tools to CI and validate existing code with them:
Round 1:
Round 2:
Docs:
Round 3:
Add docstring to existing modules.
Switch out the RuntimeError
exceptions with custom exceptions which contain the tx logs. This will make it easier to debug issues in the future
Have correct, up-to-date dependencies
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.
No response
All
No response
Add support for mnemonic (e.g. mnemonic to private key and vice versa conversion)
Demonstrate use of CosmPy and the authz
module for automating top-ups of wallet when balance falls below a specified threshold.
Not implemented
Tests for the staking module needs to be improved, on par with those for bank, auth modules.
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()
str(acc_borrower.address())
, should just be acc_borrower
Similarly when passing in address of contracts:
str(cc.atomix_mint.address)
No response
No response
Demonstrate use of CosmPy for liquidity pool trading on Starfleit DEX.
Not implemented.
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
.
No response
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.
No response
No response
Address the bug described here: tests/unit/test_mint/test_rest_client.py
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}')
Use PyTest instead of traditional unittest
Create a staking example and API for aerial
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
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()
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}"
Run snippet above.
Ubuntu 22.04
cosmpy 0.4.1
Python 3.9.7
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}"
Add the following options to Makefile:
The docker entry point file, misses the Moniker.
Generalise im plementation so it would use urllib.urlencode(...)
The @abstractmethod
decorators are missing on all methods of abstract classes defined in interface.py
of auth
& bank
modules.
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}"
>
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.
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:
Add tests that will catch bug fixed in #69
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)
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.