def setup_node(): global btc_addr # Check bitcoind is running while generating the address while True: # FIXME: Not creating a new bitcoin_cli here creates one of those Request-Sent errors I don't know how to fix # Not a big deal, but it would be nicer not having to. bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % ( config.get("BTC_RPC_USER"), config.get("BTC_RPC_PASSWORD"), config.get("BTC_RPC_CONNECT"), config.get("BTC_RPC_PORT"), )) try: btc_addr = bitcoin_cli.getnewaddress() break except ConnectionError: sleep(1) except JSONRPCException as e: if "Loading wallet..." in str(e): sleep(1) # Mine enough blocks so coinbases are mature and we have enough funds to run everything bitcoin_cli.generatetoaddress(105, btc_addr) create_initial_transactions()
def bitcoin_cli(): config = get_config(DATA_DIR, CONF_FILE_NAME, DEFAULT_CONF) return AuthServiceProxy("http://%s:%s@%s:%d" % ( config.get("BTC_RPC_USER"), config.get("BTC_RPC_PASSWORD"), config.get("BTC_RPC_CONNECT"), config.get("BTC_RPC_PORT"), ))
def bitcoin_cli(): config = get_config(DATA_DIR, CONF_FILE_NAME, DEFAULT_CONF) print(config) # btc_connect_params = {k: v["value"] for k, v in DEFAULT_CONF.items() if k.startswith("BTC")} return AuthServiceProxy("http://%s:%s@%s:%d" % ( config.get("BTC_RPC_USER"), config.get("BTC_RPC_PASSWD"), config.get("BTC_RPC_CONNECT"), config.get("BTC_RPC_PORT"), ))
def bitcoin_cli(btc_connect_params): """ An ``http`` connection with ``bitcoind`` using the ``json-rpc`` interface. Args: btc_connect_params (:obj:`dict`): a dictionary with the parameters to connect to bitcoind (rpc user, rpc password, host and port) Returns: :obj:`AuthServiceProxy <teos.utils.auth_proxy.AuthServiceProxy>`: An authenticated service proxy to ``bitcoind`` that can be used to send ``json-rpc`` commands. """ return AuthServiceProxy("http://%s:%s@%s:%d" % ( btc_connect_params.get("BTC_RPC_USER"), btc_connect_params.get("BTC_RPC_PASSWORD"), btc_connect_params.get("BTC_RPC_CONNECT"), btc_connect_params.get("BTC_RPC_PORT"), ))
from shutil import rmtree, copy from decimal import Decimal, getcontext from teos.teosd import get_config from teos.utils.auth_proxy import AuthServiceProxy, JSONRPCException getcontext().prec = 10 utxos = list() btc_addr = None cmd_args = {"BTC_NETWORK": "regtest"} config = get_config(cmd_args, ".teos") bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % ( config.get("BTC_RPC_USER"), config.get("BTC_RPC_PASSWORD"), config.get("BTC_RPC_CONNECT"), config.get("BTC_RPC_PORT"), )) @pytest.fixture(scope="session", autouse=True) def prng_seed(): random.seed(0) @pytest.fixture(scope="session") def run_bitcoind(dirname=".test_bitcoin"): # Run bitcoind in a separate folder makedirs(dirname, exist_ok=True) bitcoind = os.getenv("BITCOIND", "bitcoind")