mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-19 07:04:27 +01:00
Updates cli and api accordingly
This commit is contained in:
committed by
Sergi Delgado Segura
parent
d34b94a858
commit
b4d058fc62
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user