-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrpc.py
More file actions
30 lines (25 loc) · 864 Bytes
/
rpc.py
File metadata and controls
30 lines (25 loc) · 864 Bytes
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
import requests
import json
class RPC(object):
def __init__(self, username, password, server, port):
self.url = "http://%s:%s@%s:%s/" % (username, password, server, port)
self.headers = {'content-type': 'application/json'}
def get(self, command, params=None):
if params is None:
params = []
payload = {
"method": command,
"params": params,
"jsonrpc": "2.0",
"id": 0}
out = requests.post(self.url, data=json.dumps(payload), headers=self.headers).json()
try:
res = json.loads(out)
except:
res = {"output": out}
res['result'] = 'success'
return res
if __name__ == '__main__':
from settings import *
rpc = RPC(RPCUSER, RPCPASS, SERVER, RPCPORT)
print(rpc.get('getaccountaddress',['test']))