Python wrapper around the BUTXO Equity compiler for Bytom protocol.
Project description
PY-EQUITY
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
LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-equity-0.1.0.tar.gz
.
File metadata
- Download URL: py-equity-0.1.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3840e03805851b6da91ce09d9ea39223aadae16ec6455c9f1a3021574c51e094 |
|
MD5 | 87f7440272905221571a297dec1ccd2e |
|
BLAKE2b-256 | debc382956f48701d6a06530435c2dd6b0efa995a6188062b9c98f0d464a3073 |
File details
Details for the file py_equity-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: py_equity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0271a63c08ff1e521fe00dbd5b934bb26fc53d8502b473bf93843acab228e4e4 |
|
MD5 | 46445e8e771de378dda81469051f6782 |
|
BLAKE2b-256 | 9929b89584131b4f02269fbf656ab651d809a9244060957d331170bc3d710c4c |