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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file antelopy-0.1.2.tar.gz.

File metadata

  • Download URL: antelopy-0.1.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Windows/10

File hashes

Hashes for antelopy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 553a3bd7d16c0d20886ed8f4d80819ab30c6becf61ba114e45983cabb01ac607
MD5 01b990dfc92f2c0cf6e7041fb8377c78
BLAKE2b-256 b97a19cf15cefefb46cbaafa89f1e1e0816ee27f37fd2bfa8e84b9849ab8be11

See more details on using hashes here.

File details

Details for the file antelopy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: antelopy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Windows/10

File hashes

Hashes for antelopy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8cfbe465fe698b01b1b4e6039e13774777a78d5061a1e5e648749fcb05794f38
MD5 f7ffd5f16d1da09477d83d302c341f7d
BLAKE2b-256 49ff780899e4377bea9ae4bd72793821348f39ff35d76749c6622cf63c8534b5

See more details on using hashes here.

Supported by

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