Skip to content

Commit

Permalink
docs: add async api
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Oct 23, 2020
1 parent 9d2800d commit cca9d2c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
47 changes: 47 additions & 0 deletions docs/async.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
The Async API
=============

TronPy offers a standard synchronous API by default,
but also introduces an async client via `httpx <https://www.python-httpx.org/>`_.

The async client is ``AsyncTron``. It almost uses the same API as the synchronous client ``Tron``.

.. code-block:: python
import asyncio
from tronpy import AsyncTron
from tronpy.keys import PrivateKey
# private key of TMisHYBVvFHwKXHPYTqo8DhrRPTbWeAM6z
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
async def transfer():
async with AsyncTron(network='nile') as client:
print(client)
txb = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.fee_limit(100_000_000)
)
txn = await txb.build()
print(txn)
txn_ret = await txn.sign(priv_key).broadcast()
print(txn_ret)
# > {'result': True, 'txid': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b'}
print(await txn_ret.wait())
# > {'id': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b', 'blockNumber': 10163821,
# > 'blockTimeStamp': 1603368072000, 'contractResult': [''], 'receipt': {'net_usage': 283}}
if __name__ == '__main__':
asyncio.run(transfer())
API reference
-------------

.. autoclass:: tronpy.AsyncTron
:members:

.. autoclass:: tronpy.async_tron.AsyncTrx
:members:
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Welcome to TronPy's documentation!
contract.rst
shielded.rst
abi.rst
async.rst
exceptions.rst


TronPy is an easy-to-use TRON HTTP API client. It supports most of the java-tron 3.7 APIs, and with an experimental 4.0
Shielded TRC20 Contract API support.
TronPy is an easy-to-use TRON HTTP API client. It supports most of the java-tron 4.1 APIs.

.. note::

Expand Down
8 changes: 2 additions & 6 deletions tronpy/async_tron.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,8 @@ async def get_latest_block_number(self) -> int:
async def get_block(self, id_or_num: Union[None, str, int] = None, *, visible: bool = True) -> dict:
"""Get block from a block id or block number.
Parameters
----------
id_or_num
Block number, or Block hash(id), or ``None`` (default) to get the latest block.
visible : bool
Use ``visible=False`` to get non-base58check addresses and strings instead of hex strings.
:param id_or_num: Block number, or Block hash(id), or ``None`` (default) to get the latest block.
:param visible: Use ``visible=False`` to get non-base58check addresses and strings instead of hex strings.
"""

if isinstance(id_or_num, (int,)):
Expand Down
8 changes: 2 additions & 6 deletions tronpy/tron.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,8 @@ def get_latest_block_number(self) -> int:
def get_block(self, id_or_num: Union[None, str, int] = None, *, visible: bool = True) -> dict:
"""Get block from a block id or block number.
Parameters
----------
id_or_num
Block number, or Block hash(id), or ``None`` (default) to get the latest block.
visible : bool
Use ``visible=False`` to get non-base58check addresses and strings instead of hex strings.
:param id_or_num: Block number, or Block hash(id), or ``None`` (default) to get the latest block.
:param visible: Use ``visible=False`` to get non-base58check addresses and strings instead of hex strings.
"""

if isinstance(id_or_num, (int,)):
Expand Down

0 comments on commit cca9d2c

Please sign in to comment.