-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 689c1d7
Showing
27 changed files
with
2,564 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Python package | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python_version: [3.7] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python_version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python_version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install poetry | ||
poetry install | ||
- name: Lint with flake8 | ||
run: | | ||
poetry run flake8 | ||
- name: Test with pytest | ||
run: | | ||
poetry run pytest --cov --cov-report xml | ||
- name: Uploading coverage | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ./coverage.xml # optional | ||
flags: unittests # optional | ||
name: codecov-umbrella # optional | ||
fail_ci_if_error: true # optional (default = false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This workflows will upload a Python Package using Twine when a release is created | ||
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
|
||
name: Upload Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install poetry | ||
poetry install | ||
- name: Build and publish | ||
env: | ||
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
poetry build | ||
poetry publish -u $PYPI_USERNAME -p $PYPI_PASSWORD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# python | ||
__pycache__ | ||
*.pyc | ||
*.pyd | ||
*.so | ||
*.o | ||
*.def | ||
*.egg-info | ||
.coverage | ||
.pytest_cache | ||
.env | ||
venv | ||
build | ||
dist | ||
|
||
# ides | ||
.vscode | ||
.favorites.json | ||
.idea | ||
*.swp | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# files | ||
*.log | ||
data-test | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build: | ||
image: latest | ||
python: | ||
version: 3.7 | ||
pip_install: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Maciej Janiszewski | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# aioeos | ||
|
||
[![Documentation Status](https://readthedocs.org/projects/aioeos/badge/?version=latest)](http://aioeos.readthedocs.io/en/latest/?badge=latest) [![codecov](https://codecov.io/gh/ksiazkowicz/aioeos/branch/master/graph/badge.svg)](https://codecov.io/gh/ksiazkowicz/aioeos) ![Python package](https://github.com/ksiazkowicz/aioeos/workflows/Python%20package/badge.svg) ![Upload Python Package](https://github.com/ksiazkowicz/aioeos/workflows/Upload%20Python%20Package/badge.svg) | ||
|
||
Async Python library for interacting with EOS.io blockchain. Library consists of an async wrapper for [Nodeos RPC API](https://developers.eos.io/eosio-nodeos/docs), a simple serializer for basic ABI types like transactions and actions and private key management. Helpers for generating actions such as creating new accounts, buying and selling RAM etc. can be imported from `aioeos.contracts` namespace. | ||
|
||
Please bear in mind that the serializer is not complete. Action payloads need | ||
to be converted to binary format using `/abi_json_to_bin` endpoint on the RPC node. Use only nodes you trust. | ||
|
||
## Usage examples | ||
Converting action payload to binary format: | ||
``` | ||
rpc = EosJsonRpc() | ||
response = await rpc.abi_json_to_bin( | ||
action.account, action.name, action.data | ||
) | ||
action.data = binascii.unhexlify(response['binargs']) | ||
``` | ||
|
||
Creating a basic transaction: | ||
``` | ||
auth = [EosAuthorization(actor=from_addr, permission='active')] | ||
action = await convert_action_abi_to_bin( | ||
eosio_token.transfer(from_addr, to_addr, amount, authorization=auth) | ||
) | ||
transaction = EosTransaction( | ||
actions=[ | ||
eosio_token.transfer(from_addr, to_addr, amount, authorization=auth) | ||
] | ||
) | ||
keys = [EOSKey(private_key)] | ||
``` | ||
|
||
``` | ||
import binascii | ||
from aioeos import serializer | ||
from aioeos.contracts import eosio_token | ||
from aioeos.keys import EOSKey | ||
from aioeos.rpc import EosJsonRpc | ||
from aioeos.types import EosAuthorization, EosTransaction | ||
async def convert_action_abi_to_bin(action): | ||
rpc = EosJsonRpc() | ||
response = await rpc.abi_json_to_bin( | ||
action.account, action.name, action.data | ||
) | ||
action.data = binascii.unhexlify(response['binargs']) | ||
return action | ||
async def transfer(from_addr, to_addr, amount, private_key): | ||
rpc = EosJsonRpc() | ||
auth = [EosAuthorization(actor=from_addr, permission='active')] | ||
action = await convert_action_abi_to_bin( | ||
eosio_token.transfer(from_addr, to_addr, amount, authorization=auth) | ||
) | ||
transaction = EosTransaction( | ||
actions=[ | ||
eosio_token.transfer(from_addr, to_addr, amount, authorization=auth) | ||
] | ||
) | ||
keys = [EOSKey(private_key)] | ||
``` |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Helpers for creating actions on eosio contract""" | ||
from aioeos.types import EosAction | ||
|
||
|
||
def newaccount( | ||
creator, account_name, owner_keys, active_keys=None, authorization=[] | ||
) -> EosAction: | ||
active_keys = owner_keys if not active_keys else active_keys | ||
return EosAction( | ||
account='eosio', | ||
name='newaccount', | ||
authorization=authorization, | ||
data={ | ||
'creator': creator, | ||
'name': account_name, | ||
'owner': owner_keys, | ||
'active': active_keys | ||
} | ||
) | ||
|
||
|
||
def buyrambytes(payer, receiver, amount, authorization=[]) -> EosAction: | ||
return EosAction( | ||
account='eosio', | ||
name='buyrambytes', | ||
authorization=authorization, | ||
data={ | ||
'payer': payer, | ||
'receiver': receiver, | ||
'bytes': amount | ||
} | ||
) | ||
|
||
|
||
def sellram(account, amount, authorization=[]) -> EosAction: | ||
return EosAction( | ||
account='eosio', | ||
name='sellram', | ||
authorization=authorization, | ||
data={ | ||
'account': account, | ||
'bytes': amount | ||
} | ||
) | ||
|
||
|
||
def delegatebw( | ||
from_account, receiver, stake_net_quantity, stake_cpu_quantity, | ||
transfer=False, authorization=[] | ||
) -> EosAction: | ||
return EosAction( | ||
account='eosio', | ||
name='delegatebw', | ||
authorization=authorization, | ||
data={ | ||
'from': from_account, | ||
'receiver': receiver, | ||
'stake_net_quantity': stake_net_quantity, | ||
'stake_cpu_quantity': stake_cpu_quantity, | ||
'transfer': transfer | ||
} | ||
) | ||
|
||
|
||
def undelegatebw( | ||
from_account, receiver, unstake_net_quantity, unstake_cpu_quantity, | ||
authorization=[] | ||
) -> EosAction: | ||
return EosAction( | ||
account='eosio', | ||
name='undelegatebw', | ||
authorization=authorization, | ||
data={ | ||
'from': from_account, | ||
'receiver': receiver, | ||
'unstake_net_quantity': unstake_net_quantity, | ||
'unstake_cpu_quantity': unstake_cpu_quantity, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Helpers for creating actions on eosio.token contract""" | ||
from aioeos.types import EosAction | ||
|
||
|
||
def transfer( | ||
from_addr: str, | ||
to_addr: str, | ||
quantity: str, | ||
memo: str = '', | ||
authorization=[] | ||
) -> EosAction: | ||
return EosAction( | ||
account='eosio.token', | ||
name='transfer', | ||
authorization=authorization, | ||
data={ | ||
'from': from_addr, | ||
'to': to_addr, | ||
'quantity': quantity, | ||
'memo': memo | ||
} | ||
) | ||
|
||
|
||
def close(owner, symbol, authorization=[]) -> EosAction: | ||
return EosAction( | ||
account='eosio.token', | ||
name='close', | ||
authorization=authorization, | ||
data={ | ||
'owner': owner, | ||
'symbol': symbol | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class EosRpcException(Exception): | ||
"""Base EOS exception""" | ||
|
||
|
||
class EosAccountExistsException(EosRpcException): | ||
"""Thrown by create_wallet where account with given name already exists""" | ||
|
||
|
||
class EosAccountDoesntExistException(EosRpcException): | ||
"""Thrown by get_account where account doesn't exist""" | ||
|
||
|
||
class EosActionValidateException(EosRpcException): | ||
"""Raised when action payload is invalid""" | ||
|
||
|
||
class EosMissingTaposFieldsException(EosRpcException): | ||
"""TAPOS fields are missing from Transaction object""" | ||
|
||
|
||
class EosSerializerUnsupportedTypeException(EosRpcException): | ||
"""Our serializer doesn't support provided object type, shouldn't happen""" | ||
|
||
|
||
class EosDeadlineException(EosRpcException): | ||
"""Transaction timed out""" | ||
|
||
|
||
class EosTxCpuUsageExceededException(EosRpcException): | ||
"""Not enough EOS were staked for CPU""" | ||
|
||
|
||
class EosTxNetUsageExceededException(EosRpcException): | ||
"""Not enough EOS were staked for NET""" | ||
|
||
|
||
class EosRamUsageExceededException(EosRpcException): | ||
"""Transaction requires more RAM than what's available on the account""" | ||
|
||
|
||
class EosAssertMessageException(EosRpcException): | ||
""" | ||
Generic assertion error from smart contract, can mean literally anything, | ||
need to parse C++ traceback to figure out what went wrong. | ||
""" |
Oops, something went wrong.