-
Notifications
You must be signed in to change notification settings - Fork 1
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 17d67b3
Showing
16 changed files
with
573 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,113 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
bitcartcc: bitcartcc/bitcartcc-shared@1 | ||
|
||
executors: | ||
main-executor: | ||
parameters: | ||
v: | ||
type: string | ||
default: "3.8" | ||
|
||
docker: | ||
- image: cimg/python:<< parameters.v >> | ||
|
||
environment: | ||
TEST_ARGS: "--junitxml test-results/pytest/coverage.xml --cov-report html:coverage" | ||
|
||
commands: | ||
install_dependencies: | ||
steps: | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ .Branch }}-{{ checksum "~/.pyenv/version" }}-{{ checksum "setup.py" }}-{{ checksum "test-requirements.txt" }} | ||
|
||
- run: | ||
name: install library | ||
command: | | ||
virtualenv ~/venv | ||
echo ". ~/venv/bin/activate" >> $BASH_ENV | ||
source $BASH_ENV | ||
pip install . | ||
pip install -U -r test-requirements.txt | ||
- save_cache: | ||
paths: | ||
- ~/venv | ||
key: v1-dependencies-{{ .Branch }}-{{ checksum "~/.pyenv/version" }}-{{ checksum "setup.py" }}-{{ checksum "test-requirements.txt" }} | ||
|
||
jobs: | ||
test: | ||
parameters: | ||
v: | ||
type: string | ||
|
||
executor: | ||
name: main-executor | ||
v: << parameters.v >> | ||
|
||
environment: | ||
PYTHON: << parameters.v >> | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
- install_dependencies | ||
|
||
- run: | ||
name: run tests | ||
command: | | ||
make ci | ||
codecov -F tests -e PYTHON | ||
- bitcartcc/upload-test-results | ||
|
||
deploy: | ||
executor: bitcartcc/docker-python | ||
steps: | ||
- checkout | ||
|
||
- run: | ||
name: setup credentials | ||
command: | | ||
echo -e "[pypi]" >> ~/.pypirc | ||
echo -e "username = $PYPI_USER" >> ~/.pypirc | ||
echo -e "password = $PYPI_PASS" >> ~/.pypirc | ||
- run: | ||
name: create env, build dist and upload | ||
command: | | ||
virtualenv ~/venv | ||
. ~/venv/bin/activate | ||
pip install -U wheel twine | ||
python setup.py sdist | ||
python setup.py bdist_wheel | ||
twine upload dist/* | ||
workflows: | ||
version: 2 | ||
test_and_deploy: | ||
jobs: | ||
- bitcartcc/lint: | ||
name: lint | ||
- test: | ||
name: test-<< matrix.v >> | ||
requires: | ||
- lint | ||
matrix: | ||
parameters: | ||
v: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
|
||
- deploy: | ||
context: global | ||
filters: | ||
tags: | ||
only: /[0-9]+(\.[0-9]+)*/ | ||
branches: | ||
ignore: /.*/ |
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,20 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[Makefile] | ||
indent_style = tab | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 | ||
|
||
[*.md] | ||
indent_size = 2 | ||
trim_trailing_whitespace = 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,6 @@ | ||
[flake8] | ||
max-complexity=11 | ||
max-line-length=127 | ||
ignore=E266 # for code sections as comments | ||
E203, W503 # black compatibility | ||
exclude=trontxsize/tron_pb2.py |
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,14 @@ | ||
*.egg-info/ | ||
.coverage | ||
.idea/ | ||
.mypy_cache/ | ||
.vscode/ | ||
__pycache__/ | ||
backup/ | ||
backups/ | ||
build/ | ||
dist/ | ||
docs/_build | ||
env/ | ||
htmlcov/ | ||
venv/ |
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,53 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- repo: https://github.com/asottile/yesqa | ||
rev: v1.3.0 | ||
hooks: | ||
- id: yesqa | ||
- repo: https://github.com/psf/black | ||
rev: 22.6.0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/pycqa/isort | ||
rev: 5.10.1 | ||
hooks: | ||
- id: isort | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.9.2 | ||
hooks: | ||
- id: flake8 | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v2.34.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: ["--py38-plus"] | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- id: mixed-line-ending | ||
- id: file-contents-sorter | ||
files: | | ||
.gitignore| | ||
- id: requirements-txt-fixer | ||
- id: check-case-conflict | ||
- id: check-shebang-scripts-are-executable | ||
- id: check-json | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: check-symlinks | ||
- id: debug-statements | ||
- id: fix-byte-order-marker | ||
- id: fix-encoding-pragma | ||
args: ["--remove"] | ||
- id: detect-private-key | ||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: v2.7.1 | ||
hooks: | ||
- id: prettier | ||
exclude: >- | ||
^trontxsize/tron_pb2.py$ |
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) 2022 MrNaif2018 | ||
|
||
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,17 @@ | ||
all: ci | ||
|
||
lint: | ||
flake8 | ||
|
||
checkformat: | ||
black --check . | ||
isort --check . | ||
|
||
format: | ||
black . | ||
isort . | ||
|
||
test: | ||
pytest tests/ ${TEST_ARGS} | ||
|
||
ci: checkformat lint test |
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,25 @@ | ||
# trontxsize - Calculate tron transaction size in bytes | ||
|
||
[![CircleCI](https://circleci.com/gh/bitcartcc/trontxsize.svg?style=svg)](https://circleci.com/gh/bitcartcc/trontxsize) | ||
[![Codecov](https://img.shields.io/codecov/c/github/bitcartcc/trontxsize?style=flat-square)](https://codecov.io/gh/bitcartcc/trontxsize) | ||
[![PyPI version](https://img.shields.io/pypi/v/trontxsize.svg?style=flat-square)](https://pypi.python.org/pypi/trontxsize/) | ||
|
||
In Tron (TRX) network, fee calculation algorithm is complex. And the most complex part of it is that it depends on transaction size. | ||
|
||
But there's no method existing to calculate it | ||
|
||
This library does just this: | ||
|
||
```python | ||
import trontxsize | ||
|
||
print(trontxsize.get_tx_size({"raw_data": ..., "signatures": [...])) # matches bandwidth you see in block explorer | ||
``` | ||
|
||
How does it work? The library pre-compiled a trimmed-down version of Tron protobuf and uses it directly to calculate transaction size | ||
|
||
## Copyright and License | ||
|
||
Copyright (C) 2022 MrNaif2018 | ||
|
||
Licensed under the [MIT License](LICENSE) |
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,25 @@ | ||
[tool.black] | ||
line-length = 127 | ||
extend-exclude="trontxsize/tron_pb2.py" | ||
|
||
[tool.isort] | ||
profile = "black" | ||
line_length = 127 | ||
|
||
[tool.pytest.ini_options] | ||
addopts = [ | ||
"--cov=trontxsize", | ||
"--cov-report", | ||
"term-missing", | ||
] | ||
filterwarnings = [ | ||
"error::DeprecationWarning", | ||
"error::PendingDeprecationWarning", | ||
"ignore:.*The toolz.compatibility module is no longer needed.*:DeprecationWarning:eth_utils.toolz" | ||
] | ||
|
||
[tool.coverage.run] | ||
source = ["."] | ||
omit = [ | ||
"trontxsize/tron_pb2.py" | ||
] |
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,27 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name="trontxsize", | ||
packages=find_packages(), | ||
version="1.0.0", | ||
license="MIT", | ||
description="Calculate tron transaction size (bandwidth)", | ||
long_description=open("README.md").read(), | ||
long_description_content_type="text/markdown", | ||
author="MrNaif2018", | ||
author_email="[email protected]", | ||
url="https://github.com/bitcartcc/trontxsize", | ||
keywords=["tron", "trx", "bitcartcc", "bandwidth"], | ||
install_requires=["protobuf", "base58"], | ||
classifiers=[ | ||
"Development Status :: 5 - Production/Stable", | ||
"Intended Audience :: Developers", | ||
"Topic :: Software Development :: Build Tools", | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
], | ||
python_requires=">=3.8", | ||
) |
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,8 @@ | ||
black | ||
codecov | ||
flake8 | ||
isort | ||
pre-commit | ||
pytest | ||
pytest-cov | ||
tronpy |
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,22 @@ | ||
import pytest | ||
from tronpy import Tron | ||
|
||
import trontxsize | ||
|
||
tron = Tron(network="nile") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"tx_hash,size", | ||
[ | ||
["29e7d53e7b1463d354d1d7d90172fba89673e7bc5b0c7c441c14152a897ee363", 267], | ||
["546b52f2fe19955ba57cd431752e0e290d33a3b1670d1ad0820eb765110295bc", 283], | ||
["cd0fc9dbe9999c7beee2cee0bcd1af39bd797802d85af4e35ded9adddcd9d764", 314], | ||
["293f00a9f5415617a9889218ffed86f1d2bf78552557d2562eaa3358160c43c1", 346], | ||
["9c533f0257397642f10573676f0769b5d58d68c767c661fbf9405a032a55cb6a", 345], | ||
], | ||
) | ||
def test_tx_size_works(tx_hash, size): | ||
tx_data = tron.get_transaction(tx_hash) | ||
data = {"raw_data": tx_data["raw_data"], "signature": tx_data["signature"]} | ||
assert trontxsize.get_tx_size(data) == size |
Oops, something went wrong.