contrib.client.teos_client

add_appointment(appointment, user_sk, teos_id, teos_url)[source]
Manages the add_appointment command. The life cycle of the function is as follows:
  • Sign the appointment

  • Send the appointment to the tower

  • Wait for the response

  • Check the tower’s response and signature

Parameters
  • appointment (Appointment) – an appointment object.

  • user_sk (PrivateKey) – the user’s private key.

  • teos_id (str) – the tower’s compressed public key.

  • teos_url (str) – the teos base url.

Returns

A tuple containing the start block and the tower’s signature of the appointment.

Return type

tuple

Raises
  • ValueError – if the appointment cannot be signed.

  • ConnectionError – if the client cannot connect to the tower.

  • TowerResponseError – if the tower responded with an error, or the response was invalid.

create_appointment(appointment_data)[source]

Creates an appointment object from an appointment data dictionary provided by the user. Performs all the required sanity checks on the input data:

  • Check that the given commitment_txid is correct (proper format and not missing)

  • Check that the transaction is correct (not missing)

Parameters

appointment_data (dict) – a dictionary containing the appointment data.

Returns

An appointment built from the appointment data provided by the user.

Return type

common.appointment.Appointment

get_appointment(locator, user_sk, teos_id, teos_url)[source]

Gets information about an appointment from the tower.

Parameters
  • locator (str) – the appointment locator used to identify it.

  • user_sk (PrivateKey) – the user’s private key.

  • teos_id (PublicKey) – the tower’s compressed public key.

  • teos_url (str) – the teos base url.

Returns

A dictionary containing the appointment data.

Return type

dict

Raises
  • InvalidParameter – if appointment_data or any of its fields is invalid.

  • ConnectionError – if the client cannot connect to the tower.

  • TowerResponseError – if the tower responded with an error, or the response was invalid.

load_keys(user_sk_path)[source]

Loads all the user private key and id.

Parameters

user_sk_path (str) – path to the user’s private key file.

Returns

A tuple containing a PrivateKey and a str representing the user sk and user id (compressed pk) respectively.

Return type

tuple

Raises

InvalidKey – if any of the keys is invalid or cannot be loaded.

load_teos_id(teos_pk_path)[source]

Loads the tower id from disk.

Parameters

teos_pk_path (str) – path to the tower’s public key file.

Returns

The tower id.

Return type

str

Raises

InvalidKey – if the public key is invalid or cannot be loaded.

main(command, args, command_line_conf)[source]
parse_add_appointment_args(args)[source]

Parses the arguments of the add_appointment command.

Parameters

args (list) – a list of command line arguments that must contain a json encoded appointment, or the file option and the path to a file containing a json encoded appointment.

Returns

A dictionary containing the appointment data.

Return type

dict

Raises
  • InvalidParameter – if the appointment data is not JSON encoded.

  • FileNotFoundError – if -f is passed and the appointment file is not found.

  • IOError – if -f was passed and the file cannot be read.

post_request(data, endpoint)[source]

Sends a post request to the tower.

Parameters
  • data (dict) – a dictionary containing the data to be posted.

  • endpoint (str) – the endpoint to send the post request.

Returns

A json-encoded dictionary with the server response if the data can be posted.

Return type

dict

Raises

ConnectionError – if the client cannot connect to the tower.

process_post_response(response)[source]

Processes the server response to a post request.

Parameters

response (Response) – a Response object obtained from the request.

Returns

A dictionary containing the tower’s response data if the response type is HTTP_OK.

Return type

dict

Raises

TowerResponseError – if the tower responded with an error, or the response was invalid.

register(user_id, teos_id, teos_url)[source]

Registers the user to the tower.

Parameters
  • user_id (str) – a 33-byte hex-encoded compressed public key representing the user.

  • teos_id (str) – the tower’s compressed public key.

  • teos_url (str) – the teos base url.

Returns

A tuple containing the available slots count and the subscription expiry.

Return type

tuple

Raises
  • InvalidParameter – if user_id is invalid.

  • ConnectionError – if the client cannot connect to the tower.

  • TowerResponseError – if the tower responded with an error, or the response was invalid.

save_appointment_receipt(appointment, start_block, signature, appointments_folder_path)[source]

Saves an appointment receipt to disk. A receipt consists of an appointment and a signature from the tower.

Parameters
  • appointment (Appointment) – the appointment to be saved on disk.

  • start_block (int) – the block height at which the tower started to watch for the appointment.

  • signature (str) – the signature of the appointment performed by the tower.

  • appointments_folder_path (str) – the path to the appointments folder.

Raises

IOError – if an error occurs whilst writing the file on disk.