Skip to content

Commit

Permalink
Merge pull request #1 from stephanegg/v00
Browse files Browse the repository at this point in the history
* Update tests

* Fix account, pub key, string, coins tests

* Add miscreant to poetry deps

* Remove market api, oracle, msgauth tests and imports

* Added contract hash by code id, changed signature of get contract hash to str

* Tx search return a search tx object + minor fix

* Add signature to decrypt/encrypt

* Added wrapper for latest block, and default values to transfer_amount in contract execution message

* Clean tests, update chain to secret-4

* Tx decrypt

* BaseAccount, update consensus_io_pubkey

* Update deps + tests

* Update sdk/core

* Update sdk/client

* Fixing Execute Contract Message and mergign terra latest messages templates

* Fixed util.url name, import in account

* Remove parse content for CommunityProposal

* Fix wasm init with new messages

* Fix integration tests

* Added tx execute & multi execute at wallet level

* Refactor names to secret

* Added msg_dict_as_b64 in import list

* Adding caching on contract_hash

* Upgrade, cleaning and rebase

* secret-proto python

* Add secret.proto submodule

* Fix tx parsing

* Fix furl encoding issue

* Add wasm endpoints

* Add endpoint integration test

* Update testnet, mainnet api

* Remove unused tests

* Cleaned up terra references

* Updated tutorial and README

* Update pyproject.toml

* Update index rst

* Add pulsar-2 test accounts

* Remove timeout_height from StdTx

* Added sscrt deposit to read me

* Add custom fees, send_tokens, change estimate_fees

* Update MsgExecuteContract and other wasm msgs

* Update README

* Fix pep8

* Reformat

* Add estimate fee test

* Change package version

* Update README

* Update version

Co-authored-by: phd <[email protected]>
Co-authored-by: Stephane Guilherme Gomes <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2022
2 parents c53374d + f51c137 commit 294e0d6
Show file tree
Hide file tree
Showing 181 changed files with 100,366 additions and 153,066 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 88
ignore = E501, W503
ignore = E501, W503, E402
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- terra_sdk version:
- secret_sdk version:
- Python version:
- Operating System:

Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: publish
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching *, i.e. 1.0, 20.15.10
- "v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching *rc*, i.e. v1.0-rc1, v20.15.10-rc5
- "v[0-9]+.[0-9]+.[0-9]+-beta*" # Push events to matching *b*, i.e. v1.0-beta1, v20.15.10-beta5

jobs:
publish:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
poetry-version: [1.1.10]
os: [ubuntu-18.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}
- name: poetry-check
run: poetry check
- name: poetry-publish
run: poetry publish --build --username __token__ --password ${{ secrets.PYPI_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ ENV/
# IDE settings
.vscode/

.idea*
.idea*

# MacOS
.DS_Store
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "secret.proto"]
path = secret.proto
url = https://github.com/stephanegg/secret.proto
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

coverage: ## check code coverage
poetry run coverage run --source terra_sdk -m pytest
poetry run coverage run --source secret_sdk -m pytest
poetry run coverage report -m
poetry run coverage html
# $(BROWSER) htmlcov/index.html
Expand Down Expand Up @@ -57,8 +57,8 @@ test: ## runs tests
poetry run pytest

qa: ## runs static analysis with mypy and flake8
poetry run flake8 terra_sdk
poetry run mypy -p terra_sdk
poetry run flake8 secret_sdk
poetry run mypy -p secret_sdk

format: ## runs code style and formatter
poetry run isort .
Expand Down
229 changes: 200 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,233 @@
![logo](./docs/img/logo.png)
# <div align="center"> <p > Python SDK for Secret Network </p>

You can find the documentation [here](https://terra-project.github.io/terra-sdk-python/).
<br>
<br>
The Secret Software Development Kit (SDK) in Python is a simple library toolkit for building software that can interact with the Secret blockchain and provides simple abstractions over core data structures, serialization, key management, and API request generation. The SDK is based on a fork of <a href="https://github.com/terra-money/terra.py">terra.py</a> on Terra

## Table of Contents <!-- omit in toc -->
## Features

- [Installation](#installation)
- [For Maintainers](#for-maintainers)
- [Testing](#testing)
- Written in Python offering extensive support libraries
- Versatile support for key management solutions
- Exposes the Secret Rest API through LCDClient

<br/>

# Table of Contents
- [API Reference](#api-reference)
- [Getting Started](#getting-started)
- [Requirements](#requirements)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Tests](#tests)
- [Code Quality](#code-quality)
- [Releasing a new version](#releasing-a-new-version)
- [Usage Examples](#usage-examples)
- [Getting Blockchain Information](#getting-blockchain-information)
- [Async Usage](#async-usage)
- [Building and Signing Transactions](#building-and-signing-transactions)
- [Example Using a Wallet](#example-using-a-wallet-recommended)
- [Contributing](#contributing)
- [Reporting an Issue](#reporting-an-issue)
- [Requesting a Feature](#requesting-a-feature)
- [Contributing Code](#contributing-code)
- [Documentation Contributions](#documentation-contributions)
- [License](#license)

## Installation
<br/>

Terra SDK requires **Python v3.7+**.

```sh
$ pip install -U terra-sdk
```

## For Maintainers
# API Reference
An intricate reference to the APIs on the Secret SDK can be found <a href="https://secretapi.io/#/">here</a>.

<br/>

# Getting Started
A walk-through of the steps to get started with the Secret SDK alongside with a few use case examples are provided below.

## Requirements
Secret SDK requires <a href="https://www.python.org/downloads/">Python v3.7+</a>.

## Installation

<sub>**NOTE:** *All code starting with a `$` is meant to run on your terminal (a bash prompt). All code starting with a `>>>` is meant to run in a python interpreter, like <a href="https://pypi.org/project/ipython/">ipython</a>.*</sub>

**NOTE:** This section is for developers and maintainers of the Terra SDK for Python.
Secret SDK can be installed (preferably in a `virtual environment` from PyPI using `pip`) as follows:

Terra SDK uses [Poetry](https://python-poetry.org/) to manage dependencies. To get set up with all the
```
$ pip install -U secret-sdk
```
<sub>*You might have `pip3` installed instead of `pip`; proceed according to your own setup.*<sub>

```sh
## Dependencies
Secret SDK uses <a href="https://python-poetry.org/">Poetry</a> to manage dependencies. To get set up with all the required dependencies, run:
```
$ pip install poetry
$ poetry install
```

### Testing

Terra SDK provides tests for data classes and functions. To run them:

## Tests
Secret SDK provides extensive tests for data classes and functions. To run them, after the steps in [Dependencies](#dependencies):
```
$ make test
```

### Code Quality
<br/>

Terra SDK uses Black, isort, and mypy for checking code quality and maintaining style:
# Usage Examples
Secret SDK can help you read block data, query secret contracts, sign and send transactions, and many more.
Following examples are provided to help get building started.

In order to interact with the Secret blockchain, you'll need a connection to a Secret node or an api. This can be done through setting up an LCDClient (The LCDClient is an object representing an HTTP connection to a Secret LCD node.):

```
$ make qa && make format
>>> from secret_sdk.client.lcd import LCDClient
>>> secret = LCDClient(chain_id="secret-4", url=node_rest_endpoint)
```

### Releasing a new version
## Getting Blockchain Information

**NOTE**: This section only concerns approved publishers on PyPI. An automated release
process will be run upon merging into the `master` branch.
Once properly configured, the `LCDClient` instance will allow you to interact with the Secret blockchain. Try getting the latest block height:

To publish a new version on PyPI, bump the version on `pyproject.toml` and run:

```
$ make release
>>> secret.tendermint.block_info()['block']['header']['height']
```

`'1687543'`


### Async Usage

If you want to make asynchronous, non-blocking LCD requests, you can use AsyncLCDClient. The interface is similar to LCDClient, except the module and wallet API functions must be awaited.


<pre><code>
>>> import asyncio
>>> from secret_sdk.client.lcd import AsyncLCDClient

>>> async def main():
<strong>async with AsyncLCDClient(url=node_rest_endpoint, chain_id="secret-4") as secret:</strong>
community_pool = await secret.distribution.community_pool()
print(community_pool)
<strong>await secret.session.close() # you must close the session</strong>

>>> asyncio.get_event_loop().run_until_complete(main())
</code></pre>

## Building and Signing Transactions

If you wish to perform a state-changing operation on the Secret blockchain such as sending tokens, swapping assets, withdrawing rewards, or even invoking functions on smart contracts, you must create a **transaction** and broadcast it to the network.
Secret SDK provides functions that help create StdTx objects.

### Example Using a Wallet (*recommended*)

A `Wallet` allows you to create and sign a transaction in a single step by automatically fetching the latest information from the blockchain (chain ID, account number, sequence).

Use `LCDClient.wallet()` to create a Wallet from any Key instance. The Key provided should correspond to the account you intend to sign the transaction with.


```
>>> from secret_sdk.client.lcd import LCDClient
>>> from secret_sdk.key.mnemonic import MnemonicKey
>>> mk = MnemonicKey(mnemonic=MNEMONIC)
>>> secret = LCDClient(node_rest_endpoint, "secret-4")
>>> wallet = secret.wallet(mk)
```

Once you have your Wallet, you can create a StdTx using `Wallet.create_and_sign_tx` then broadcast it to the network with `secret.tx.broadcast` with your broadcast mode of choice (block, sync, async - see cosmos docs).

```
>>> from secret_sdk.core.auth import StdFee
>>> from secret_sdk.core.bank import MsgSend
>>> send_msg = MsgSend(
wallet.key.acc_address,
RECIPIENT,
"1000000uscrt" # send 1 scrt
)
>>> tx = wallet.create_and_sign_tx(
msgs=[send_msg],
memo="My first transaction!",
fee=StdFee(200000, "120000uscrt")
)
>>> result = secret.tx.broadcast(tx)
>>> print(result)
```

Or use the abstraction `wallet.send_tokens` (see `wallet.execute_tx` to execute a smart contract with `handle_msg`).

```
>>> tx = wallet.send_tokens(wallet.key.acc_address, RECIPIENT, "1000000uscrt")
```

<br/>

# Contributing

Community contribution, whether it's a new feature, correction, bug report, additional documentation, or any other feedback is always welcome. Please read through this section to ensure that your contribution is in the most suitable format for us to effectively process.

<br/>

## Reporting an Issue
First things first: **Do NOT report security vulnerabilities in public issues!** Please disclose responsibly by letting the Secret SDK team know upfront (discord , telegram). We will assess the issue as soon as possible on a best-effort basis and will give you an estimate for when we have a fix and release available for an eventual public disclosure. </br>
If you encounter a different issue with the Python SDK, check first to see if there is an existing issue on the Issues page or a pull request on the Pull request page (both Open and Closed tabs) addressing the topic.

If there isn't a discussion on the topic there, you can file an issue. The ideal report includes:

* A description of the problem / suggestion.
* How to recreate the bug.
* If relevant, including the versions of your:
* Python interpreter
* Secret SDK
* Optionally of the other dependencies involved
* If possible, create a pull request with a (failing) test case demonstrating what's wrong. This makes the process for fixing bugs quicker & gets issues resolved sooner.
</br>

## Requesting a Feature
If you wish to request the addition of a feature, please first checkout the Issues page and the Pull requests page (both Open and Closed tabs). If you decide to continue with the request, think of the merits of the feature to convince the project's developers, and provide as much detail and context as possible in the form of filing an issue on the Issues page.


<br/>

## Contributing Code
If you wish to contribute to the repository in the form of patches, improvements, new features, etc., first scale the contribution. If it is a major development, like implementing a feature, it is recommended that you consult with the developers of the project before starting the development in order not to risk spending a lot of time working on a change that might not get merged into the project. Once confirmed, you are welcome to submit your pull request.
</br>

### For new contributors, here is a quick guide:

1. Fork the repository.
2. Build the project using the [Dependencies](#dependencies) and [Tests](#tests) steps.
3. Install a <a href="https://virtualenv.pypa.io/en/latest/index.html">virtualenv</a>.
4. Develop your code and test the changes using the [Tests](#tests) and [Code Quality](#code-quality) steps.
5. Commit your changes
6. Push your fork and submit a pull request to the repository's `main` branch to propose your code.


A good pull request:
* is clear.
* works across all supported versions of Python. (3.7+)
* Follows the existing style of the code base (<a href="https://pypi.org/project/flake8/">`Flake8`</a>).
* Has comments included as needed.
* A test case that demonstrates the previous flaw that now passes with the included patch, or demonstrates the newly added feature.
* If it adds / changes a public API, it must also include documentation for those changes.
* Must be appropriately licensed (MIT License).
</br>

## Documentation Contributions
Documentation improvements are always welcome. The documentation files live in the [docs](./docs) directory of the repository and are written in <a href="https://docutils.sourceforge.io/rst.html">reStructuredText</a> and use <a href="https://www.sphinx-doc.org/en/master/">Sphinx</a> to create the full suite of documentation.
</br>
When contributing documentation, please do your best to follow the style of the documentation files. This means a soft-limit of 88 characters wide in your text files and a semi-formal, yet friendly and approachable, prose style. You can propose your imporvements by submiting a pull request as explained above.

### Need more information on how to contribute?
You can give this <a href="https://opensource.guide/how-to-contribute/#how-to-submit-a-contribution">guide</a> read for more insight.


<br/>

# License

This software is licensed under the MIT license. See [LICENSE](./LICENSE) for full disclosure.

## License

Terra SDK is licensed under the MIT License. More details are available [here](./LICENSE).
4 changes: 2 additions & 2 deletions docs/common/coin_coins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Coin & Coins
Coin
----

.. autoclass:: terra_sdk.core.coin.Coin
.. autoclass:: secret_sdk.core.coin.Coin
:members:


Coins
-----

.. autoclass:: terra_sdk.core.coins.Coins
.. autoclass:: secret_sdk.core.coins.Coins
:members:
2 changes: 1 addition & 1 deletion docs/common/exceptions.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Exceptions
==========

.. automodule:: terra_sdk.exceptions
.. automodule:: secret_sdk.exceptions
:members:
Loading

0 comments on commit 294e0d6

Please sign in to comment.