Skip to main content

PY-EQUITY

Build Status PyPI License PyPI Version Coverage Status

Python wrapper around the BUTXO Equity compiler for Bytom protocol.

Installation

$ pip install py-equity

Development

We welcome pull requests. To get started, just fork this repo, clone it locally, and run:

$ pip install -e . -r requirements.txt

Quick Usage

from equity import Equity

LOCK_WITH_PUBLIC_KEY_SOURCE = """
    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {
      clause spend(sig: Signature) {
        verify checkTxSig(publicKey, sig)
        unlock valueAmount of valueAsset
      }
    }
"""

LOCK_WITH_PUBLIC_KEY_PATH = "./LockWithPublicKey.equity"

# LOCK_WITH_PUBLIC_KEY_ARGS = [
#     "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78"
# ]

equity = Equity("http://localhost:9888")

COMPILED = equity.compile_source(LOCK_WITH_PUBLIC_KEY_SOURCE,
                                 "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78")

print(COMPILED["name"])
print(COMPILED["program"])
print(COMPILED["opcodes"])

print(COMPILED)

# Save compiled contract
equity.save()

OUTPUT

'LockWithPublicKey'
'20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0'
'0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78 DEPTH 0xae7cac FALSE CHECKPREDICATE'

{'name': 'LockWithPublicKey', 'source': '\n    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {\n      clause spend(sig: Signature) {\n        verify checkTxSig(publicKey, sig)\n        unlock valueAmount of valueAsset\n      }\n    }\n', 'program': '20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0', 'params': [{'name': 'publicKey', 'type': 'PublicKey'}], 'value': 'valueAmount of valueAsset', 'clause_info': [{'name': 'spend', 'params': [{'name': 'sig', 'type': 'Signature'}], 'values': [{'name': '', 'asset': 'valueAsset', 'amount': 'valueAmount'}]}], 'opcodes': '0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78 DEPTH 0xae7cac FALSE CHECKPREDICATE', 'error': ''}

CLI

Command line interface, run the following command:

$ eqt --version

Example eqt:

$ eqt --file LockWithPublicKey.equity --args "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78"

Get help:

$ eqt --help

From there, you can run eqt more commands, -s\--save to save your contract, -u\--url to change Bytom API url. by default (http://localhost:9888).

Testing

You can run the tests with:

$ pytest tests

Or use tox to run the complete suite against the full set of build targets, or pytest to run specific tests against a specific version of Python.

API

Class Equity()

Parameters

Optional:

  • String - url, Bytom API url, by default (http://localhost:9888).
  • String - api_key, Bytom API key.
  • Integer - timeout, request timeout, by default (1).

compile_source(): It is to compiling Bytom smart contract(Equity source).

Parameters

Object:

  • String - equity_source, Equity source code.

Optional:

  • Boolean/String/Integer/Array - *argv.
    • Boolean - boolean, boolean parameter.
    • String - string, string parameter.
    • Integer - integer, integer parameter.

Returns

Object:

  • String - name, contract name.
  • String - source, contract source code.
  • String - program, contract program.
  • Array - params, contract params.
  • String - value, contract value.
  • Array - clause_info, contract clause_info.
  • Array - values, contract values.
  • String - opcodes, contract opcodes.
  • String - error, contract error.

Example

LOCK_WITH_PUBLIC_KEY_SOURCE = """
    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {
      clause spend(sig: Signature) {
        verify checkTxSig(publicKey, sig)
        unlock valueAmount of valueAsset
      }
    }
"""
equity = Equity("http://localhost:9888", timeout=5)
COMPILED = equity.compile_source(LOCK_WITH_PUBLIC_KEY_SOURCE,
                                 "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78")

print(COMPILED)
Output
{'name': 'LockWithPublicKey', 'source': '\n    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {\n      clause spend(sig: Signature) {\n        verify checkTxSig(publicKey, sig)\n        unlock valueAmount of valueAsset\n      }\n    }\n', 'program': '20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0', 'params': [{'name': 'publicKey', 'type': 'PublicKey'}], 'value': 'valueAmount of valueAsset', 'clause_info': [{'name': 'spend', 'params': [{'name': 'sig', 'type': 'Signature'}], 'values': [{'name': '', 'asset': 'valueAsset', 'amount': 'valueAmount'}]}], 'opcodes': '0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78 DEPTH 0xae7cac FALSE CHECKPREDICATE', 'error': ''}

compile_file(): It is to compiling Bytom smart contract form Equity file.

Parameters

Object:

  • String - equity_source, Equity source code file(.equity or .eqt).

Optional:

  • Boolean/String/Integer/Array - *argv.
    • Boolean - boolean, boolean parameter.
    • String - string, string parameter.
    • Integer - integer, integer parameter.

Returns

Object:

  • String - name, contract name.
  • String - source, contract source code.
  • String - program, contract program.
  • Array - params, contract params.
  • String - value, contract value.
  • Array - clause_info, contract clause_info.
  • Array - values, contract values.
  • String - opcodes, contract opcodes.
  • String - error, contract error.

Example

LOCK_WITH_PUBLIC_KEY_PATH = "./LockWithPublicKey.equity"
equity = Equity("http://localhost:9888", timeout=5)
COMPILED = equity.compile_file(LOCK_WITH_PUBLIC_KEY_PATH,
                               "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78")

print(COMPILED)
Output
{'name': 'LockWithPublicKey', 'source': '\n    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {\n      clause spend(sig: Signature) {\n        verify checkTxSig(publicKey, sig)\n        unlock valueAmount of valueAsset\n      }\n    }\n', 'program': '20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0', 'params': [{'name': 'publicKey', 'type': 'PublicKey'}], 'value': 'valueAmount of valueAsset', 'clause_info': [{'name': 'spend', 'params': [{'name': 'sig', 'type': 'Signature'}], 'values': [{'name': '', 'asset': 'valueAsset', 'amount': 'valueAmount'}]}], 'opcodes': '0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78 DEPTH 0xae7cac FALSE CHECKPREDICATE', 'error': ''}

save(): Save compiled equity source.

Parameters

Optional:

  • String - file_path, It is for full path with name.
  • String - dir_path, It is for only dir path.

Returns

Object:

  • String - name, contract name.

AUTHOR

MEHERET TESFAYE

LICENSE

AGPLv3+

Metadata

Release files for py-equity 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-equity 0.1.0
File Size Uploaded
py-equity-0.1.0.tar.gz 19.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-equity 0.1.0
File Interpreter ABI Platform
py_equity-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.8 kB

Release files / py-equity-0.1.0.tar.gz

Download URL py-equity-0.1.0.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3840e03805851b6da91ce09d9ea39223aadae16ec6455c9f1a3021574c51e094
BLAKE2b-256 checksum
How to use checksums
debc382956f48701d6a06530435c2dd6b0efa995a6188062b9c98f0d464a3073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

Release files / py_equity-0.1.0-py3-none-any.whl

Download URL py_equity-0.1.0-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0271a63c08ff1e521fe00dbd5b934bb26fc53d8502b473bf93843acab228e4e4
BLAKE2b-256 checksum
How to use checksums
9929b89584131b4f02269fbf656ab651d809a9244060957d331170bc3d710c4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page