From b53627aa6d17e82a53e035a0ca7641fb3a354467 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 11 Dec 2019 13:12:37 +0100 Subject: [PATCH] tools docstrings --- pisa/tools.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pisa/tools.py b/pisa/tools.py index bb2174c..4931d2e 100644 --- a/pisa/tools.py +++ b/pisa/tools.py @@ -1,12 +1,23 @@ -import re from http.client import HTTPException import pisa.conf as conf from pisa.utils.auth_proxy import AuthServiceProxy, JSONRPCException +""" +Tools is a module with general methods that can used by different entities in the codebase. +""" + # NOTCOVERED def bitcoin_cli(): + """ + An ``http`` connection with ``bitcoind`` using the ``json-rpc`` interface. + + Returns: + ``AuthServiceProxy``: An authenticated service proxy to ``bitcoind`` that can be used to send ``json-rpc`` + commands. + """ + return AuthServiceProxy( "http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST, conf.BTC_RPC_PORT) ) @@ -14,6 +25,13 @@ def bitcoin_cli(): # NOTCOVERED def can_connect_to_bitcoind(): + """ + Checks if the tower has connection to ``bitcoind``. + + Returns: + ``bool``: ``True`` if the connection can be established. ``False`` otherwise. + """ + can_connect = True try: @@ -25,6 +43,14 @@ def can_connect_to_bitcoind(): def in_correct_network(network): + """ + Checks if ``bitcoind`` and the tower are configured to run in the same network (``mainnet``, ``testnet`` or + ``regtest``) + + Returns: + ``bool``: ``True`` if the network configuration matches. ``False`` otherwise. + """ + mainnet_genesis_block_hash = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" testnet3_genesis_block_hash = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" correct_network = False