diff --git a/.env-sample b/.env-sample index 668417382..3ef472a6a 100644 --- a/.env-sample +++ b/.env-sample @@ -11,14 +11,24 @@ MACAROON_PATH='data/chain/bitcoin/testnet/admin.macaroon' LND_CERT_BASE64='LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNLVENDQWRDZ0F3SUJBZ0lRQ0VoeGpPZXY1bGQyVFNPTXhKalFvekFLQmdncWhrak9QUVFEQWpBNE1SOHcKSFFZRFZRUUtFeFpzYm1RZ1lYVjBiMmRsYm1WeVlYUmxaQ0JqWlhKME1SVXdFd1lEVlFRREV3d3dNakJtTVRnMQpZelkwTnpVd0hoY05Nakl3TWpBNE1UWXhOalV3V2hjTk1qTXdOREExTVRZeE5qVXdXakE0TVI4d0hRWURWUVFLCkV4WnNibVFnWVhWMGIyZGxibVZ5WVhSbFpDQmpaWEowTVJVd0V3WURWUVFERXd3d01qQm1NVGcxWXpZME56VXcKV1RBVEJnY3Foa2pPUFFJQkJnZ3Foa2pPUFFNQkJ3TkNBQVNJVWdkcVMrWFZKL3EzY0JZeWd6ZDc2endaanlmdQpLK3BzcWNYVkFyeGZjU2NXQ25jbXliNGRaMy9Lc3lLWlRaamlySDE3aEY0OGtIMlp5clRZSW9hZG80RzdNSUc0Ck1BNEdBMVVkRHdFQi93UUVBd0lDcERBVEJnTlZIU1VFRERBS0JnZ3JCZ0VGQlFjREFUQVBCZ05WSFJNQkFmOEUKQlRBREFRSC9NQjBHQTFVZERnUVdCQlEwWUJjZXdsd1BqYTJPRXFyTGxzZnJscEswUFRCaEJnTlZIUkVFV2pCWQpnZ3d3TWpCbU1UZzFZelkwTnpXQ0NXeHZZMkZzYUc5emRJSUVkVzVwZUlJS2RXNXBlSEJoWTJ0bGRJSUhZblZtClkyOXVib2NFZndBQUFZY1FBQUFBQUFBQUFBQUFBQUFBQUFBQUFZY0V3S2dRQW9jRUFBQUFBREFLQmdncWhrak8KUFFRREFnTkhBREJFQWlBd0dMY05qNXVZSkVwanhYR05OUnNFSzAwWmlSUUh2Qm50NHp6M0htWHBiZ0lnSWtvUQo3cHFvNGdWNGhiczdrSmt1bnk2bkxlNVg0ZzgxYjJQOW52ZnZ2bkk9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K' # base64 ~/.lnd/data/chain/bitcoin/testnet/admin.macaroon | tr -d '\n' LND_MACAROON_BASE64='AgEDbG5kAvgBAwoQsyI+PK+fyb7F2UyTeZ4seRIBMBoWCgdhZGRyZXNzEgRyZWFkEgV3cml0ZRoTCgRpbmZvEgRyZWFkEgV3cml0ZRoXCghpbnZvaWNlcxIEcmVhZBIFd3JpdGUaIQoIbWFjYXJvb24SCGdlbmVyYXRlEgRyZWFkEgV3cml0ZRoWCgdtZXNzYWdlEgRyZWFkEgV3cml0ZRoXCghvZmZjaGFpbhIEcmVhZBIFd3JpdGUaFgoHb25jaGFpbhIEcmVhZBIFd3JpdGUaFAoFcGVlcnMSBHJlYWQSBXdyaXRlGhgKBnNpZ25lchIIZ2VuZXJhdGUSBHJlYWQAAAYgMt90uD6v4truTadWCjlppoeJ4hZrL1SBb09Y+4WOiI0=' +LND_GRPC_HOST='localhost' +LND_GRPC_PORT='10009' +# Auto unlock LND password. Only used in development docker-compose environment. +# It will fail starting up the node without it. +# To disable auto unlock, comment out 'wallet-unlock-password-file=/tmp/pwd' from 'docker/lnd/lnd.conf' +AUTO_UNLOCK_PWD='1234' # CLN directory CLN_DIR='/cln/testnet/' -CLN_GRPC_HOST='localhost:9999' -CLN_GRPC_HOLD_HOST='localhost:9998' +CLN_GRPC_HOST='localhost' +CLN_GRPC_PORT='9999' +CLN_GRPC_HOLD_HOST='localhost' +CLN_GRPC_HOLD_PORT='9998' # Bitcoin Core Daemon RPC, used to validate addresses -BITCOIND_RPCURL = 'http://127.0.0.1:18332' +# mainnet: 8332, testnet: 18332, signet: 38332, regtest: 18443 +BITCOIND_RPCHOST = '127.0.0.1' +BITCOIND_RPCPORT = '18332' BITCOIND_RPCUSER = 'robodev' BITCOIND_RPCPASSWORD = 'robodev' @@ -33,14 +43,9 @@ POSTGRES_PORT='5432' USE_TOR=True TOR_PROXY='127.0.0.1:9050' -# Auto unlock LND password. Only used in development docker-compose environment. -# It will fail starting up the node without it. -# To disable auto unlock, comment out 'wallet-unlock-password-file=/tmp/pwd' from 'docker/lnd/lnd.conf' -AUTO_UNLOCK_PWD='1234' - -LND_GRPC_HOST='localhost:10009' - -REDIS_URL='redis://localhost:6379/1' +REDIS_HOST="localhost" +REDIS_PORT="6379" +REDIS_DB_NUMBER="1" # List of market price public APIs. If the currency is available in more than 1 API, will use median price. MARKET_PRICE_APIS = https://blockchain.info/ticker, https://api.yadio.io/exrates/BTC, https://bitpay.com/rates/BTC, https://criptoya.com/api/btc diff --git a/api/lightning/cln.py b/api/lightning/cln.py index c446a83a9..260706d64 100755 --- a/api/lightning/cln.py +++ b/api/lightning/cln.py @@ -29,8 +29,12 @@ server_cert = f.read() -CLN_GRPC_HOST = config("CLN_GRPC_HOST", cast=str, default="localhost:9999") -CLN_GRPC_HOLD_HOST = config("CLN_GRPC_HOLD_HOST", cast=str, default="localhost:9998") +CLN_GRPC_HOST = \ + str(config("CLN_GRPC_HOST", cast=str, default="localhost")) + \ + ":" + str(config("CLN_GRPC_PORT", cast=str, default="9999")) +CLN_GRPC_HOLD_HOST = \ + str(config("CLN_GRPC_HOLD_HOST", cast=str, default="localhost")) + \ + ":" + str(config("CLN_GRPC_HOLD_PORT", cast=str, default="9998")) DISABLE_ONCHAIN = config("DISABLE_ONCHAIN", cast=bool, default=True) MAX_SWAP_AMOUNT = config("MAX_SWAP_AMOUNT", cast=int, default=500000) diff --git a/api/lightning/lnd.py b/api/lightning/lnd.py index 706b4a6b1..90f8fc833 100644 --- a/api/lightning/lnd.py +++ b/api/lightning/lnd.py @@ -42,7 +42,9 @@ except Exception: MACAROON = b64decode(config("LND_MACAROON_BASE64")) -LND_GRPC_HOST = config("LND_GRPC_HOST") +LND_GRPC_HOST = \ + str(config("LND_GRPC_HOST", cast=str, default="localhost")) + \ + ":" + str(config("LND_GRPC_PORT", cast=str, default="10009")) DISABLE_ONCHAIN = config("DISABLE_ONCHAIN", cast=bool, default=True) MAX_SWAP_AMOUNT = config("MAX_SWAP_AMOUNT", cast=int, default=500_000) diff --git a/api/tests/test_utils.py b/api/tests/test_utils.py index 0cf427ca2..8971d35e2 100644 --- a/api/tests/test_utils.py +++ b/api/tests/test_utils.py @@ -35,7 +35,7 @@ def test_get_session(self, mock_session, mock_config): @patch("api.utils.config") @patch("api.utils.requests.post") def test_bitcoind_rpc(self, mock_post, mock_config): - mock_config.side_effect = ["url", "user", "password"] + mock_config.side_effect = ["host", "port", "user", "password"] mock_post.return_value.json.return_value = {"result": "response"} response = bitcoind_rpc("method", ["params"]) self.assertEqual(response, "response") diff --git a/api/utils.py b/api/utils.py index 66658db2b..06cbdd989 100644 --- a/api/utils.py +++ b/api/utils.py @@ -37,7 +37,9 @@ def bitcoind_rpc(method, params=None): :return: """ - BITCOIND_RPCURL = config("BITCOIND_RPCURL") + BITCOIND_RPCHOST = str(config("BITCOIND_RPCHOST", cast=str, default="127.0.0.1")) + BITCOIND_RPCPORT = str(config("BITCOIND_RPCPORT", cast=str, default="18332")) + BITCOIND_RPCURL = "http://" + BITCOIND_RPCHOST + ":" + BITCOIND_RPCPORT BITCOIND_RPCUSER = config("BITCOIND_RPCUSER") BITCOIND_RPCPASSWORD = config("BITCOIND_RPCPASSWORD") diff --git a/docker-compose.yml b/docker-compose.yml index c8334bdb8..e21ed7f33 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -115,7 +115,9 @@ services: container_name: cele-worker-dev restart: always environment: - REDIS_URL: redis://localhost:6379 + REDIS_HOST: localhost + REDIS_PORT: 6379 + REDIS_DB_NUMBER: 1 SKIP_COLLECT_STATIC: "true" volumes: - .:/usr/src/robosats @@ -132,7 +134,9 @@ services: container_name: cele-beat-dev restart: always environment: - REDIS_URL: redis://localhost:6379 + REDIS_HOST: localhost + REDIS_PORT: 6379 + REDIS_DB_NUMBER: 1 SKIP_COLLECT_STATIC: "true" command: celery -A robosats beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler volumes: diff --git a/docker-tests.yml b/docker-tests.yml index 975747e88..432d791a8 100644 --- a/docker-tests.yml +++ b/docker-tests.yml @@ -149,7 +149,8 @@ services: USE_TOR: False MACAROON_PATH: 'data/chain/bitcoin/regtest/admin.macaroon' CLN_DIR: '/cln/regtest/' - BITCOIND_RPCURL: 'http://127.0.0.1:18443' + BITCOIND_RPCHOST: '127.0.0.1' + BITCOIND_RPCPORT: '18443' BITCOIND_RPCUSER: 'test' BITCOIND_RPCPASSWORD: 'test' env_file: @@ -190,7 +191,8 @@ services: # USE_TOR: False # MACAROON_PATH: 'data/chain/bitcoin/regtest/admin.macaroon' # CLN_DIR: '/cln/regtest/' - # BITCOIND_RPCURL: 'http://127.0.0.1:18443' + # BITCOIND_RPCHOST: '127.0.0.1' + # BITCOIND_RPCPORT: '18443' # BITCOIND_RPCUSER: 'test' # BITCOIND_RPCPASSWORD: 'test' # SKIP_COLLECT_STATIC: "true" @@ -210,4 +212,4 @@ volumes: bitcoin: lnd: cln: - lndrobot: \ No newline at end of file + lndrobot: diff --git a/robosats/celery/__init__.py b/robosats/celery/__init__.py index c1a27eb60..313796660 100644 --- a/robosats/celery/__init__.py +++ b/robosats/celery/__init__.py @@ -3,11 +3,15 @@ import os from datetime import timedelta +from decouple import config from celery import Celery from celery.schedules import crontab # You can use rabbitmq instead here. -BASE_REDIS_URL = os.environ.get("REDIS_URL", "redis://localhost:6379") +BASE_REDIS_URL = \ + "redis://" + str(config("REDIS_HOST", cast=str, default="localhost")) + \ + ":" + str(config("REDIS_PORT", cast=str, default="6379")) + \ + "/" + str(config("REDIS_DB_NUMBER", cast=str, default="1")) # set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "robosats.settings") diff --git a/robosats/settings.py b/robosats/settings.py index 555061f06..4a762300f 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -231,7 +231,11 @@ "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { - "hosts": [config("REDIS_URL")], + "hosts": [ + "redis://" + str(config("REDIS_HOST", cast=str, default="localhost")) + \ + ":" + str(config("REDIS_PORT", cast=str, default="6379")) + \ + "/" + str(config("REDIS_DB_NUMBER", cast=str, default="1")) + ], }, }, } @@ -239,7 +243,10 @@ CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": config("REDIS_URL"), + "LOCATION": \ + "redis://" + str(config("REDIS_HOST", cast=str, default="localhost")) + \ + ":" + str(config("REDIS_PORT", cast=str, default="6379")) + \ + "/" + str(config("REDIS_DB_NUMBER", cast=str, default="1")), "OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"}, } }