Skip to content

Python helper for Antelope transaction serialization

License

Notifications You must be signed in to change notification settings

callmenemo491/antelopy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

antelopy

Workflow Badge Python version PyPI

v0.1.6 - 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
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 = abi_cache.unhexlify(abi_bin['binargs'])

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

    digest = abi_cache.sha256digest(
        b''.join((chain_id, serialized_transaction, bytes(32)))
    )

    return await RPC.push_transaction(
        signatures=[key.sign(digest) for key in [wax_account.key]],
        serialized_transaction=(
            abi_cache.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

About

Python helper for Antelope transaction serialization

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%