Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import websocket
- import json
- def on_message(ws, message):
- jsons = json.loads(message)
- data_result = jsons.get('result')
- if jsons.get('id') == 1:
- height = int(data_result.get('previous')[0:8], 16)
- ws.send(json.dumps({'id': 2, 'method': 'call', 'jsonrpc':'2.0', 'params': ['operation_history', 'get_ops_in_block', [height, 'false']]}))
- elif jsons.get('id') == 2:
- print(data_result)
- def on_error(ws, error):
- print(error)
- def on_close(ws):
- print("### closed ###")
- def on_open(ws):
- ws.send(json.dumps({'id': 1, 'method': 'call', 'jsonrpc':'2.0', 'params': ['database_api', 'set_block_applied_callback', [0]]}))
- if __name__ == '__main__':
- ws = websocket.WebSocketApp("wss://ws18.golos.io/",
- on_message = on_message,
- on_error = on_error,
- on_close = on_close)
- ws.on_open = on_open
- ws.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement