Skip to content

Commit 32af95e

Browse files
committed
Improve README
1 parent c963c9f commit 32af95e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,46 @@ custom_json = {"x": 35, "y": 70, "color": "#e50000"}
4949
viz.custom(protocol, custom_json, None, required_regular_auths)
5050
```
5151

52-
### Get account with custom protocol and latest block
52+
### Get data from custom protocol
5353

5454
```python
5555
from viz import Client
5656
from viz.account import Account
5757
from viz.block import Block
5858
from viz.instance import set_shared_blockchain_instance
59+
import json
5960

6061
viz = Client("wss://node.viz.cx/ws")
6162
set_shared_blockchain_instance(viz)
6263

64+
account_name = "id"
6365
protocol = "V"
64-
account = Account("id", viz, protocol)
66+
account = Account(account_name, protocol=protocol)
67+
6568
counter_inside_protocol = account["custom_sequence"]
6669
last_used_in_block = account["custom_sequence_block_num"]
70+
6771
block = Block(last_used_in_block)
72+
73+
for tx in block["transactions"]:
74+
for op_type, op_data in tx["operations"]:
75+
if op_type != "custom":
76+
continue
77+
if op_data.get("id") != protocol:
78+
continue
79+
if account_name not in op_data.get("required_regular_auths", []):
80+
continue
81+
82+
raw_json = op_data.get("json")
83+
try:
84+
json_from_protocol = json.loads(raw_json) if raw_json else None
85+
except json.JSONDecodeError:
86+
json_from_protocol = None
87+
88+
print(json_from_protocol)
6889
```
6990

70-
Any direct RPC call:
91+
### Any direct RPC call
7192

7293
```python
7394
from viz import Client

0 commit comments

Comments
 (0)