Robonomics wrapper over https://github.com/polkascan/py-substrate-interface created to facilitate programming with Robonomics
Project description
robonomics-interface
This is a simple wrapper over https://github.com/polkascan/py-substrate-interface used to facilitate writing code for applications using Robonomics.
Robonomics project: https://robonomics.network/
Robonomics parachain dapp: https://parachain.robonomics.network/
Installation
pip3 install robonomics-interface
Usage
More info may be found in docstrings in the source code
import robonomicsinterface as RI
Initialization
interface = RI.RobonomicsInterface()
By default, you will only be able to fetch Chainstate info from Frontier parachain and use PubSub pattern.
You can specify another node address
(e.g. local), seed
to sign extrinsics (more on that later)
and custom registry types
.
By default, in the Frontier parachain there is a 10 minutes timeout, after which connection becomes broken.
But there is also a keep_alive
option that keeps websocket opened with ping()
calls in an
asynchronous event loop. Watch out using asyncio
with this option since keep_alive
tasks are added to main thread
event loop, which is running in another thread. More on that in a docstring of the method.
Simple case: fetch Chainstate
Here, no need to pass any arguments, by
interface = RI.RobonomicsInterface()
you will be able to read any Chainstate info from the Frontier parachain:
num_dt = interface.custom_chainstate("DigitalTwin", "Total")
you can also specify an argument for the query. Several arguments should be put in a list.
There is a dedicated function to obtain Datalog:
record = interface.fetch_datalog(<ss58_addr>)
This will give you the latest datalog record of the specified account with its timestamp. You may pass an index argument to fetch specific record. If you create an interface with a provided seed, you'll be able to fetch self-datalog calling fetch_datalog
with no arguments (or just the index
argument).
Extrinsics
Providing seed (any raw or mnemonic) while initializing will let you create and submit extrinsics:
interface = RI.RobonmicsInterface(seed:str = <seed>)
hash = interface.custom_extrinsic("DigitalTwin", "create")
hash
here is the transaction hash of the succeeded extrinsic. You can also specify arguments for the extrinsic as a dictionary.
There are dedicated functions for recording datalog and sending launch commands:
interface.record_datalog("Hello, Robonomics")
interface.send_launch(<target_addr>, True)
Current nonce definition and manual nonce setting is also possible.
Robonomics Web Services (RWS)
There are as well dedicated methods for convenient usage of RWS.
- Chainstate functions
auctionQueue
,auction
to examine subscriptions auctions:
interface.rws_auction_queue()
inteface.rws_auction(<auction_index>)
- Extrinsincs:
bid
,set_devices
and, the most important,call
interface.rws_bid(<auction_index>, <amount_weiners>)
interface.rws_set_devices([<ss58_addr>, <ss58_addr>])
interface.rws_custom_call(<subscription_owner_addr>,
<call_module>,
<call_function>,
<params_dict>)
There are as well dedicated datalog
and launch
functions for RWS-based transactions.
interface.rws_record_datalog(<subscription_owner_addr>, <data>)
interface.rws_send_launch(<subscription_owner_addr>, <target_addr>, True)
Subscriptions
There is a subscriptions functional implemented. When initiated, blocks thread and processes new events with a user-passed
callback function. Pay attention that this callback may only accept one argument - the event data. Up to now, the only supported
events are NewRecord
, NewLaunch
, Transfer
from robonomicsinterface import RobonomicsInterface, Subscriber, SubEvent
def callback(data):
print(data)
interface = RobonomicsInterface()
subscriber = Subscriber(interface, SubEvent.NewLaunch, callback, <ss58_addr>)
JSON RPC
WARNING: THIS MODULE IS UNDER CONSTRUCTIONS, USE AT YOUR OWN RISK! TO BE UPDATED SOON.
There is a way to implement robonomics pubsub rpc calls:
interface = RI.RobonomicsInterface()
pubsub = PubSub(interface)
pubsub.peer()
This is an evolving package, it may have errors and lack of functionality, fixes are coming. Feel free to open issues when faced a problem.
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 robonomics-interface-0.3.0.tar.gz
.
File metadata
- Download URL: robonomics-interface-0.3.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8b058607cb433ad5a23159ddc30bebebf9354d1982959180b5cd5e5468ddae9 |
|
MD5 | 01bf0dff5785467270d55fe7114e2ac1 |
|
BLAKE2b-256 | abce358850dd3b1e3897875839d975e5bfc85ab936c1325e369b16f8519931d6 |
File details
Details for the file robonomics_interface-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: robonomics_interface-0.3.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 722385230f3ba6f63774244233143bb307a80f50baf457618a78af4a87f00eca |
|
MD5 | 4385305c9011aedd859cfd6d67cdcef3 |
|
BLAKE2b-256 | c71d24ac5b34a397620879feb7d217546943b2cc95c2f907c399677cac8cac48 |