mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Updates cli and api accordingly
This commit is contained in:
committed by
Sergi Delgado Segura
parent
d34b94a858
commit
b4d058fc62
@@ -1,2 +1,2 @@
|
||||
PISA_API_SERVER = 'localhost'
|
||||
PISA_API_PORT = 2222
|
||||
PISA_API_PORT = 2222
|
||||
@@ -1 +1 @@
|
||||
wrong_txid = "You should provide the 16 MSB (in base58 hex) of the txid you'd like to be monitored."
|
||||
wrong_txid = "You should provide the 16 MSB (in hex) of the txid you'd like to be monitored."
|
||||
@@ -3,25 +3,22 @@ from getopt import getopt
|
||||
from sys import argv
|
||||
from apps import PISA_API_SERVER, PISA_API_PORT
|
||||
import apps.messages as msg
|
||||
from base58 import b58decode
|
||||
import re
|
||||
|
||||
|
||||
commands = ['register_tx']
|
||||
commands = ['add_appointment']
|
||||
|
||||
|
||||
def check_txid_format(txid):
|
||||
if len(txid) != 32:
|
||||
raise Exception("txid does not matches the expected size (16-byte / 32 hex chars). " + msg.wrong_txid)
|
||||
try:
|
||||
b58decode(txid)
|
||||
except ValueError:
|
||||
raise Exception("The provided txid is not in base58. " + msg.wrong_txid)
|
||||
|
||||
return re.search(r'^[0-9A-Fa-f]+$', txid) is not None
|
||||
|
||||
|
||||
def show_usage():
|
||||
print("usage: python pisa-cli.py argument [additional_arguments]."
|
||||
"\nArguments:"
|
||||
"\nregister_tx half_txid: \tregisters a txid to be monitored by PISA using the 16 MSB of the txid (in hex)."
|
||||
"\nadd_appointment appointment: \tregisters a json formatted appointment "
|
||||
"\nhelp: \t\tshows this message.")
|
||||
|
||||
|
||||
@@ -36,17 +33,20 @@ if __name__ == '__main__':
|
||||
|
||||
if command in commands:
|
||||
|
||||
if command == 'register_tx':
|
||||
if command in commands:
|
||||
if len(args) != 2:
|
||||
raise Exception("txid missing. " + msg.wrong_txid)
|
||||
|
||||
arg = args[1]
|
||||
check_txid_format(arg)
|
||||
valid_locator = check_txid_format(arg)
|
||||
|
||||
conn = Client((PISA_API_SERVER, PISA_API_PORT))
|
||||
if valid_locator:
|
||||
conn = Client((PISA_API_SERVER, PISA_API_PORT))
|
||||
|
||||
# Argv could be undefined, but we only have one command for now so safe
|
||||
conn.send((command, arg))
|
||||
# Argv could be undefined, but we only have one command so it's safe for now
|
||||
conn.send((command, arg))
|
||||
else:
|
||||
raise ValueError("The provided locator is not valid. " + msg.wrong_txid)
|
||||
|
||||
else:
|
||||
show_usage()
|
||||
|
||||
@@ -35,7 +35,7 @@ def manage_request(conn, remote_addr, remote_port, inspector, watcher, debug, lo
|
||||
command, arg = msg
|
||||
|
||||
if command == "add_appointment":
|
||||
appointment = inspector.inspect(msg, debug)
|
||||
appointment = inspector.inspect(arg, debug)
|
||||
if appointment:
|
||||
appointment_added = watcher.add_appointment(appointment, debug, logging)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user