-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env/ | ||
target/ | ||
_readthedocs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.11" | ||
rust: "1.70" | ||
commands: | ||
- pip install maturin[patchelf] | ||
- cd sdk && maturin build | ||
- pip install sdk/target/wheels/*.whl | ||
- pip install -r sdk/docs/requirements.txt | ||
- sphinx-build -M html sdk/docs/source/ _readthedocs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sphinx-autoapi==3.0.0 | ||
sphinx-rtd-theme==2.0.0 | ||
sphinxcontrib-applehelp==1.0.4 | ||
sphinxcontrib-devhelp==1.0.2 | ||
sphinxcontrib-htmlhelp==2.0.1 | ||
sphinxcontrib-jquery==4.1 | ||
sphinxcontrib-jsmath==1.0.1 | ||
sphinxcontrib-qthelp==1.0.3 | ||
sphinxcontrib-serializinghtml==1.1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
|
||
|
||
# We need to import the module to get __doc__ strings in runtime. | ||
import aleo | ||
|
||
|
||
# -- Project information | ||
|
||
project = 'aleo' | ||
copyright = '2023, AleoHQ' | ||
author = 'kpp' | ||
|
||
version = '0.2.0' | ||
|
||
# -- General configuration | ||
|
||
extensions = [ | ||
'sphinx.ext.autodoc', | ||
'sphinx.ext.doctest', | ||
'sphinx.ext.intersphinx', | ||
'autoapi.extension', | ||
] | ||
|
||
intersphinx_mapping = { | ||
'python': ('https://docs.python.org/3', None) | ||
} | ||
|
||
autoapi_dirs = ['../../'] | ||
autoapi_file_patterns = ['aleo.pyi'] | ||
autoapi_generate_api_docs = True | ||
autoapi_add_toctree_entry = False | ||
autoapi_keep_files = False | ||
|
||
autoapi_options = [ | ||
"members", | ||
"undoc-members", | ||
"show-inheritance", | ||
"show-module-summary", | ||
"imported-members", | ||
] | ||
|
||
autodoc_typehints = "signature" | ||
|
||
# We need to use autoapi because autodoc | ||
# doesn' twork with stub files. | ||
# | ||
# However when we use stub files, autodoc doesn't | ||
# know anything about __doc__ string from the .so library. | ||
# | ||
# So we need to monkey patch the autoapi objects to update | ||
# its obj._docstring to aleo.so.__doc__. | ||
def monkey_patch_documentation(app, what, name, obj, skip, options): | ||
def transform_docstring(doc): | ||
if doc: | ||
return doc.replace("\n", " ") + "\n" | ||
else: | ||
return '' | ||
|
||
if name.startswith("aleo"): | ||
if what == "module": | ||
doc = aleo.__doc__ | ||
obj._docstring = transform_docstring(doc) | ||
if what == "class": | ||
(module, klass) = name.split(".") | ||
klass = getattr(aleo, klass) | ||
doc = klass.__doc__ | ||
obj._docstring = transform_docstring(doc) | ||
if what == "method": | ||
(module, klass, method_name) = name.split(".") | ||
klass = getattr(aleo, klass) | ||
method = getattr(klass, method_name) | ||
if method_name == "from_bytes": | ||
obj.args = "bytes: bytes" | ||
doc = method.__doc__ | ||
obj._docstring = transform_docstring(doc) | ||
if what == "property": | ||
(module, klass, property_name) = name.split(".") | ||
klass = getattr(aleo, klass) | ||
property = getattr(klass, property_name) | ||
doc = property.__doc__ | ||
obj._docstring = transform_docstring(doc) | ||
return None | ||
|
||
def setup(sphinx): | ||
sphinx.connect("autoapi-skip-member", monkey_patch_documentation) | ||
|
||
# -- Options for HTML output | ||
|
||
html_theme = 'sphinx_rtd_theme' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Examples | ||
================= | ||
|
||
.. testsetup:: * | ||
|
||
import aleo | ||
|
||
Working with accounts | ||
********************* | ||
|
||
.. doctest:: | ||
|
||
>>> account = aleo.Account() | ||
>>> private_key = account.private_key() | ||
>>> secret = str(private_key) | ||
>>> restored = aleo.PrivateKey.from_string(secret) | ||
>>> same_account = aleo.Account.from_private_key(private_key) | ||
>>> assert account == same_account | ||
|
||
|
||
Working with signatures | ||
*********************** | ||
|
||
.. doctest:: | ||
|
||
>>> account = aleo.Account() | ||
>>> message = b'Hello world' | ||
>>> signature = account.sign(message) | ||
>>> serialized = str(signature) | ||
>>> restored = aleo.Signature.from_string(serialized) | ||
>>> assert account.verify(restored, message) | ||
|
||
|
||
Calling a **transfer_public** function | ||
************************************** | ||
|
||
.. doctest:: | ||
:options: +ELLIPSIS | ||
|
||
>>> private_key = aleo.PrivateKey() | ||
>>> destination = aleo.Account().address() | ||
>>> amount = aleo.Credits(0.3) | ||
>>> query = aleo.Query.rest("https://explorer.hamp.app") | ||
>>> process = aleo.Process.load() | ||
>>> credits = aleo.Program.credits() | ||
>>> process.add_program(credits) | ||
>>> transfer_name = aleo.Identifier.from_string("transfer_public") | ||
>>> transfer_auth = process.authorize(private_key, credits.id(), transfer_name, [ | ||
... aleo.Value.from_literal(aleo.Literal.from_address(destination)), | ||
... aleo.Value.from_literal(aleo.Literal.from_u64( | ||
... aleo.U64(int(amount.micro())))), | ||
... ]) | ||
>>> (_transfer_resp, transfer_trace) = process.execute(transfer_auth) | ||
>>> transfer_trace.prepare(query) | ||
>>> transfer_execution = transfer_trace.prove_execution( | ||
... aleo.Locator(credits.id(), aleo.Identifier.from_string("transfer"))) | ||
>>> execution_id = transfer_execution.execution_id() | ||
>>> process.verify_execution(transfer_execution) | ||
|
||
>>> (fee_cost, _) = process.execution_cost(transfer_execution) | ||
>>> fee_priority = None | ||
>>> fee_auth = process.authorize_fee_public( | ||
... private_key, fee_cost, execution_id, fee_priority) | ||
>>> (_fee_resp, fee_trace) = process.execute(fee_auth) | ||
>>> fee_trace.prepare(query) | ||
>>> fee = fee_trace.prove_fee() | ||
>>> process.verify_fee(fee, execution_id) | ||
|
||
>>> transaction = aleo.Transaction.from_execution(transfer_execution, fee) | ||
>>> transaction.to_json() | ||
'{"type":"execute","id":"at... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Welcome to Aleo's documentation! | ||
=================================== | ||
|
||
**aleo** is a Python SDK for the https://aleo.org/ project. | ||
|
||
.. note:: | ||
|
||
This project is under active development. | ||
|
||
Contents | ||
-------- | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
usage | ||
examples | ||
autoapi/aleo/index | ||
|
||
Indices and tables | ||
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`modindex` | ||
* :ref:`search` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
Installation | ||
------------ | ||
|
||
To use Aleo SDK, first install it using pip: | ||
|
||
.. code-block:: console | ||
(.venv) $ pip install aleo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters