Skip to main content

Python helper for Antelope transaction serialization

Project description

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

pip install antelopy

Example with aioeos

Loading a contract's ABI into the cache:

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)

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
  • Implement better type hinting for serialization
  • Expand test coverage
  • Add examples for aioeos, eospy, and pyantelope

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

antelopy-0.1.2.tar.gz (9.3 kB view hashes)

Uploaded Source

Built Distribution

antelopy-0.1.2-py3-none-any.whl (11.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page