Metadata-Version: 2.1
Name: antelopy
Version: 0.1.2
Summary: Python helper for Antelope transaction serialization
Home-page: https://python-poetry.org/
License: MIT
Author: Jake Hattwell
Author-email: stuck@sixpm.dev
Requires-Python: >=3.8,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: base58 (>=2.1.1,<3.0.0)
Requires-Dist: pydantic (>=2.4.2,<3.0.0)
Requires-Dist: requests (>=2.31.0,<3.0.0)
Description-Content-Type: text/markdown

# antelopy

*v0.1.2 - initial release*

Drop-in Python ABI cache for Antelope chains with local serialization support. 

## Features
* Serialization of Antelope built-in types
* Caches ABIs for faster serialization of actions
* Support for ABI custom types/variants

## Basic Usage:
*Note: Reading ABIs uses `requests` and is not asynchronous.*

### Instaliation

```bash
pip install antelopy
```

### Example with aioeos
**Loading a contract's ABI into the cache:**
```py
from antelopy import AbiCache

CHAIN_ENDPOINT = "https://wax.eosphere.io"

# Create ABI Cache and read the Atomic Assets contract ABI
abicache = AbiCache(chain_endpoint=CHAIN_ENDPOINT)
abicache.read_abi("atomicassets")
```


**Serializing, signing, and pushing a transaction** *(modified version of aioeos' built-in `EosTransaction.sign_and_push_transaction` function)*
```py
import asyncio
import binascii
import hashlib
from antelopy import AbiCache
from aioeos import EosAccount, EosJsonRpc, EosTransaction, serializer

CHAIN_ENDPOINT = "https://wax.eosphere.io"

# Create ABI Cache and read the Atomic Assets contract ABI
abicache = AbiCache(chain_endpoint=CHAIN_ENDPOINT)
abicache.read_abi("atomicassets")

# Fake Account
wax_account = EosAccount(
    name="testaccount1",
    private_key="your private key"
)

# 
rpc = EosJsonRpc(CHAIN_ENDPOINT)

transaction = EosTransaction(
    # transaction data
)
async def serialize_sign_and_push(transaction: EosTransaction):
    for action in transaction.actions: 
        if isinstance(action.data, dict):
            # This {"binargs": serialized_data} structure emulates
            # the response from the old `abi_json_to_bin` endpoint.
            abi_bin = {"binargs":abicache.serialize_data(action.account,action.name, action.data)}
            action.data = binascii.unhexlify(abi_bin['binargs'])

    chain_id = await RPC.get_chain_id()
    serialized_transaction = serializer.serialize(transaction)

    digest = hashlib.sha256(
        b''.join((chain_id, serialized_transaction, bytes(32)))
    ).digest()

    return await RPC.push_transaction(
        signatures=[key.sign(digest) for key in [wax_account.key]],
        serialized_transaction=(
            binascii.hexlify(serialized_transaction).decode()
        )
    )

await serialize_sign_and_push(transaction)
```

## Todo:
* Implement remaining types
* refactor serializers to class based approach, similar to [aioeos](https://github.com/ulamlabs/aioeos/blob/master/aioeos/serializer.py)
* Implement better type hinting for serialization
* Expand test coverage
* Add examples for aioeos, eospy, and pyantelope
