mirror of
https://github.com/basicswap/basicswap.git
synced 2026-05-07 06:52:12 +02:00
Merge pull request #463 from tecnovert/extracoinopts
New extracoinopts run parameter
This commit is contained in:
+42
-26
@@ -2,10 +2,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2019-2024 tecnovert
|
# Copyright (c) 2019-2024 tecnovert
|
||||||
# Copyright (c) 2024-2025 The Basicswap developers
|
# Copyright (c) 2024-2026 The Basicswap developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
import copy
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -22,6 +23,7 @@ from basicswap.chainparams import chainparams, Coins, isKnownCoinName
|
|||||||
from basicswap.network.simplex_chat import startSimplexClient
|
from basicswap.network.simplex_chat import startSimplexClient
|
||||||
from basicswap.ui.util import getCoinName
|
from basicswap.ui.util import getCoinName
|
||||||
from basicswap.util.daemon import Daemon
|
from basicswap.util.daemon import Daemon
|
||||||
|
from typing import Set
|
||||||
|
|
||||||
initial_logger = logging.getLogger()
|
initial_logger = logging.getLogger()
|
||||||
initial_logger.level = logging.DEBUG
|
initial_logger.level = logging.DEBUG
|
||||||
@@ -347,7 +349,7 @@ def mainLoop(daemons, update: bool = True):
|
|||||||
def runClient(
|
def runClient(
|
||||||
data_dir: str,
|
data_dir: str,
|
||||||
chain: str,
|
chain: str,
|
||||||
start_only_coins: bool,
|
start_only_coins: Set[str],
|
||||||
log_prefix: str = "BasicSwap",
|
log_prefix: str = "BasicSwap",
|
||||||
extra_opts=dict(),
|
extra_opts=dict(),
|
||||||
) -> int:
|
) -> int:
|
||||||
@@ -391,17 +393,24 @@ def runClient(
|
|||||||
# Settings may have been modified
|
# Settings may have been modified
|
||||||
settings = swap_client.settings
|
settings = swap_client.settings
|
||||||
|
|
||||||
|
base_coin_opts = []
|
||||||
|
if "extra_coin_opts" in extra_opts:
|
||||||
|
if len(start_only_coins) == 0:
|
||||||
|
raise ValueError('"extracoinopts" can only be used with "startonlycoins"')
|
||||||
|
base_coin_opts += extra_opts["extra_coin_opts"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Try start daemons
|
# Try start daemons
|
||||||
|
if len(start_only_coins) > 0:
|
||||||
|
swap_client.log.warning('Not starting networks as "startonlycoin" is set')
|
||||||
|
else:
|
||||||
for network in settings.get("networks", []):
|
for network in settings.get("networks", []):
|
||||||
if network.get("enabled", True) is False:
|
if network.get("enabled", True) is False:
|
||||||
continue
|
continue
|
||||||
network_type: str = network.get("type", "unknown")
|
network_type: str = network.get("type", "unknown")
|
||||||
if network_type == "simplex":
|
if network_type == "simplex":
|
||||||
simplex_dir = os.path.join(data_dir, "simplex")
|
simplex_dir = os.path.join(data_dir, "simplex")
|
||||||
|
|
||||||
log_level = "debug" if swap_client.debug else "info"
|
log_level = "debug" if swap_client.debug else "info"
|
||||||
|
|
||||||
socks_proxy = None
|
socks_proxy = None
|
||||||
if "socks_proxy_override" in network:
|
if "socks_proxy_override" in network:
|
||||||
socks_proxy = network["socks_proxy_override"]
|
socks_proxy = network["socks_proxy_override"]
|
||||||
@@ -460,10 +469,18 @@ def runClient(
|
|||||||
trusted_daemon: bool = swap_client.getXMRTrustedDaemon(
|
trusted_daemon: bool = swap_client.getXMRTrustedDaemon(
|
||||||
coin_id, v["rpchost"]
|
coin_id, v["rpchost"]
|
||||||
)
|
)
|
||||||
opts = [
|
wallet_opts = [
|
||||||
|
"--trusted-daemon" if trusted_daemon else "--untrusted-daemon",
|
||||||
"--daemon-address",
|
"--daemon-address",
|
||||||
daemon_addr,
|
daemon_addr,
|
||||||
]
|
]
|
||||||
|
daemon_rpcuser = v.get("rpcuser", "")
|
||||||
|
daemon_rpcpass = v.get("rpcpassword", "")
|
||||||
|
if daemon_rpcuser != "":
|
||||||
|
wallet_opts += [
|
||||||
|
"--daemon-login",
|
||||||
|
daemon_rpcuser + ":" + daemon_rpcpass,
|
||||||
|
]
|
||||||
|
|
||||||
proxy_log_str = ""
|
proxy_log_str = ""
|
||||||
proxy_host, proxy_port = swap_client.getXMRWalletProxy(
|
proxy_host, proxy_port = swap_client.getXMRWalletProxy(
|
||||||
@@ -471,7 +488,7 @@ def runClient(
|
|||||||
)
|
)
|
||||||
if proxy_host:
|
if proxy_host:
|
||||||
proxy_log_str = " through proxy"
|
proxy_log_str = " through proxy"
|
||||||
opts += [
|
wallet_opts += [
|
||||||
"--proxy",
|
"--proxy",
|
||||||
f"{proxy_host}:{proxy_port}",
|
f"{proxy_host}:{proxy_port}",
|
||||||
"--daemon-ssl-allow-any-cert",
|
"--daemon-ssl-allow-any-cert",
|
||||||
@@ -485,19 +502,11 @@ def runClient(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
daemon_rpcuser = v.get("rpcuser", "")
|
|
||||||
daemon_rpcpass = v.get("rpcpassword", "")
|
|
||||||
if daemon_rpcuser != "":
|
|
||||||
opts.append("--daemon-login")
|
|
||||||
opts.append(daemon_rpcuser + ":" + daemon_rpcpass)
|
|
||||||
|
|
||||||
opts.append(
|
|
||||||
"--trusted-daemon" if trusted_daemon else "--untrusted-daemon"
|
|
||||||
)
|
|
||||||
filename: str = getWalletBinName(coin_id, v, c + "-wallet-rpc")
|
filename: str = getWalletBinName(coin_id, v, c + "-wallet-rpc")
|
||||||
|
|
||||||
daemons.append(
|
daemons.append(
|
||||||
startXmrWalletDaemon(v["datadir"], v["bindir"], filename, opts)
|
startXmrWalletDaemon(
|
||||||
|
v["datadir"], v["bindir"], filename, wallet_opts
|
||||||
|
)
|
||||||
)
|
)
|
||||||
pid = daemons[-1].handle.pid
|
pid = daemons[-1].handle.pid
|
||||||
swap_client.log.info(f"Started {filename} {pid}")
|
swap_client.log.info(f"Started {filename} {pid}")
|
||||||
@@ -506,9 +515,8 @@ def runClient(
|
|||||||
|
|
||||||
if c == "decred":
|
if c == "decred":
|
||||||
appdata = v["datadir"]
|
appdata = v["datadir"]
|
||||||
extra_opts = [
|
coin_opts = copy.deepcopy(base_coin_opts)
|
||||||
f'--appdata="{appdata}"',
|
coin_opts.append(f'--appdata="{appdata}"')
|
||||||
]
|
|
||||||
use_shell: bool = True if os.name == "nt" else False
|
use_shell: bool = True if os.name == "nt" else False
|
||||||
if v["manage_daemon"] is True:
|
if v["manage_daemon"] is True:
|
||||||
swap_client.log.info(f"Starting {display_name} daemon")
|
swap_client.log.info(f"Starting {display_name} daemon")
|
||||||
@@ -526,7 +534,7 @@ def runClient(
|
|||||||
appdata,
|
appdata,
|
||||||
v["bindir"],
|
v["bindir"],
|
||||||
filename,
|
filename,
|
||||||
opts=extra_opts,
|
opts=coin_opts,
|
||||||
extra_config=extra_config,
|
extra_config=extra_config,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -537,12 +545,13 @@ def runClient(
|
|||||||
swap_client.log.info(f"Starting {display_name} wallet daemon")
|
swap_client.log.info(f"Starting {display_name} wallet daemon")
|
||||||
filename: str = getWalletBinName(coin_id, v, "dcrwallet")
|
filename: str = getWalletBinName(coin_id, v, "dcrwallet")
|
||||||
|
|
||||||
|
wallet_opts = [f'--appdata="{appdata}"']
|
||||||
wallet_pwd = v["wallet_pwd"]
|
wallet_pwd = v["wallet_pwd"]
|
||||||
if wallet_pwd == "":
|
if wallet_pwd == "":
|
||||||
# Only set when in startonlycoin mode
|
# Only set when in startonlycoin mode
|
||||||
wallet_pwd = os.getenv("WALLET_ENCRYPTION_PWD", "")
|
wallet_pwd = os.getenv("WALLET_ENCRYPTION_PWD", "")
|
||||||
if wallet_pwd != "":
|
if wallet_pwd != "":
|
||||||
extra_opts.append(f'--pass="{wallet_pwd}"')
|
wallet_opts.append(f'--pass="{wallet_pwd}"')
|
||||||
extra_config = {
|
extra_config = {
|
||||||
"add_datadir": False,
|
"add_datadir": False,
|
||||||
"stdout_to_file": True,
|
"stdout_to_file": True,
|
||||||
@@ -555,13 +564,12 @@ def runClient(
|
|||||||
appdata,
|
appdata,
|
||||||
v["bindir"],
|
v["bindir"],
|
||||||
filename,
|
filename,
|
||||||
opts=extra_opts,
|
opts=wallet_opts,
|
||||||
extra_config=extra_config,
|
extra_config=extra_config,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
pid = daemons[-1].handle.pid
|
pid = daemons[-1].handle.pid
|
||||||
swap_client.log.info(f"Started {filename} {pid}")
|
swap_client.log.info(f"Started {filename} {pid}")
|
||||||
|
|
||||||
continue # /decred
|
continue # /decred
|
||||||
|
|
||||||
if v["manage_daemon"] is True:
|
if v["manage_daemon"] is True:
|
||||||
@@ -571,7 +579,7 @@ def runClient(
|
|||||||
swap_client.log.info(f"Starting {display_name} daemon")
|
swap_client.log.info(f"Starting {display_name} daemon")
|
||||||
|
|
||||||
filename: str = getCoreBinName(coin_id, v, c + "d")
|
filename: str = getCoreBinName(coin_id, v, c + "d")
|
||||||
extra_opts = getCoreBinArgs(
|
coin_opts = copy.deepcopy(base_coin_opts) + getCoreBinArgs(
|
||||||
coin_id, v, use_tor_proxy=swap_client.use_tor_proxy
|
coin_id, v, use_tor_proxy=swap_client.use_tor_proxy
|
||||||
)
|
)
|
||||||
extra_config = {"coin_name": c}
|
extra_config = {"coin_name": c}
|
||||||
@@ -580,7 +588,7 @@ def runClient(
|
|||||||
v["datadir"],
|
v["datadir"],
|
||||||
v["bindir"],
|
v["bindir"],
|
||||||
filename,
|
filename,
|
||||||
opts=extra_opts,
|
opts=coin_opts,
|
||||||
extra_config=extra_config,
|
extra_config=extra_config,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -679,6 +687,9 @@ def printHelp():
|
|||||||
print(
|
print(
|
||||||
"--startonlycoin Only start the provides coin daemon/s, use this if a chain requires extra processing."
|
"--startonlycoin Only start the provides coin daemon/s, use this if a chain requires extra processing."
|
||||||
)
|
)
|
||||||
|
print(
|
||||||
|
"--extracoinopts Extra options to pass to coin daemon, can only be used with --startonlycoin."
|
||||||
|
)
|
||||||
print("--logprefix Specify log prefix.")
|
print("--logprefix Specify log prefix.")
|
||||||
print(
|
print(
|
||||||
"--forcedbupgrade Recheck database against schema regardless of version."
|
"--forcedbupgrade Recheck database against schema regardless of version."
|
||||||
@@ -743,6 +754,11 @@ def main():
|
|||||||
ensure_coin_valid(coin)
|
ensure_coin_valid(coin)
|
||||||
start_only_coins.add(coin)
|
start_only_coins.add(coin)
|
||||||
continue
|
continue
|
||||||
|
if name == "extracoinopts":
|
||||||
|
options["extra_coin_opts"] = []
|
||||||
|
for opt in [s.lower() for s in s[1].split(",")]:
|
||||||
|
options["extra_coin_opts"].append(opt)
|
||||||
|
continue
|
||||||
|
|
||||||
logger.warning(f"Unknown argument {v}")
|
logger.warning(f"Unknown argument {v}")
|
||||||
|
|
||||||
|
|||||||
@@ -250,11 +250,18 @@ def upgradeDatabaseFromSchema(self, cursor, expect_schema):
|
|||||||
|
|
||||||
|
|
||||||
def upgradeDatabase(self, db_version: int):
|
def upgradeDatabase(self, db_version: int):
|
||||||
if self._force_db_upgrade is False and db_version >= CURRENT_DB_VERSION:
|
upgrade_forced: bool = False
|
||||||
|
if db_version < CURRENT_DB_VERSION:
|
||||||
|
pass
|
||||||
|
elif self._force_db_upgrade is True:
|
||||||
|
upgrade_forced = True
|
||||||
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
f"Upgrading database from version {db_version} to {CURRENT_DB_VERSION}."
|
f"Upgrading database from version {db_version} to {CURRENT_DB_VERSION}"
|
||||||
|
+ (" (forced)" if upgrade_forced else "")
|
||||||
|
+ "."
|
||||||
)
|
)
|
||||||
|
|
||||||
# db_version, tablename, oldcolumnname, newcolumnname
|
# db_version, tablename, oldcolumnname, newcolumnname
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ Observe progress with
|
|||||||
tail -f /tmp/firo.log
|
tail -f /tmp/firo.log
|
||||||
|
|
||||||
|
|
||||||
|
Alternatively --extracoinopts can be used with --startonlycoin
|
||||||
|
|
||||||
|
docker-compose run --rm swapclient \
|
||||||
|
basicswap-run --datadir=/coindata --startonlycoin=litecoin --extracoinopts="-reindex"
|
||||||
|
|
||||||
|
|
||||||
## Start a subset of the configured coins using docker
|
## Start a subset of the configured coins using docker
|
||||||
|
|
||||||
docker compose run --rm --service-ports swapclient basicswap-run -datadir=/coindata -withcoins=monero
|
docker compose run --rm --service-ports swapclient basicswap-run -datadir=/coindata -withcoins=monero
|
||||||
|
|||||||
Reference in New Issue
Block a user