From c3a93d6496d5d8ee3f71a8b54502b37d7960b4b9 Mon Sep 17 00:00:00 2001 From: macong-cdc Date: Fri, 3 Dec 2021 16:42:36 +0800 Subject: [PATCH] add development notes in README.md --- README.md | 78 +++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index efa07cc..4d5080e 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,6 @@ # chainlibpy - - -> Version 2.0.0 - > Tools for [Crypto.org Chain](https://github.com/crypto-org-chain/chain-main) wallet management and offline transaction signing @@ -16,8 +12,8 @@ - [Installing](#installing) - [Usage](#usage) - [Generating a wallet](#generating-a-wallet) - - [Signing transactions](#signing-transactions) - - [thanks](#thanks) + - [Signing and broadcasting a transaction](#signing-and-broadcasting-a-transaction) + - [Acknowledgement](#acknowledgement) - [Development](#development) - [Set up development environment](#set-up-development-environment) - [Generate gRPC code](#generate-grpc-code) @@ -51,42 +47,39 @@ print(wallet.public_key) print(wallet.address) ``` -### Signing transactions +### Signing and broadcasting a transaction ```python -from chainlibpy import Transaction, Wallet -from chainlibpy.amino import StdFee, Coin -from chainlibpy.amino.message import MsgSend - -wallet = Wallet.new() -fee = StdFee("300000", [Coin("100000")]) -tx = Transaction( - wallet=wallet, - account_num=11335, - sequence=0, - fee=fee, - memo="", - chain_id="test", - sync_mode="sync", -) -from_add = wallet.address -msg = MsgSend( - from_address=wallet.address, - to_address="cro103l758ps7403sd9c0y8j6hrfw4xyl70j4mmwkf", - amount="387000", -) -tx.add_msg(msg) -pushable_tx = tx.get_pushable() +from chainlibpy.generated.cosmos.base.v1beta1.coin_pb2 import Coin +from chainlibpy.grpc_client import GrpcClient +from chainlibpy.transaction import sign_transaction +from chainlibpy.wallet import Wallet + +# Refer to example/transaction.py for how to obtain CONSTANT values below +DENOM = "basecro" +MNEMONIC_PHRASE = "rhythm armed olympic accident cost brief since right rail ramp abstract live modify pluck convince balance onion auction jewel mansion flock scare bleak sample" # noqa 501 +TO_ADDRESS = "cro195qumzv7qefsyw76amnlk253z7tplz0avyrg32" +AMOUNT = [Coin(amount="10000", denom=DENOM)] +CHAIN_ID = "chainmaind" +GRPC_ENDPOINT = "0.0.0.0:26653" + +wallet = Wallet(MNEMONIC_PHRASE) +client = GrpcClient(wallet, CHAIN_ID, GRPC_ENDPOINT) + +from_address = wallet.address +account_number = client.query_account_data(wallet.address).account_number + +msg = client.get_packed_send_msg(wallet.address, TO_ADDRESS, AMOUNT) +tx = client.generate_tx([msg], [wallet.address], [wallet.public_key]) +sign_transaction(tx, wallet.private_key, CHAIN_ID, account_number) +client.broadcast_tx(tx) ``` -One or more token transfers can be added to a transaction by calling the `add_transfer` method. +You may also refer to `example/transaction.py` on how to use a high level function `bank_send()` to sign and broadcast a transaction -When the transaction is fully prepared, calling `get_pushable` will return a signed transaction in the form of a JSON string. -This can be used as request body when calling the `POST /txs` endpoint of rpc. +### Acknowledgement -### thanks - -thanks [cosmospy](https://github.com/hukkinj1/cosmospy) for the following: +Thanks [cosmospy](https://github.com/hukkinj1/cosmospy) for the following: - referenced the packages to sign transaction and create hd wallet - python lint config file @@ -96,7 +89,7 @@ thanks [cosmospy](https://github.com/hukkinj1/cosmospy) for the following: ### Set up development environment -More about [Poetry](https://python-poetry.org/docs/) +More about [poetry](https://python-poetry.org/docs/). ``` poetry install @@ -122,9 +115,14 @@ git clone --branch v0.34.10 https://github.com/tendermint/tendermint.git $TENDER pyenv local 3.7.a 3.8.b 3.9.c ``` -After this command, `.python-version` will be generated at project root directory -Then run +`a`, `b` and `c` is python versions installed on your computer by `pyenv`. More about [pyenv](https://github.com/pyenv/pyenv). -``` +After this command, a `.python-version` file will be generated at project root directory, which means python versions inside `.python-version` are presented for this project. So running `tox` command with `py{37,38,39}` configuration should succeed.\ +Then run to verify. This command is recommended to run before pushing a commit. + +```sh +poetry run tox +# or +poetry shell tox ```