diff --git a/README.md b/README.md index 48661f3..a15dde2 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,34 @@ Utility library for parsing and processing the [Partisia Blockchain's ABI format](https://partisiablockchain.gitlab.io/documentation/smart-contracts/smart-contract-binary-formats.html).. +## Example usage + +This example is based upon the [Token Contract example contract](https://gitlab.com/partisiablockchain/language/example-contracts). +It assumes a compiled ABI in `token.abi` and a blockchain state stored in `token_state.bin`. + +```py +# Imports +from pbcabi.binaryreader import BinaryReader +import pbcabi.model + +# Read ABI +with open('token.abi', 'rb') as f: + TOKEN_ABI = pbcabi.model.FileAbi.read_from(BinaryReader(f.read())) + +with open('token_state.bin', 'rb') as f: + state_bytes = f.read() + +# Read structure TokenState from state_bytes +token_state = TOKEN_ABI.contract.read_state('TokenState', BinaryReader(state_bytes)) + +my_address = BlockchainAddress.from_hex_hash("00e72e44eab933faaf1fd4ce94bb57e08bff98a1ed") + +print(token_state['name']) +> MyToken +print(token_state['balances'][my_address]) +> 213112 +``` + ## Legalese This project is licensed under MIT Licence, see `LICENSE` for full text. diff --git a/pbcabi/__init__.py b/pbcabi/__init__.py index 2d8791d..91a7d3e 100644 --- a/pbcabi/__init__.py +++ b/pbcabi/__init__.py @@ -8,3 +8,11 @@ Follows the ABI specification quite closely. The full ABI specification can be f import pbcabi.model import pbcabi.binaryreader + +__version__ = "0.1.0" + +def get_version(): + """ + Returns a PEP 386-compliant version number from __version__. + """ + return __version__ diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3d8e3e7 --- /dev/null +++ b/setup.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from os import path +from io import open +from setuptools import setup, find_packages +from enforce_typing import get_version + +HERE = path.abspath(path.dirname(__file__)) + +with open(path.join(HERE, "README.md"), encoding="utf-8") as f: + LONG_DESCRIPTION = f.read() + +if __name__ == "__main__": + setup( + name="pbcabi", + version=get_version(), + description="Utility library for parsing and processing the Partisia Blockchain's ABI format", + long_description=LONG_DESCRIPTION, + long_description_content_type="text/markdown", + author="Jon Michael Aanes", + author_email="jonjmaa@gmail.com", + url="https://gitfub.space/Jmaa/pbcabi", + packages=find_packages(), + license="MIT", + python_requires=">=3.9", + classifiers=[], + ) +