From 5e5ff0278ad6e73156d389e8580c92318f258d62 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 12:09:58 +0100 Subject: [PATCH 01/12] Removes apps folder --- .gitignore | 2 +- {apps/cli => cli}/DEPENDENCIES.md | 0 {apps/cli => cli}/INSTALL.md | 0 {apps/cli => cli}/README.md | 0 {apps/cli => cli}/TEOS-API.md | 0 {apps/cli => cli}/__init__.py | 2 +- {apps/cli => cli}/help.py | 0 {apps/cli => cli}/requirements-dev.txt | 0 {apps/cli => cli}/requirements.txt | 0 {apps/cli => cli}/sample_conf.py | 0 {apps/cli => cli}/teos_cli.py | 4 ++-- apps/generate_key.py => generate_keys.py | 14 +++++++++++--- test/apps/cli/__init__.py | 0 test/apps/cli/unit/__init__.py | 0 {apps => test/cli}/__init__.py | 0 test/{apps => cli/unit}/__init__.py | 0 test/{apps => }/cli/unit/conftest.py | 0 test/{apps => }/cli/unit/test_teos_cli.py | 4 ++-- test/teos/e2e/test_basic_e2e.py | 4 ++-- 19 files changed, 19 insertions(+), 11 deletions(-) rename {apps/cli => cli}/DEPENDENCIES.md (100%) rename {apps/cli => cli}/INSTALL.md (100%) rename {apps/cli => cli}/README.md (100%) rename {apps/cli => cli}/TEOS-API.md (100%) rename {apps/cli => cli}/__init__.py (97%) rename {apps/cli => cli}/help.py (100%) rename {apps/cli => cli}/requirements-dev.txt (100%) rename {apps/cli => cli}/requirements.txt (100%) rename {apps/cli => cli}/sample_conf.py (100%) rename {apps/cli => cli}/teos_cli.py (99%) rename apps/generate_key.py => generate_keys.py (79%) delete mode 100644 test/apps/cli/__init__.py delete mode 100644 test/apps/cli/unit/__init__.py rename {apps => test/cli}/__init__.py (100%) rename test/{apps => cli/unit}/__init__.py (100%) rename test/{apps => }/cli/unit/conftest.py (100%) rename test/{apps => }/cli/unit/test_teos_cli.py (98%) diff --git a/.gitignore b/.gitignore index 9dac4f1..fb8a68f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ conf.py bitcoin.conf* *__pycache__ .pending* -apps/cli/*.json +cli/*.json appointments/ test.py *.pyc diff --git a/apps/cli/DEPENDENCIES.md b/cli/DEPENDENCIES.md similarity index 100% rename from apps/cli/DEPENDENCIES.md rename to cli/DEPENDENCIES.md diff --git a/apps/cli/INSTALL.md b/cli/INSTALL.md similarity index 100% rename from apps/cli/INSTALL.md rename to cli/INSTALL.md diff --git a/apps/cli/README.md b/cli/README.md similarity index 100% rename from apps/cli/README.md rename to cli/README.md diff --git a/apps/cli/TEOS-API.md b/cli/TEOS-API.md similarity index 100% rename from apps/cli/TEOS-API.md rename to cli/TEOS-API.md diff --git a/apps/cli/__init__.py b/cli/__init__.py similarity index 97% rename from apps/cli/__init__.py rename to cli/__init__.py index 76d2246..925027f 100644 --- a/apps/cli/__init__.py +++ b/cli/__init__.py @@ -1,5 +1,5 @@ import os -import apps.cli.conf as conf +import cli.conf as conf from common.tools import extend_paths, check_conf_fields, setup_logging, setup_data_folder LOG_PREFIX = "cli" diff --git a/apps/cli/help.py b/cli/help.py similarity index 100% rename from apps/cli/help.py rename to cli/help.py diff --git a/apps/cli/requirements-dev.txt b/cli/requirements-dev.txt similarity index 100% rename from apps/cli/requirements-dev.txt rename to cli/requirements-dev.txt diff --git a/apps/cli/requirements.txt b/cli/requirements.txt similarity index 100% rename from apps/cli/requirements.txt rename to cli/requirements.txt diff --git a/apps/cli/sample_conf.py b/cli/sample_conf.py similarity index 100% rename from apps/cli/sample_conf.py rename to cli/sample_conf.py diff --git a/apps/cli/teos_cli.py b/cli/teos_cli.py similarity index 99% rename from apps/cli/teos_cli.py rename to cli/teos_cli.py index d1d15f0..bbfbd68 100644 --- a/apps/cli/teos_cli.py +++ b/cli/teos_cli.py @@ -10,8 +10,8 @@ from coincurve import PublicKey from getopt import getopt, GetoptError from requests import ConnectTimeout, ConnectionError -from apps.cli import config, LOG_PREFIX -from apps.cli.help import help_add_appointment, help_get_appointment +from cli import config, LOG_PREFIX +from cli.help import help_add_appointment, help_get_appointment from common.blob import Blob import common.cryptographer diff --git a/apps/generate_key.py b/generate_keys.py similarity index 79% rename from apps/generate_key.py rename to generate_keys.py index 5a6b449..762f142 100644 --- a/apps/generate_key.py +++ b/generate_keys.py @@ -7,8 +7,16 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import ec -# Simple tool to generate an ECDSA private key using the secp256k1 curve and save private and public keys -# as 'teos_sk.der' 'and teos_pk.der', respectively. +""" +Simple too to generate an ECDSA key pair using the secp256k1 curve and store it on disk. + +Default output dir = . +Default key naming = teos_sk.der and teos_pk.der + +The output dir and naming can be changed using the -n and -d command line options, respectively. + +DISCLAIMER: Use this for testing only, using keys generated from this file in production is highly unadvised. +""" def save_sk(sk, filename): @@ -30,7 +38,7 @@ def save_pk(pk, filename): if __name__ == "__main__": name = "teos" - output_dir = "." + output_dir = "apps" opts, _ = getopt(argv[1:], "n:d:", ["name", "dir"]) for opt, arg in opts: diff --git a/test/apps/cli/__init__.py b/test/apps/cli/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/apps/cli/unit/__init__.py b/test/apps/cli/unit/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/__init__.py b/test/cli/__init__.py similarity index 100% rename from apps/__init__.py rename to test/cli/__init__.py diff --git a/test/apps/__init__.py b/test/cli/unit/__init__.py similarity index 100% rename from test/apps/__init__.py rename to test/cli/unit/__init__.py diff --git a/test/apps/cli/unit/conftest.py b/test/cli/unit/conftest.py similarity index 100% rename from test/apps/cli/unit/conftest.py rename to test/cli/unit/conftest.py diff --git a/test/apps/cli/unit/test_teos_cli.py b/test/cli/unit/test_teos_cli.py similarity index 98% rename from test/apps/cli/unit/test_teos_cli.py rename to test/cli/unit/test_teos_cli.py index 00c9c9d..850a99f 100644 --- a/test/apps/cli/unit/test_teos_cli.py +++ b/test/cli/unit/test_teos_cli.py @@ -11,8 +11,8 @@ from common.appointment import Appointment from common.cryptographer import Cryptographer from common.blob import Blob -import apps.cli.teos_cli as teos_cli -from test.apps.cli.unit.conftest import get_random_value_hex +import cli.teos_cli as teos_cli +from test.cli.unit.conftest import get_random_value_hex common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=teos_cli.LOG_PREFIX) diff --git a/test/teos/e2e/test_basic_e2e.py b/test/teos/e2e/test_basic_e2e.py index ed6fab4..c87090a 100644 --- a/test/teos/e2e/test_basic_e2e.py +++ b/test/teos/e2e/test_basic_e2e.py @@ -5,7 +5,7 @@ from riemann.tx import Tx from teos import HOST, PORT -from apps.cli import teos_cli +from cli import teos_cli from common.blob import Blob import common.cryptographer @@ -21,7 +21,7 @@ from test.teos.e2e.conftest import ( create_penalty_tx, run_teosd, ) -from apps.cli import config as cli_conf +from cli import config as cli_conf common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="") From 90ec15923e15b0a0385672e9a204fcc127623c61 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 12:12:34 +0100 Subject: [PATCH 02/12] Move requeriments to root and creates readmes --- CONTRIBUTING.md | 4 + DEPENDENCIES.md | 86 +++++++++++++++++++ INSTALL.md | 35 ++++++++ README.md | 34 ++++++++ cli/requirements-dev.txt | 3 - ...quirements-dev.txt => requirements-dev.txt | 1 + teos/requirements.txt => requirements.txt | 0 7 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 DEPENDENCIES.md create mode 100644 INSTALL.md create mode 100644 README.md delete mode 100644 cli/requirements-dev.txt rename teos/requirements-dev.txt => requirements-dev.txt (77%) rename teos/requirements.txt => requirements.txt (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a25fd79..d27518c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,6 +46,10 @@ if rcode == 0: rcode, message = self.check_end_time(end_time, start_time, block_height) ``` +## Dev requirements +In order to contrubite you will need to install additional dependencies. They can be found at `requirements-dev.txt`. Install them by running: + + pip install -r requirements-dev.txt ## Code Documentation Code should be, at least, documented using docstrings. We use the [Sphinx Google Style](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html#example-google) for documenting functions. diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md new file mode 100644 index 0000000..bb849db --- /dev/null +++ b/DEPENDENCIES.md @@ -0,0 +1,86 @@ +# Dependencies + +`teos` has both system-wide and Python dependencies. This document walks you through how to satisfy them. + +## System-wide dependencies + +`teos` has the following system-wide dependencies: + +- `python3` +- `pip3` + +### Checking if the dependencies are already satisfied + +Most UNIX systems ship with `python3` already installed, whereas OSX systems tend to ship with `python2`. In order to check our python version we should run: + + python --version + +For what we will get something like: + + Python 2.X.X + +Or + + Python 3.X.X + +It is also likely that, if `python3` is installed in our system, the `python` alias is not set to it but instead to `python2`. In order to check so, we can run: + + python3 --version + +If `python3` is installed but the `python` alias is not set to it, we should either set it, or use `python3` to run `teos`. + +Regarding `pip`, we can check what version is installed in our system (if any) by running: + + pip --version + +For what we will get something like: + + pip X.X.X from /usr/local/lib/python2.X/dist-packages/pip (python 2.X) + +Or + + pip X.X.X from /usr/local/lib/python3.X/dist-packages/pip (python 3.X) + +A similar thing to the `python` alias applies to the `pip` alias. We can check if pip3 is install by running: + + pip3 --version + +And, if it happens to be installed, change the alias to `pip3`, or use `pip3` instead of `pip`. + + +### Installing the dependencies + +`python3` ca be downloaded from the [Python official website](https://www.python.org/downloads/) or installed using a package manager, depending on your distribution. Examples for both UNIX-like and OSX systems are provided. + +#### Ubuntu + +`python3` can be installed using `apt` as follows: + + sudo apt-get update + sudo apt-get install python3 + +and for `pip3`: + + sudo apt-get install python3-pip + pip install --upgrade pip==9.0.3 + +#### OSX + +`python3` can be installed using `Homebrew` as follows: + + brew install python3 + +`pip3` will be installed alongside `python3` in this case. + +## Python dependencies + +`teos` has the following dependencies (which can be satisfied by using `pip install -r requirements.txt`): + +- `zmq` +- `flask` +- `cryptography` +- `coincurve` +- `pyzbase32` +- `requests` +- `plyvel` + diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..a0593a8 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,35 @@ +# Install + +`teos` has some dependencies that can be satisfied by following [DEPENDENCIES.md](DEPENDENCIES.md). If your system already satisfies the dependencies, you can skip that part. + +There are two ways of running `teos`: adding the library to the `PYTHONPATH` env variable, or running it as a module. + +## Modifying `PYTHONPATH` +In order to run `teos`, you should set your `PYTHONPATH` env variable to include the **outer** teos folder. You can do so by running: + + export PYTHONPATH=$PYTHONPATH: + +For example, for user alice running a UNIX system and having `teos` in her home folder, she would run: + + export PYTHONPATH=$PYTHONPATH:/home/alice/teos/ + +You should also include the command in your `.bashrc` to avoid having to run it every time you open a new terminal. You can do it by running: + + echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc + +Once the `PYTHONPATH` is set, you should be able to run `teos` straightaway. Try it by running: + + cd /teos/ + python teosd.py + +## Running `teos` as a module +Python code can be also run as a module, to do so you need to use `python -m`. From the **outer** teos directory run: + + python -m teos.teosd + +Notice that if you run `teos` as a module, you'll need to replace all the calls from `python teosd.py` to `python -m teos.teosd` + +## Modify configuration parameters +If you'd like to modify some of the configuration defaults (such as the user directory, where the logs will be stored) you can do so in the config file located at: + + /teos/conf.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..22ff8b2 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# The Eye of Satoshi (TEOS) + +The Eye of Satoshi is a Lightning watchtower compliant with [BOLT13](https://github.com/sr-gi/bolt13), written in Python 3. + +TEOS consists in three main modules: + +- `teos`: including the tower's main functionality (server-side) +- `cli`: including a reference command line interface (client-side) +- `common`: including shared functionality between `teos` and `cli`. + +Additionally, tests for every module can be found at `tests`. + + +### Running TEOS +In order to run `teos` you will need to create a configuration file (follow [INSTALL.md](INSTALL.md)) and run `teosd.py`. Currently you will also need a set of keys (to sign appointments) stored in your data directory. + +You can use `generate_keys.py` to generate those keys. + +### Interacting with a TEOS instance +You can interact with a `teos` instance (either run by yourself or someone else) by using `teos_cli` under `cli`. + +Since `teos_cli` works independently of `teos`, you will need a separate configuration file for this (follow [cli/INSTALL.md](cli/INSTALL.md)) and a different set of keys. You can use `generate_keys.py` to generate those keys. + +Notice that `teos_cli` is a simple way to interact with `teos`, but ideally that should be part of your wallet functionality (therefore why they are independent entities). `teos_cli` can be used as an example for how to send data to a [BOLT13](https://github.com/sr-gi/bolt13) compliant watchtower. + +## Dependencies +Refer to [DEPENDENCIES.md](DEPENDENCIES.md) + +## Installation + +Refer to [INSTALL.md](INSTALL.md) + +## Contributing +Refer to [CONTRIBUTING.md](CONTRIBUTING.md) \ No newline at end of file diff --git a/cli/requirements-dev.txt b/cli/requirements-dev.txt deleted file mode 100644 index f8c47f0..0000000 --- a/cli/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -responses -pytest -black \ No newline at end of file diff --git a/teos/requirements-dev.txt b/requirements-dev.txt similarity index 77% rename from teos/requirements-dev.txt rename to requirements-dev.txt index 10481e4..8a51da8 100644 --- a/teos/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ pytest black +responses bitcoind_mock===0.0.4 diff --git a/teos/requirements.txt b/requirements.txt similarity index 100% rename from teos/requirements.txt rename to requirements.txt From 6d6fa9f7281a8cf4f1b06e090eb66fb0f4103ca0 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 12:17:31 +0100 Subject: [PATCH 03/12] Update missing readmes and circleci - Some apps intances were not removed - requeriment paths were wrong in circleci and some apps path needed to be removed --- .circleci/config.yml | 18 +++++++++--------- DEPENDENCIES.md | 6 ++++++ README.md | 9 +++++++-- cli/INSTALL.md | 18 +++++++++--------- generate_keys.py | 4 ++-- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 32cf538..453ff63 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,7 +21,7 @@ jobs: # Download and cache dependencies - restore_cache: keys: - - v1-dependencies-{{ checksum "teos/requirements.txt" }}-{{ checksum "teos/requirements-dev.txt" }}-{{ checksum "apps/cli/requirements-dev.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} + - v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "cli/requirements.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} - run: name: Install dependencies @@ -31,15 +31,15 @@ jobs: python3 -m venv venv . venv/bin/activate sudo pip install --upgrade pip - pip install -r teos/requirements.txt - pip install -r teos/requirements-dev.txt - pip install -r apps/cli/requirements-dev.txt + pip install -r requirements.txt + pip install -r requirements-dev.txt + pip install -r cli/requirements.txt - save_cache: paths: - ./venv - /snap - key: v1-dependencies-{{ checksum "teos/requirements.txt" }}-{{ checksum "teos/requirements-dev.txt" }}-{{ checksum "apps/cli/requirements-dev.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} + key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "cli/requirements.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} # Run bitcoind for E2E testing (running it early so it has time to bootstrap) - run: @@ -54,7 +54,7 @@ jobs: name: Creates config files command: | cp teos/sample_conf.py teos/conf.py - cp apps/cli/sample_conf.py apps/cli/conf.py + cp cli/sample_conf.py cli/conf.py - run: name: Run teos unit tests @@ -72,7 +72,7 @@ jobs: name: Run cli unit tests command: | . venv/bin/activate - pytest test/apps/cli/unit + pytest test/cli/unit # Setup teos for E2E testing - run: @@ -80,8 +80,8 @@ jobs: command: | . venv/bin/activate cp test/teos/e2e/teos-conf.py teos/conf.py - python3 -m apps.generate_key -d ~/.teos/ - python3 -m apps.generate_key -n cli -d ~/.teos_cli/ + python3 -m generate_keys -d ~/.teos/ + python3 -m generate_keys -n cli -d ~/.teos_cli/ cp ~/.teos/teos_pk.der ~/.teos_cli/ diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index bb849db..f8e0443 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -8,6 +8,7 @@ - `python3` - `pip3` +- `bitcoind` ### Checking if the dependencies are already satisfied @@ -47,6 +48,11 @@ A similar thing to the `python` alias applies to the `pip` alias. We can check i And, if it happens to be installed, change the alias to `pip3`, or use `pip3` instead of `pip`. +### Installing bitcoind + +`teos` runs on top of a Bitcoin Core node. Other underlaying Bitcoin nodes are not supported at the moment. + +You can get Bitcoin Core from [bitcoin.org](https://bitcoin.org/en/download). ### Installing the dependencies diff --git a/README.md b/README.md index 22ff8b2..f0de7c9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +## State of the code + +Currently working on updating the software to match [BOLT13 rev1](https://github.com/sr-gi/bolt13). + # The Eye of Satoshi (TEOS) The Eye of Satoshi is a Lightning watchtower compliant with [BOLT13](https://github.com/sr-gi/bolt13), written in Python 3. @@ -10,7 +14,6 @@ TEOS consists in three main modules: Additionally, tests for every module can be found at `tests`. - ### Running TEOS In order to run `teos` you will need to create a configuration file (follow [INSTALL.md](INSTALL.md)) and run `teosd.py`. Currently you will also need a set of keys (to sign appointments) stored in your data directory. @@ -19,7 +22,9 @@ You can use `generate_keys.py` to generate those keys. ### Interacting with a TEOS instance You can interact with a `teos` instance (either run by yourself or someone else) by using `teos_cli` under `cli`. -Since `teos_cli` works independently of `teos`, you will need a separate configuration file for this (follow [cli/INSTALL.md](cli/INSTALL.md)) and a different set of keys. You can use `generate_keys.py` to generate those keys. +Since `teos_cli` works independently of `teos`, you will need a separate configuration file for this (follow [cli/INSTALL.md](cli/INSTALL.md)). + +`teos_cli` will also need an independent set of keys (that can be generated using `generate_keys.py`) as well as the public key of the tower instance (`teos_pk.der`). The same data directory can be used for both if you are running things locally. Notice that `teos_cli` is a simple way to interact with `teos`, but ideally that should be part of your wallet functionality (therefore why they are independent entities). `teos_cli` can be used as an example for how to send data to a [BOLT13](https://github.com/sr-gi/bolt13) compliant watchtower. diff --git a/cli/INSTALL.md b/cli/INSTALL.md index a5a32d5..2c9d4bf 100644 --- a/cli/INSTALL.md +++ b/cli/INSTALL.md @@ -5,31 +5,31 @@ There are two ways of running `teos_cli`: adding the library to the `PYTHONPATH` env variable, or running it as a module. ## Modifying `PYTHONPATH` -In order to run `teos_cli`, you should set your `PYTHONPATH` env variable to include the folder that contains the `apps` folder. You can do so by running: +In order to run `teos_cli`, you should set your `PYTHONPATH` env variable to include the folder that contains the `cli` folder. You can do so by running: - export PYTHONPATH=$PYTHONPATH: + export PYTHONPATH=$PYTHONPATH: -For example, for user alice running a UNIX system and having `apps` in her home folder, she would run: +For example, for user alice running a UNIX system and having `cli` in her home folder, she would run: export PYTHONPATH=$PYTHONPATH:/home/alice/ You should also include the command in your `.bashrc` to avoid having to run it every time you open a new terminal. You can do it by running: - echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc + echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc Once the `PYTHONPATH` is set, you should be able to run `teos_cli` straightaway. Try it by running: - cd /apps/cli + cd /cli python teos_cli.py -h ## Running `teos_cli` as a module -Python code can be also run as a module, to do so you need to use `python -m`. From `apps` **parent** directory run: +Python code can be also run as a module, to do so you need to use `python -m`. From `cli` **parent** directory run: - python -m apps.cli.teos_cli -h + python -m cli.teos_cli -h -Notice that if you run `teos_cli` as a module, you'll need to replace all the calls from `python teos_cli.py ` to `python -m apps.cli.teos_cli ` +Notice that if you run `teos_cli` as a module, you'll need to replace all the calls from `python teos_cli.py ` to `python -m cli.teos_cli ` ## Modify configuration parameters If you'd like to modify some of the configuration defaults (such as the user directory, where the logs and appointment receipts will be stored) you can do so in the config file located at: - /apps/cli/conf.py + /cli/conf.py diff --git a/generate_keys.py b/generate_keys.py index 762f142..add59c7 100644 --- a/generate_keys.py +++ b/generate_keys.py @@ -8,7 +8,7 @@ from cryptography.hazmat.primitives.asymmetric import ec """ -Simple too to generate an ECDSA key pair using the secp256k1 curve and store it on disk. +Simple way too to generate an ECDSA key pair using the secp256k1 curve and store it on disk. Default output dir = . Default key naming = teos_sk.der and teos_pk.der @@ -38,7 +38,7 @@ def save_pk(pk, filename): if __name__ == "__main__": name = "teos" - output_dir = "apps" + output_dir = "." opts, _ = getopt(argv[1:], "n:d:", ["name", "dir"]) for opt, arg in opts: From 8f3834ad903ef37d86e8c93dcc0b48d3f6712f19 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 15:35:55 +0100 Subject: [PATCH 04/12] Caps --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d27518c..b2abd3a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to The Eye of Satoshi +# Contributing to the Eye of Satoshi The following is a set of guidelines for contributing to TEOS. From b200968da99ca81ecc8d5008fbcef067f8471aed Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 15:55:48 +0100 Subject: [PATCH 05/12] Removes snap catching until a way of doing it is found. Currently it fails on restoring the cache due to trying to resto /snap --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 453ff63..b883c23 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,7 +21,7 @@ jobs: # Download and cache dependencies - restore_cache: keys: - - v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "cli/requirements.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} + - v2-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "cli/requirements.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} - run: name: Install dependencies @@ -38,8 +38,8 @@ jobs: - save_cache: paths: - ./venv - - /snap - key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "cli/requirements.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} + #- /snap + key: v2-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "cli/requirements.txt" }}-{{ checksum "test/teos/e2e/bitcoind_snap.sh" }} # Run bitcoind for E2E testing (running it early so it has time to bootstrap) - run: From 685c81fa40e3a3b0aa7727c9f045fe0bf36a2be7 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 17:08:40 +0100 Subject: [PATCH 06/12] Updates repo name to not match server-side name. Updates INSTALL --- INSTALL.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index a0593a8..e615ac3 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -5,25 +5,25 @@ There are two ways of running `teos`: adding the library to the `PYTHONPATH` env variable, or running it as a module. ## Modifying `PYTHONPATH` -In order to run `teos`, you should set your `PYTHONPATH` env variable to include the **outer** teos folder. You can do so by running: +In order to run `teos`, you should set your `PYTHONPATH` env variable to include the teos parent folder. You can do so by running: - export PYTHONPATH=$PYTHONPATH: + export PYTHONPATH=$PYTHONPATH: For example, for user alice running a UNIX system and having `teos` in her home folder, she would run: - export PYTHONPATH=$PYTHONPATH:/home/alice/teos/ + export PYTHONPATH=$PYTHONPATH:/home/alice/ You should also include the command in your `.bashrc` to avoid having to run it every time you open a new terminal. You can do it by running: - echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc + echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc Once the `PYTHONPATH` is set, you should be able to run `teos` straightaway. Try it by running: - cd /teos/ + cd /teos/ python teosd.py ## Running `teos` as a module -Python code can be also run as a module, to do so you need to use `python -m`. From the **outer** teos directory run: +Python code can be also run as a module, to do so you need to use `python -m`. From the teos parent directory run: python -m teos.teosd @@ -32,4 +32,4 @@ Notice that if you run `teos` as a module, you'll need to replace all the calls ## Modify configuration parameters If you'd like to modify some of the configuration defaults (such as the user directory, where the logs will be stored) you can do so in the config file located at: - /teos/conf.py + /teos/conf.py From 5ff33ad5cf25ce6b909cffa3fd778f18e417c460 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 18:10:09 +0100 Subject: [PATCH 07/12] Gets rid of sample_confs and add defaults confs --- .circleci/config.yml | 6 ------ .gitignore | 1 - cli/{sample_conf.py => conf.py} | 4 ++-- teos/{sample_conf.py => conf.py} | 0 4 files changed, 2 insertions(+), 9 deletions(-) rename cli/{sample_conf.py => conf.py} (74%) rename teos/{sample_conf.py => conf.py} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index b883c23..863cebb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,12 +50,6 @@ jobs: /snap/bin/bitcoin-core.daemon # Run unit tests - - run: - name: Creates config files - command: | - cp teos/sample_conf.py teos/conf.py - cp cli/sample_conf.py cli/conf.py - - run: name: Run teos unit tests command: | diff --git a/.gitignore b/.gitignore index fb8a68f..64b00b0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ .venv/ *.log .DS_Store -conf.py bitcoin.conf* *__pycache__ .pending* diff --git a/cli/sample_conf.py b/cli/conf.py similarity index 74% rename from cli/sample_conf.py rename to cli/conf.py index 155e788..1072da7 100644 --- a/cli/sample_conf.py +++ b/cli/conf.py @@ -1,6 +1,6 @@ # TEOS-SERVER -DEFAULT_TEOS_API_SERVER = "https://teos.pisa.watch" -DEFAULT_TEOS_API_PORT = 443 +DEFAULT_TEOS_API_SERVER = "http://localhost" +DEFAULT_TEOS_API_PORT = 9814 # WT-CLI DATA_FOLDER = "~/.teos_cli/" diff --git a/teos/sample_conf.py b/teos/conf.py similarity index 100% rename from teos/sample_conf.py rename to teos/conf.py From f5c7f2308310af5c6b004de86626b5dbb454e428 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 18:10:51 +0100 Subject: [PATCH 08/12] Makes sure cryptography dependency is at least 2.8 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f168a98..5ea83ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ zmq flask -cryptography +cryptography==2.8 coincurve pyzbase32 requests From 6f8af947ae8e9f055ff6be4d501dc390f80a5e24 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 18:13:33 +0100 Subject: [PATCH 09/12] Adds unhandled exception when not bneing able to connect to bitcoind --- teos/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teos/tools.py b/teos/tools.py index d10d63c..53b85cc 100644 --- a/teos/tools.py +++ b/teos/tools.py @@ -37,7 +37,7 @@ def can_connect_to_bitcoind(): try: bitcoin_cli().help() - except (timeout, ConnectionRefusedError, JSONRPCException, HTTPException): + except (timeout, ConnectionRefusedError, JSONRPCException, HTTPException, OSError): can_connect = False return can_connect From 6e06c87cf522ca2e41f7a9f11a6dbefaa7ae594c Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 18:26:37 +0100 Subject: [PATCH 10/12] Adds some notes on running bitcoind and how to change networks --- DEPENDENCIES.md | 30 ++++++++++++++++++++++++++++++ README.md | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index f8e0443..de59c84 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -54,6 +54,36 @@ And, if it happens to be installed, change the alias to `pip3`, or use `pip3` in You can get Bitcoin Core from [bitcoin.org](https://bitcoin.org/en/download). +Bitcoin needs to be running with the following options enables: + +- `zmq` for rawblockhash notifications +- `txindex` to be able to look for non-wallet transactions +- `server` to run rpc commands + +Here's an example of a `bitcoin.conf` you can use: + +``` +# [debug] +regtest=1 +daemon=1 +debug=1 +logips=1 + +# [rpc] +server=1 +rpcuser=user +rpcpassword=passwd + +# [blockchain] +txindex=1 + +# [ZMQ] +zmqpubhashblock=tcp://127.0.0.1:28332 +zmqpubrawblock=tcp://127.0.0.1:28332 +zmqpubhashtx=tcp://127.0.0.1:28333 +zmqpubrawtx=tcp://127.0.0.1:28333 +``` + ### Installing the dependencies `python3` ca be downloaded from the [Python official website](https://www.python.org/downloads/) or installed using a package manager, depending on your distribution. Examples for both UNIX-like and OSX systems are provided. diff --git a/README.md b/README.md index f0de7c9..4aaf3a0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ TEOS consists in three main modules: Additionally, tests for every module can be found at `tests`. +By default, `teos` will run on `regtest`. In order to run it on another network you need to change your `bitcoin.conf` (to run in the proper network) and your `conf.py` to match the network name and rpc port: + +``` +BTC_RPC_PORT = 18443 +BTC_NETWORK = "regtest" +``` + + ### Running TEOS In order to run `teos` you will need to create a configuration file (follow [INSTALL.md](INSTALL.md)) and run `teosd.py`. Currently you will also need a set of keys (to sign appointments) stored in your data directory. From 9d08c104168e44ecce11745d40c2d04ad99528c6 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 18:41:19 +0100 Subject: [PATCH 11/12] Updates README to improve the conf file wording --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4aaf3a0..051cffa 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,19 @@ BTC_RPC_PORT = 18443 BTC_NETWORK = "regtest" ``` - ### Running TEOS -In order to run `teos` you will need to create a configuration file (follow [INSTALL.md](INSTALL.md)) and run `teosd.py`. Currently you will also need a set of keys (to sign appointments) stored in your data directory. +You can run `teos` buy running `teosd.py` under `teos`. -You can use `generate_keys.py` to generate those keys. +To run `teos` you need a set of keys (to sign appointments) stored in your data directory. You can use `generate_keys.py` to generate those keys. + +`teos` comes with a default configuration file (check [conf.py](teos/conf.py)). The configuration file include, amost others, where your data folder is placed, what network it connects to, etc. ### Interacting with a TEOS instance You can interact with a `teos` instance (either run by yourself or someone else) by using `teos_cli` under `cli`. -Since `teos_cli` works independently of `teos`, you will need a separate configuration file for this (follow [cli/INSTALL.md](cli/INSTALL.md)). +Since `teos_cli` works independently of `teos`, it uses a different configuration file (check [cli/conf.py](cli/conf.py)). -`teos_cli` will also need an independent set of keys (that can be generated using `generate_keys.py`) as well as the public key of the tower instance (`teos_pk.der`). The same data directory can be used for both if you are running things locally. +`teos_cli` also needs an independent set of keys (that can be generated using `generate_keys.py`) as well as the public key of the tower instance (`teos_pk.der`). The same data directory can be used for both if you are running things locally. Notice that `teos_cli` is a simple way to interact with `teos`, but ideally that should be part of your wallet functionality (therefore why they are independent entities). `teos_cli` can be used as an example for how to send data to a [BOLT13](https://github.com/sr-gi/bolt13) compliant watchtower. From 89708e86b3957ae26752c772d5586a2d0128ec02 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 18 Mar 2020 20:13:50 +0100 Subject: [PATCH 12/12] Improves docs --- CONTRIBUTING.md | 2 +- DEPENDENCIES.md | 6 +++--- INSTALL.md | 39 +++++++++++++++++---------------------- README.md | 36 +++++++++++++++++++++++++++++------- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b2abd3a..2a13c1b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,7 +46,7 @@ if rcode == 0: rcode, message = self.check_end_time(end_time, start_time, block_height) ``` -## Dev requirements +## Dev Requirements In order to contrubite you will need to install additional dependencies. They can be found at `requirements-dev.txt`. Install them by running: pip install -r requirements-dev.txt diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index de59c84..4f9e611 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -2,7 +2,7 @@ `teos` has both system-wide and Python dependencies. This document walks you through how to satisfy them. -## System-wide dependencies +## System-wide Dependencies `teos` has the following system-wide dependencies: @@ -84,7 +84,7 @@ zmqpubhashtx=tcp://127.0.0.1:28333 zmqpubrawtx=tcp://127.0.0.1:28333 ``` -### Installing the dependencies +### Installing the Dependencies `python3` ca be downloaded from the [Python official website](https://www.python.org/downloads/) or installed using a package manager, depending on your distribution. Examples for both UNIX-like and OSX systems are provided. @@ -108,7 +108,7 @@ and for `pip3`: `pip3` will be installed alongside `python3` in this case. -## Python dependencies +## Python Dependencies `teos` has the following dependencies (which can be satisfied by using `pip install -r requirements.txt`): diff --git a/INSTALL.md b/INSTALL.md index e615ac3..26cdad5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,34 +2,29 @@ `teos` has some dependencies that can be satisfied by following [DEPENDENCIES.md](DEPENDENCIES.md). If your system already satisfies the dependencies, you can skip that part. -There are two ways of running `teos`: adding the library to the `PYTHONPATH` env variable, or running it as a module. +There are two ways of running `teos`: running it as a module or adding the library to the `PYTHONPATH` env variable. -## Modifying `PYTHONPATH` -In order to run `teos`, you should set your `PYTHONPATH` env variable to include the teos parent folder. You can do so by running: - - export PYTHONPATH=$PYTHONPATH: - -For example, for user alice running a UNIX system and having `teos` in her home folder, she would run: - - export PYTHONPATH=$PYTHONPATH:/home/alice/ - -You should also include the command in your `.bashrc` to avoid having to run it every time you open a new terminal. You can do it by running: - - echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc - -Once the `PYTHONPATH` is set, you should be able to run `teos` straightaway. Try it by running: - - cd /teos/ - python teosd.py - -## Running `teos` as a module -Python code can be also run as a module, to do so you need to use `python -m`. From the teos parent directory run: +## Running `teos` as a Module +The easiest way to run `teos` is as a module. To do so you need to use `python -m`. From the teos parent directory run: python -m teos.teosd Notice that if you run `teos` as a module, you'll need to replace all the calls from `python teosd.py` to `python -m teos.teosd` -## Modify configuration parameters +## Modifying `PYTHONPATH` +Alternatively, you can add `teos` to your `PYTHONPATH`. You can do so by running: + + export PYTHONPATH=$PYTHONPATH: + +For example, for user alice running a UNIX system and having `python-teos` in her home folder, she would run: + + export PYTHONPATH=$PYTHONPATH:/home/alice/python-teos/ + +You should also include the command in your `.bashrc` to avoid having to run it every time you open a new terminal. You can do it by running: + + echo 'export PYTHONPATH=$PYTHONPATH:' >> ~/.bashrc + +## Modify Configuration Parameters If you'd like to modify some of the configuration defaults (such as the user directory, where the logs will be stored) you can do so in the config file located at: /teos/conf.py diff --git a/README.md b/README.md index 051cffa..60942b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## State of the code +## State of the Code Currently working on updating the software to match [BOLT13 rev1](https://github.com/sr-gi/bolt13). @@ -6,7 +6,7 @@ Currently working on updating the software to match [BOLT13 rev1](https://github The Eye of Satoshi is a Lightning watchtower compliant with [BOLT13](https://github.com/sr-gi/bolt13), written in Python 3. -TEOS consists in three main modules: +`teos` consists in three main modules: - `teos`: including the tower's main functionality (server-side) - `cli`: including a reference command line interface (client-side) @@ -24,19 +24,41 @@ BTC_NETWORK = "regtest" ### Running TEOS You can run `teos` buy running `teosd.py` under `teos`. -To run `teos` you need a set of keys (to sign appointments) stored in your data directory. You can use `generate_keys.py` to generate those keys. +`teos` comes with a default configuration file (check [conf.py](teos/conf.py)). The configuration file include, amongst others, where your data folder is placed, what network it connects to, etc. -`teos` comes with a default configuration file (check [conf.py](teos/conf.py)). The configuration file include, amost others, where your data folder is placed, what network it connects to, etc. +To run `teos` you need a set of keys (to sign appointments) stored in your data directory. You can follow [generate keys](#generate-keys) to generate them. -### Interacting with a TEOS instance +### Interacting with a TEOS Instance You can interact with a `teos` instance (either run by yourself or someone else) by using `teos_cli` under `cli`. Since `teos_cli` works independently of `teos`, it uses a different configuration file (check [cli/conf.py](cli/conf.py)). -`teos_cli` also needs an independent set of keys (that can be generated using `generate_keys.py`) as well as the public key of the tower instance (`teos_pk.der`). The same data directory can be used for both if you are running things locally. +`teos_cli` also needs an independent set of keys (that can be generated following [generate keys](#generate-keys)) as well as the public key of the tower instance (`teos_pk.der`). The same data directory can be used for both if you are running things locally. Notice that `teos_cli` is a simple way to interact with `teos`, but ideally that should be part of your wallet functionality (therefore why they are independent entities). `teos_cli` can be used as an example for how to send data to a [BOLT13](https://github.com/sr-gi/bolt13) compliant watchtower. - + +### Generate Keys + +In order to generate a pair of keys for `teos` (or `teos_cli`) you can use `generate_keys.py`. + +The script generates a set of keys (`teos_sk.der` and `teos_pk.der`) in the current directory, by default. The name and output directory can be changed using `-n` and `-d` respectively. + +The following command will generate a set of keys for `teos` and store it in the default data directory (`~/.teos`): +``` +python generate_keys.py -d ~./teos +``` + +The following command will generate a set of keys for `teos_cli` and store it in the default data directory (`~/.teos_cli`): +``` +python generate_keys.py -n cli -d ~./teos_cli +``` + +Notice that `cli` needs a copy of the tower public key, so you should make a copy of that if you're using different data directories (as in this example): + +``` +cp ~./teos/teos_pk.der ~./teos_cli/teos_pk.der +``` + ## Dependencies Refer to [DEPENDENCIES.md](DEPENDENCIES.md)