Example in readme
This commit is contained in:
parent
8580530e09
commit
6b2cacb7b8
28
README.md
28
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.
|
||||
|
|
|
@ -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__
|
||||
|
|
28
setup.py
Normal file
28
setup.py
Normal file
|
@ -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=[],
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user