OSDN Git Service

fix bug and add tool for claim tx
[bytom/vapor.git] / tools / side_chain_tool / app / api / Connection.py
1 import requests
2 import json
3 from websocket import create_connection
4
5
6 class Connection(object):
7     def __init__(self, base_url, token=''):
8         self.baseUrl = base_url
9         self.token = token
10
11     def request(self, path, body={}):
12         url = self.baseUrl + path
13         headers = {}
14         resp = requests.post(url, data=json.dumps(body), headers=headers)
15         return resp
16
17     @staticmethod
18     def generate():
19         return Connection("http://127.0.0.1:9888")
20
21
22 class WSClient(object):
23     def __init__(self, url):
24         self.ws = create_connection(url)
25
26     def send(self, data):
27         self.ws.send(data)
28     
29     def recv(self):
30         return self.ws.recv()
31     
32     def close(self):
33         self.ws.close()