|
@@ -2,71 +2,92 @@ import argparse
|
|
|
import requests
|
|
import requests
|
|
|
import json
|
|
import json
|
|
|
|
|
|
|
|
-def arg_parser(DarkClient):
|
|
|
|
|
|
|
+def arg_parser(client):
|
|
|
parser = argparse.ArgumentParser(prog='dark',
|
|
parser = argparse.ArgumentParser(prog='dark',
|
|
|
usage='%(prog)s [commands]',
|
|
usage='%(prog)s [commands]',
|
|
|
description="""DarkFi wallet
|
|
description="""DarkFi wallet
|
|
|
command-line tool""")
|
|
command-line tool""")
|
|
|
- parser.add_argument("new", help="Calls a new method")
|
|
|
|
|
parser.add_argument("-k", "--key", action='store_true', help="Generate a new keypair")
|
|
parser.add_argument("-k", "--key", action='store_true', help="Generate a new keypair")
|
|
|
parser.add_argument("-i", "--info", action='store_true', help="Request info from daemon")
|
|
parser.add_argument("-i", "--info", action='store_true', help="Request info from daemon")
|
|
|
|
|
+ parser.add_argument("-s", "--stop", action='store_true', help="Send a stop signal to the daemon")
|
|
|
|
|
+ parser.add_argument("-hi", "--hello", action='store_true', help="Say hello")
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.key:
|
|
if args.key:
|
|
|
try:
|
|
try:
|
|
|
print("Attemping to generate a new key pair...")
|
|
print("Attemping to generate a new key pair...")
|
|
|
- client.key_gen()
|
|
|
|
|
|
|
+ client.key_gen(client.payload)
|
|
|
except Exception:
|
|
except Exception:
|
|
|
- print("Something went wrong")
|
|
|
|
|
raise
|
|
raise
|
|
|
|
|
|
|
|
if args.info:
|
|
if args.info:
|
|
|
try:
|
|
try:
|
|
|
print("Info was entered")
|
|
print("Info was entered")
|
|
|
- client.get_info()
|
|
|
|
|
|
|
+ client.get_info(client.payload)
|
|
|
print("Requesting daemon info...")
|
|
print("Requesting daemon info...")
|
|
|
except Exception:
|
|
except Exception:
|
|
|
- print("Something went wrong")
|
|
|
|
|
|
|
+ raise
|
|
|
|
|
+
|
|
|
|
|
+ if args.stop:
|
|
|
|
|
+ try:
|
|
|
|
|
+ print("Stop was entered")
|
|
|
|
|
+ client.stop(client.payload)
|
|
|
|
|
+ print("Sending a stop signal...")
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ raise
|
|
|
|
|
+
|
|
|
|
|
+ if args.hello:
|
|
|
|
|
+ try:
|
|
|
|
|
+ print("Hello was entered")
|
|
|
|
|
+ client.say_hello(client.payload)
|
|
|
|
|
+ except Exception:
|
|
|
raise
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
class DarkClient:
|
|
class DarkClient:
|
|
|
- # generate random ID (4 byte unsigned int) (rand range 0 - max size
|
|
|
|
|
|
|
+ # TODO: generate random ID (4 byte unsigned int) (rand range 0 - max size
|
|
|
# uint32
|
|
# uint32
|
|
|
- def __init__(self, rpc_id = None, params = None, method = None):
|
|
|
|
|
- print("init called")
|
|
|
|
|
|
|
+ def __init__(self):
|
|
|
self.url = "http://localhost:8000/"
|
|
self.url = "http://localhost:8000/"
|
|
|
- self.rpc_id = rpc_id
|
|
|
|
|
- self.params = params
|
|
|
|
|
- self.method = method
|
|
|
|
|
- print("init done")
|
|
|
|
|
|
|
+ self.payload = {
|
|
|
|
|
+ "method": [],
|
|
|
|
|
+ "params": [],
|
|
|
|
|
+ "jsonrpc": [],
|
|
|
|
|
+ "id": [],
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- def test_method(self, rpc_id, method):
|
|
|
|
|
- print("Test variables are:\n" + "url:\n" + str(self.url) + "" + str(rpc_id) + " " + str(method))
|
|
|
|
|
|
|
+ def key_gen(self, payload):
|
|
|
|
|
+ payload['method'] = "key_gen"
|
|
|
|
|
+ payload['jsonrpc'] = "2.0"
|
|
|
|
|
+ payload['id'] = "0"
|
|
|
|
|
+ key = self.__request(payload)
|
|
|
|
|
+ print(key)
|
|
|
|
|
|
|
|
- def key_gen(self):
|
|
|
|
|
- rpc_id = 0
|
|
|
|
|
- method = "key_gen"
|
|
|
|
|
- params = None
|
|
|
|
|
- self.__request(rpc_id, params, method)
|
|
|
|
|
|
|
+ def get_info(self, payload):
|
|
|
|
|
+ payload['method'] = "get_info"
|
|
|
|
|
+ payload['jsonrpc'] = "2.0"
|
|
|
|
|
+ payload['id'] = "0"
|
|
|
|
|
+ info = self.__request(payload)
|
|
|
|
|
+ print(info)
|
|
|
|
|
|
|
|
- def get_info(self):
|
|
|
|
|
- rpc_id = 1
|
|
|
|
|
- method = "get_info",
|
|
|
|
|
- params = []
|
|
|
|
|
- self.__request(rpc_id, params, method)
|
|
|
|
|
|
|
+ def stop(self, payload):
|
|
|
|
|
+ payload['method'] = "stop"
|
|
|
|
|
+ payload['jsonrpc'] = "2.0"
|
|
|
|
|
+ payload['id'] = "0"
|
|
|
|
|
+ stop = self.__request(payload)
|
|
|
|
|
+ print(stop)
|
|
|
|
|
|
|
|
- def __request(self, rpc_id, params, method):
|
|
|
|
|
- payload = {
|
|
|
|
|
- "method": method,
|
|
|
|
|
- "params": params,
|
|
|
|
|
- "jsonrpc": "2.0",
|
|
|
|
|
- "id": rpc_id,
|
|
|
|
|
- }
|
|
|
|
|
- payload['method'] = 'get_info'
|
|
|
|
|
- payload['id'] = 0
|
|
|
|
|
|
|
+ def say_hello(self, payload):
|
|
|
|
|
+ payload['method'] = "say_hello"
|
|
|
|
|
+ payload['jsonrpc'] = "2.0"
|
|
|
|
|
+ payload['id'] = "0"
|
|
|
|
|
+ hello = self.__request(payload)
|
|
|
|
|
+ print(hello)
|
|
|
|
|
+
|
|
|
|
|
+ def __request(self, payload):
|
|
|
response = requests.post(self.url, json=payload).json()
|
|
response = requests.post(self.url, json=payload).json()
|
|
|
# print something better
|
|
# print something better
|
|
|
|
|
+ # parse into data structure
|
|
|
print(response)
|
|
print(response)
|
|
|
assert response["jsonrpc"]
|
|
assert response["jsonrpc"]
|
|
|
|
|
|