diff --git a/pisa-btc/apps/__init__.py b/pisa-btc/apps/__init__.py index 41def5a..bf87110 100644 --- a/pisa-btc/apps/__init__.py +++ b/pisa-btc/apps/__init__.py @@ -1,2 +1,2 @@ PISA_API_SERVER = 'localhost' -PISA_API_PORT = 2222 +PISA_API_PORT = 2222 \ No newline at end of file diff --git a/pisa-btc/apps/messages.py b/pisa-btc/apps/messages.py index 39c83d9..b57d1ed 100644 --- a/pisa-btc/apps/messages.py +++ b/pisa-btc/apps/messages.py @@ -1 +1 @@ -wrong_txid = "You should provide the 16 MSB (in base58 hex) of the txid you'd like to be monitored." \ No newline at end of file +wrong_txid = "You should provide the 16 MSB (in hex) of the txid you'd like to be monitored." \ No newline at end of file diff --git a/pisa-btc/apps/pisa-cli.py b/pisa-btc/apps/pisa-cli.py index 0782c8b..2cd0817 100644 --- a/pisa-btc/apps/pisa-cli.py +++ b/pisa-btc/apps/pisa-cli.py @@ -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() diff --git a/pisa-btc/pisa/api.py b/pisa-btc/pisa/api.py index c69e415..c5e3f05 100644 --- a/pisa-btc/pisa/api.py +++ b/pisa-btc/pisa/api.py @@ -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)