-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathravenrpc.py
34 lines (30 loc) · 1.08 KB
/
ravenrpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
from requests.auth import HTTPBasicAuth
import base64
import json
class Ravencoin:
def __init__(self, username, password, host='localhost', port=8766):
self.username = username
self.password = password
self.host = host
self.port = port
self.id = 0
def __getattr__(self, name):
if name.startswith('__') and name.endswith('__'):
# Python internal stuff
raise AttributeError
def ret(*args):
self.id += 1
url = f'http://{self.host}:{self.port}'
auth = HTTPBasicAuth(self.username, self.password)
data = {
'method': name,
'params': list(args),
'id': self.id,
'jsonrpc': '2.0',
}
response = requests.post(url, json.dumps(data), headers={'Content-Type': 'application/json'}, auth=auth)
if 'error' in response and response['error'] != None:
raise Exception(response['error'])
return json.loads(response.text)
return ret