-
Notifications
You must be signed in to change notification settings - Fork 648
Websocket Subscriptions
Fabian Schuh edited this page Sep 15, 2015
·
4 revisions
We first ask for access to the database
-api with
> {"id":2,"method":"call","params":[0,"database",[]]}
< {"id":2,"result":1}
The result
will be our DATABASE_API_ID
!
All objects can be subscribed to in order to get notified by the wallet via websocket whenever the object changes. To simplify development a global subscription callback can be registered with the following RPC
> {"id":4,"method":"call","params":[DATABASE_API_ID,"set_subscribe_callback",[SUBSCRIPTION_ID]]}
This call above will register SUBSCRIPTION_ID
as id for notifications.
After calling set_subscribe_callback
the wallet will start to receive notices
every time the object changes:
< {
"method": "notice"
"params": [
SUBSCRIPTION_ID,
[
{
"current_witness": "1.7.5",
"head_block_number": 5,
"random": "2033120557c36e278db2eaad818494f791ff4d7b0418858a7ab9b5a8",
"head_block_id": "00000005171f82f1b6bd948e7d58d95e572001fd",
"next_maintenance_time": "2015-05-02T00:00:00",
"time": "2015-05-01T13:05:50",
"id": "2.1.0"
}
]
],
}
Here is an example of a full session:
> {"id":1,"method":"call","params":[0,"login",["",""]]}
< {"id":1,"result":true}
> {"id":2,"method":"call","params":[0,"database",[]]}
< {"id":2,"result":1}
> {"id":3,"method":"call","params":[1,"set_subscribe_callback",[200]]}
< {"id":3,"result":true}
< {"method":"notice","params":[200,[{"id":"2.1.0","random":"2033120557c36e278db2eaad818494f791ff4d7b0418858a7ab9b5a8","head_block_number":5,"head_block_id":"00000005171f82f1b6bd948e7d58d95e572001fd","time":"2015-05-01T13:05:50","current_witness":"1.7.5","next_maintenance_time":"2015-05-02T00:00:00"}]]}
< {"method":"notice","params":[200,[{"id":"2.1.0","random":"9d5ff7e453db4815005eb42ddd040e3afb459950f75f4440deb3dec0","head_block_number":6,"head_block_id":"000000060e3369d6feaf330ea9114cd855c93aab","time":"2015-05-01T13:05:55","current_witness":"1.7.3","next_maintenance_time":"2015-05-02T00:00:00"}]]}
< {"method":"notice","params":[200,[{"id":"2.1.0","random":"cb8686582c40634a0c0834d0f2c4ad19f8ca80598cc3eee2b93c124d","head_block_number":7,"head_block_id":"000000071d0bc8db55d7da75d1d880818d1930fd","time":"2015-05-01T13:06:00","current_witness":"1.7.0","next_maintenance_time":"2015-05-02T00:00:00"}]]}