12 Commits

Author SHA1 Message Date
tecnovert
19d7d0a5b4 test: change more wallet names 2026-04-08 22:23:18 +02:00
tecnovert
67b290db27 Merge pull request #442 from tecnovert/set_wallet_name
refactor: where possible use "bsx_wallet" name for new installs
2026-04-08 20:07:03 +00:00
tecnovert
6df5c4687d Merge pull request #441 from tecnovert/wallet_name
fix: remove workaround for blank wallet name
2026-04-08 20:06:21 +00:00
tecnovert
7f125a2fe1 Merge pull request #443 from tecnovert/backports
refactor: backports
2026-04-08 20:06:00 +00:00
tecnovert
9b4a853c65 Merge pull request #445 from gerlofvanek/wallet_tables
Cleanup / Wallet tables use own schema.
2026-04-08 20:05:41 +00:00
gerlofvanek
953ef6b4ae Remove extra_tables. 2026-04-08 20:52:05 +02:00
gerlofvanek
614d29c31c Cleanup / Wallet tables use own schema. 2026-04-08 19:55:33 +02:00
tecnovert
360d356cbf refactor: backports 2026-04-08 09:47:27 +02:00
tecnovert
3ff67f0766 fix: enable multiwallet for BCH 2026-04-08 00:39:52 +02:00
tecnovert
25b7ecfc42 tests: change wallet name 2026-04-07 23:23:02 +02:00
tecnovert
da248239d4 refactor: where possible use "bsx_wallet" name for new installs 2026-04-07 23:23:02 +02:00
tecnovert
0061b347f5 fix: remove workaround for blank wallet name 2026-04-07 22:54:41 +02:00
27 changed files with 233 additions and 190 deletions

View File

@@ -148,14 +148,7 @@ from .db import (
XmrSwap, XmrSwap,
) )
from .wallet_manager import WalletManager from .wallet_manager import WalletManager
from .db_wallet import (
WalletAddress,
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
)
from .explorers import ( from .explorers import (
ExplorerInsight, ExplorerInsight,
ExplorerBitAps, ExplorerBitAps,
@@ -614,15 +607,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
if not db_exists: if not db_exists:
self.log.info("First run") self.log.info("First run")
wallet_tables = [ create_db(self.sqlite_file, self.log)
WalletAddress,
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
]
create_db(self.sqlite_file, self.log, extra_tables=wallet_tables)
cursor = self.openDB() cursor = self.openDB()
try: try:
@@ -3964,6 +3949,13 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
except Exception as e: except Exception as e:
raise ValueError(f"Invalid message networks: {e}") raise ValueError(f"Invalid message networks: {e}")
def isValidSwapDest(self, ci, dest: bytes):
ensure(isinstance(dest, bytes), "Swap destination must be bytes")
if ci.coin_type() in (Coins.PART_BLIND,):
return ci.isValidPubkey(dest)
# TODO: allow p2wsh
return ci.isValidAddressHash(dest)
def ensureWalletCanSend( def ensureWalletCanSend(
self, ci, swap_type, ensure_balance: int, estimated_fee: int, for_offer=True self, ci, swap_type, ensure_balance: int, estimated_fee: int, for_offer=True
) -> None: ) -> None:
@@ -5365,12 +5357,13 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.loadBidTxns(bid, cursor) self.loadBidTxns(bid, cursor)
return bid, xmr_swap return bid, xmr_swap
def getXmrBid(self, bid_id: bytes): def getXmrBid(self, bid_id: bytes, cursor=None):
try: try:
cursor = self.openDB() use_cursor = self.openDB(cursor)
return self.getXmrBidFromSession(cursor, bid_id) return self.getXmrBidFromSession(use_cursor, bid_id)
finally: finally:
self.closeDB(cursor, commit=False) if cursor is None:
self.closeDB(use_cursor, commit=False)
def getXmrOfferFromSession(self, cursor, offer_id: bytes): def getXmrOfferFromSession(self, cursor, offer_id: bytes):
offer = self.queryOne(Offer, cursor, {"offer_id": offer_id}) offer = self.queryOne(Offer, cursor, {"offer_id": offer_id})
@@ -5875,7 +5868,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
) )
if bid.bid_id and bid_msg_id != bid.bid_id: if bid.bid_id and bid_msg_id != bid.bid_id:
self.log.warning( self.log.warning(
f"sendBidMessage: Mismatched bid ids: {bid.bid_id.hex()}, {bid_msg_id.hex()}." f"sendBidMessage: Mismatched bid ids: {self.log.id(bid.bid_id)}, {self.log.id(bid_msg_id)}."
) )
return bid_msg_id return bid_msg_id
@@ -7771,7 +7764,12 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
len(xmr_swap.al_lock_refund_tx_sig) > 0 len(xmr_swap.al_lock_refund_tx_sig) > 0
and len(xmr_swap.af_lock_refund_tx_sig) > 0 and len(xmr_swap.af_lock_refund_tx_sig) > 0
): ):
try: try:
if bid.xmr_b_lock_tx is None and self.haveDebugInd(
bid.bid_id, DebugTypes.WAIT_FOR_COIN_B_LOCK_BEFORE_PREREFUND
):
raise TemporaryError("Debug: Waiting for Coin B Lock Tx")
txid = ci_from.publishTx(xmr_swap.a_lock_refund_tx) txid = ci_from.publishTx(xmr_swap.a_lock_refund_tx)
# BCH txids change # BCH txids change
@@ -7821,6 +7819,10 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.saveBidInSession(bid_id, bid, cursor, xmr_swap) self.saveBidInSession(bid_id, bid, cursor, xmr_swap)
self.commitDB() self.commitDB()
return rv return rv
else:
self.log.warning(
f"Trying to publish coin a lock refund tx: {ex}"
)
state = BidStates(bid.state) state = BidStates(bid.state)
if state == BidStates.SWAP_COMPLETED: if state == BidStates.SWAP_COMPLETED:
@@ -8067,6 +8069,15 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.log.warning( self.log.warning(
f"Not releasing ads script coin lock tx for bid {self.log.id(bid_id)}: Chain A lock refund tx already exists." f"Not releasing ads script coin lock tx for bid {self.log.id(bid_id)}: Chain A lock refund tx already exists."
) )
elif (
bid.debug_ind == DebugTypes.DONT_RELEASE_COIN_A_LOCK
):
self.logBidEvent(
bid_id,
EventLogTypes.DEBUG_TWEAK_APPLIED,
f"ind {DebugTypes.DONT_RELEASE_COIN_A_LOCK}",
None,
)
else: else:
delay = self.get_delay_event_seconds() delay = self.get_delay_event_seconds()
self.log.info( self.log.info(
@@ -8513,9 +8524,8 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
) )
watched = self.coin_clients[coin_type]["watched_transactions"] watched = self.coin_clients[coin_type]["watched_transactions"]
for wt in watched:
for wo in watched: if wt.bid_id == bid_id and wt.txid_hex == txid_hex:
if wo.bid_id == bid_id and wo.txid_hex == txid_hex:
self.log.debug("Transaction already being watched.") self.log.debug("Transaction already being watched.")
return return
@@ -8953,7 +8963,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
else: else:
self.log.info( self.log.info(
f"Coin a lock refund spent by unknown tx, bid {self.log.id(bid_id)}." f"Coin a lock refund spent by unknown tx, bid {self.log.id(bid_id)}, txid {self.logIDT(spending_txid)}."
) )
mercy_keyshare = None mercy_keyshare = None
@@ -8980,6 +8990,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
bid.setState(BidStates.XMR_SWAP_FAILED_SWIPED) bid.setState(BidStates.XMR_SWAP_FAILED_SWIPED)
else: else:
delay = self.get_delay_event_seconds() delay = self.get_delay_event_seconds()
self.log.info("Found mercy output.")
self.log.info( self.log.info(
f"Redeeming coin b lock tx for bid {self.log.id(bid_id)} in {delay} seconds." f"Redeeming coin b lock tx for bid {self.log.id(bid_id)} in {delay} seconds."
) )
@@ -9298,6 +9309,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.processFoundTransaction( self.processFoundTransaction(
t, block_hash, block["height"], chain_blocks t, block_hash, block["height"], chain_blocks
) )
for s in c["watched_scripts"]: for s in c["watched_scripts"]:
for i, txo in enumerate(tx["vout"]): for i, txo in enumerate(tx["vout"]):
if "scriptPubKey" in txo and "hex" in txo["scriptPubKey"]: if "scriptPubKey" in txo and "hex" in txo["scriptPubKey"]:
@@ -12174,7 +12186,9 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
xmr_swap.af_lock_refund_spend_tx_sig = ci_from.decryptOtVES( xmr_swap.af_lock_refund_spend_tx_sig = ci_from.decryptOtVES(
kbsl, xmr_swap.af_lock_refund_spend_tx_esig kbsl, xmr_swap.af_lock_refund_spend_tx_esig
) )
prevout_amount = ci_from.getLockRefundTxSwapOutputValue(bid, xmr_swap) prevout_amount: int = ci_from.getLockRefundTxSwapOutputValue(
bid, xmr_swap
)
al_lock_refund_spend_tx_sig = ci_from.signTx( al_lock_refund_spend_tx_sig = ci_from.signTx(
kal, kal,
xmr_swap.a_lock_refund_spend_tx, xmr_swap.a_lock_refund_spend_tx,
@@ -12601,8 +12615,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
ci_from.verifyPubkey(msg_data.pkaf), "Invalid chain A follower public key" ci_from.verifyPubkey(msg_data.pkaf), "Invalid chain A follower public key"
) )
ensure( ensure(
ci_from.isValidAddressHash(msg_data.dest_af) self.isValidSwapDest(ci_from, msg_data.dest_af),
or ci_from.isValidPubkey(msg_data.dest_af),
"Invalid destination address", "Invalid destination address",
) )
if ci_to.curve_type() == Curves.ed25519: if ci_to.curve_type() == Curves.ed25519:

View File

@@ -240,8 +240,11 @@ class DebugTypes(IntEnum):
OFFER_LOCK_2_VALUE_INC = auto() OFFER_LOCK_2_VALUE_INC = auto()
BID_STOP_AFTER_COIN_B_LOCK = auto() BID_STOP_AFTER_COIN_B_LOCK = auto()
BID_DONT_SPEND_COIN_B_LOCK = auto() BID_DONT_SPEND_COIN_B_LOCK = auto()
WAIT_FOR_COIN_B_LOCK_BEFORE_PREREFUND = auto()
WAIT_FOR_COIN_B_LOCK_BEFORE_REFUND = auto() WAIT_FOR_COIN_B_LOCK_BEFORE_REFUND = auto()
BID_DONT_SPEND_COIN_A_LOCK = auto() BID_DONT_SPEND_COIN_A_LOCK = auto()
DONT_SEND_COIN_B_LOCK = auto()
DONT_RELEASE_COIN_A_LOCK = auto()
class NotificationTypes(IntEnum): class NotificationTypes(IntEnum):

View File

@@ -2892,9 +2892,15 @@ def main():
coin_id = getCoinIdFromName(coin_name) coin_id = getCoinIdFromName(coin_name)
coin_params = chainparams[coin_id] coin_params = chainparams[coin_id]
if coin_settings.get("core_type_group", "") == "xmr": if coin_settings.get("core_type_group", "") == "xmr":
default_name = "swap_wallet" default_name: str = "swap_wallet"
use_name: str = default_name
else: else:
default_name = "wallet.dat" default_name: str = "wallet.dat"
use_name: str = (
"wallet.dat"
if coin_id in (Coins.NAV, Coins.FIRO, Coins.DCR)
else "bsx_wallet"
)
if coin_name == "litecoin": if coin_name == "litecoin":
set_name: str = getWalletName( set_name: str = getWalletName(
@@ -2903,7 +2909,7 @@ def main():
if set_name != "mweb": if set_name != "mweb":
coin_settings["mweb_wallet_name"] = set_name coin_settings["mweb_wallet_name"] = set_name
set_name: str = getWalletName(coin_params, default_name) set_name: str = getWalletName(coin_params, use_name)
if set_name != default_name: if set_name != default_name:
coin_settings["wallet_name"] = set_name coin_settings["wallet_name"] = set_name

View File

@@ -566,7 +566,7 @@ def getCoinIdFromTicker(ticker: str) -> str:
raise ValueError(f"Unknown coin {ticker}") raise ValueError(f"Unknown coin {ticker}")
def getCoinIdFromName(name: str) -> str: def getCoinIdFromName(name: str) -> Coins:
try: try:
return name_map[name.lower()] return name_map[name.lower()]
except Exception: except Exception:

View File

@@ -772,12 +772,8 @@ class NetworkPortal(Table):
created_at = Column("integer") created_at = Column("integer")
def extract_schema(extra_tables: list = None) -> dict: def extract_schema(input_globals: dict = None) -> dict:
g = globals().copy() g = (input_globals if input_globals else globals()).copy()
if extra_tables:
for table_class in extra_tables:
g[table_class.__name__] = table_class
tables = {} tables = {}
for name, obj in g.items(): for name, obj in g.items():
@@ -898,18 +894,21 @@ def create_table(c, table_name, table) -> None:
c.execute(query) c.execute(query)
def create_db_(con, log, extra_tables: list = None) -> None: def create_db_(con, log) -> None:
db_schema = extract_schema(extra_tables=extra_tables) from .db_wallet import extract_wallet_schema
db_schema = extract_schema()
db_schema.update(extract_wallet_schema())
c = con.cursor() c = con.cursor()
for table_name, table in db_schema.items(): for table_name, table in db_schema.items():
create_table(c, table_name, table) create_table(c, table_name, table)
def create_db(db_path: str, log, extra_tables: list = None) -> None: def create_db(db_path: str, log) -> None:
con = None con = None
try: try:
con = sqlite3.connect(db_path) con = sqlite3.connect(db_path)
create_db_(con, log, extra_tables=extra_tables) create_db_(con, log)
con.commit() con.commit()
finally: finally:
if con: if con:
@@ -1229,7 +1228,6 @@ class DBMethods:
values = {} values = {}
constraint_values = {} constraint_values = {}
set_columns = [] set_columns = []
for mc in inspect.getmembers(obj.__class__): for mc in inspect.getmembers(obj.__class__):
mc_name, mc_obj = mc mc_name, mc_obj = mc
if not hasattr(mc_obj, "__sqlite3_column__"): if not hasattr(mc_obj, "__sqlite3_column__"):

View File

@@ -18,14 +18,7 @@ from .db import (
extract_schema, extract_schema,
) )
from .db_wallet import ( from .db_wallet import extract_wallet_schema
WalletAddress,
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
)
from .basicswap_util import ( from .basicswap_util import (
BidStates, BidStates,
@@ -277,15 +270,8 @@ def upgradeDatabase(self, db_version: int):
), ),
] ]
wallet_tables = [ expect_schema = extract_schema()
WalletAddress, expect_schema.update(extract_wallet_schema())
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
]
expect_schema = extract_schema(extra_tables=wallet_tables)
have_tables = {} have_tables = {}
try: try:
cursor = self.openDB() cursor = self.openDB()

View File

@@ -5,7 +5,7 @@
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
from .db import Column, Index, Table, UniqueConstraint from .db import Column, Index, Table, UniqueConstraint, extract_schema
class WalletAddress(Table): class WalletAddress(Table):
@@ -120,3 +120,7 @@ class WalletPendingTx(Table):
__unique_1__ = UniqueConstraint("coin_type", "txid") __unique_1__ = UniqueConstraint("coin_type", "txid")
__index_pending_coin__ = Index("idx_pending_coin", "coin_type", "confirmed_at") __index_pending_coin__ = Index("idx_pending_coin", "coin_type", "confirmed_at")
def extract_wallet_schema() -> dict:
return extract_schema(input_globals=globals())

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 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.
@@ -10,7 +10,6 @@ from basicswap.contrib.test_framework.messages import COutPoint, CTransaction, C
from basicswap.util import b2i, ensure, i2b from basicswap.util import b2i, ensure, i2b
from basicswap.util.script import decodePushData, decodeScriptNum from basicswap.util.script import decodePushData, decodeScriptNum
from .btc import BTCInterface, ensure_op, findOutput from .btc import BTCInterface, ensure_op, findOutput
from basicswap.rpc import make_rpc_func
from basicswap.chainparams import Coins from basicswap.chainparams import Coins
from basicswap.interface.contrib.bch_test_framework.cashaddress import Address from basicswap.interface.contrib.bch_test_framework.cashaddress import Address
from basicswap.util.crypto import hash160, sha256 from basicswap.util.crypto import hash160, sha256
@@ -74,12 +73,7 @@ class BCHInterface(BTCInterface):
def __init__(self, coin_settings, network, swap_client=None): def __init__(self, coin_settings, network, swap_client=None):
super(BCHInterface, self).__init__(coin_settings, network, swap_client) super(BCHInterface, self).__init__(coin_settings, network, swap_client)
# No multiwallet support
self.swap_client = swap_client self.swap_client = swap_client
self.rpc_wallet = make_rpc_func(
self._rpcport, self._rpcauth, host=self._rpc_host
)
self.rpc_wallet_watch = self.rpc_wallet
def has_segwit(self) -> bool: def has_segwit(self) -> bool:
# bch does not have segwit, but we return true here to avoid extra checks in basicswap.py # bch does not have segwit, but we return true here to avoid extra checks in basicswap.py

View File

@@ -7,6 +7,7 @@
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import base64 import base64
import copy
import hashlib import hashlib
import json import json
import logging import logging
@@ -381,7 +382,7 @@ class BTCInterface(Secp256k1Interface):
if self._rpc_wallet not in wallets: if self._rpc_wallet not in wallets:
self._log.debug( self._log.debug(
f"Wallet: {self._rpc_wallet} not active, attempting to load." f'{self.ticker()} wallet: "{self._rpc_wallet}" not active, attempting to load.'
) )
try: try:
self.rpc( self.rpc(
@@ -425,32 +426,43 @@ class BTCInterface(Secp256k1Interface):
except Exception as create_e: except Exception as create_e:
self._log.error(f"Error creating wallet: {create_e}") self._log.error(f"Error creating wallet: {create_e}")
if (
self._rpc_wallet_watch != self._rpc_wallet
and self._rpc_wallet_watch not in wallets
):
self._log.debug(
f'{self.ticker()} watchonly wallet: "{self._rpc_wallet_watch}" not active, attempting to load.'
)
try:
self.rpc(
"loadwallet",
[
self._rpc_wallet_watch,
],
)
wallets = self.rpc("listwallets")
except Exception as e:
self._log.debug(
f'Error loading {self.ticker()} watchonly wallet "{self._rpc_wallet_watch}": {e}.'
)
# Wallet name is "" for some LTC and PART installs on older cores # Wallet name is "" for some LTC and PART installs on older cores
if self._rpc_wallet not in wallets and len(wallets) > 0: if self._rpc_wallet not in wallets and len(wallets) > 0:
self._log.warning(f"Changing {self.ticker()} wallet name.") if "" in wallets:
for wallet_name in wallets: self._log.warning(
# Skip over other expected wallets f"Nameless {self.ticker()} wallet found."
if wallet_name in ("mweb",): + '\nPlease set the "wallet_name" coin setting to "" or recreate the wallet'
continue
change_watchonly_wallet: bool = (
self._rpc_wallet_watch == self._rpc_wallet
) )
# backupwallet and restorewallet with name should work.
self._rpc_wallet = wallet_name if self._rpc_wallet not in wallets:
self._log.info( raise RuntimeError(
f"Switched {self.ticker()} wallet name to {self._rpc_wallet}." f'{self.ticker()} wallet "{self._rpc_wallet}" not active'
) )
self.rpc_wallet = make_rpc_func( if self._rpc_wallet_watch not in wallets:
self._rpcport, raise RuntimeError(
self._rpcauth, f'{self.ticker()} watchonly wallet "{self._rpc_wallet_watch}" not active'
host=self._rpc_host,
wallet=self._rpc_wallet,
) )
if change_watchonly_wallet:
self.rpc_wallet_watch = self.rpc_wallet
break
return len(wallets) return len(wallets)
def testDaemonRPC(self, with_wallet=True) -> None: def testDaemonRPC(self, with_wallet=True) -> None:
@@ -530,6 +542,16 @@ class BTCInterface(Secp256k1Interface):
) )
return self.rpc("getblockheader", [block_hash]) return self.rpc("getblockheader", [block_hash])
def getPrevBlockInChain(self, block_header_in):
block_header = copy.deeocopy(block_header_in)
while True:
previousblockhash = block_header.get("previousblockhash", None)
if previousblockhash is None:
raise RuntimeError("previousblockhash not in block_header")
if block_header["confirmations"] > 0:
return block_header
block_header = self.rpc("getblockheader", [previousblockhash])
def getBlockHeaderAt(self, time_target: int, block_after=False): def getBlockHeaderAt(self, time_target: int, block_after=False):
blockchaininfo = self.rpc("getblockchaininfo") blockchaininfo = self.rpc("getblockchaininfo")
last_block_header = self.rpc( last_block_header = self.rpc(
@@ -1310,7 +1332,7 @@ class BTCInterface(Secp256k1Interface):
vkbv=None, vkbv=None,
kbsf=None, kbsf=None,
): ):
# lock refund swipe tx # Lock refund swipe tx
# Sends the coinA locked coin to the follower # Sends the coinA locked coin to the follower
tx_lock_refund = self.loadTx(tx_lock_refund_bytes) tx_lock_refund = self.loadTx(tx_lock_refund_bytes)
@@ -1584,7 +1606,7 @@ class BTCInterface(Secp256k1Interface):
) )
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return txid, locked_coin, locked_n return txid, locked_coin, locked_n
@@ -1647,7 +1669,7 @@ class BTCInterface(Secp256k1Interface):
) )
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return True return True
@@ -1706,7 +1728,7 @@ class BTCInterface(Secp256k1Interface):
) )
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return True return True

View File

@@ -1403,7 +1403,7 @@ class DCRInterface(Secp256k1Interface):
) )
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return True return True
@@ -1472,7 +1472,7 @@ class DCRInterface(Secp256k1Interface):
) )
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return txid, locked_coin, locked_n return txid, locked_coin, locked_n
@@ -1533,7 +1533,7 @@ class DCRInterface(Secp256k1Interface):
) )
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return True return True

View File

@@ -658,7 +658,7 @@ class PARTInterfaceBlind(PARTInterface):
ensure( ensure(
self.compareFeeRates(fee_rate_paid, feerate), self.compareFeeRates(fee_rate_paid, feerate),
"Bad fee rate, expected: {}".format(feerate), f"Bad fee rate, expected: {feerate}",
) )
return ( return (
@@ -734,7 +734,7 @@ class PARTInterfaceBlind(PARTInterface):
fee_rate_paid = fee_paid * 1000 // vsize fee_rate_paid = fee_paid * 1000 // vsize
ensure( ensure(
self.compareFeeRates(fee_rate_paid, feerate), self.compareFeeRates(fee_rate_paid, feerate),
"Bad fee rate, expected: {}".format(feerate), f"Bad fee rate, expected: {feerate}",
) )
return True return True
@@ -958,7 +958,7 @@ class PARTInterfaceBlind(PARTInterface):
fee_rate_paid = fee_paid * 1000 // vsize fee_rate_paid = fee_paid * 1000 // vsize
self._log.info("vsize, feerate: %ld, %ld", vsize, fee_rate_paid) self._log.info("vsize, feerate: %ld, %ld", vsize, fee_rate_paid)
if not self.compareFeeRates(fee_rate_paid, feerate): if not self.compareFeeRates(fee_rate_paid, feerate):
raise ValueError("Bad fee rate, expected: {}".format(feerate)) raise ValueError(f"Bad fee rate, expected: {feerate}")
return True return True

View File

@@ -45,3 +45,21 @@ class BSXLogger(logging.Logger):
def info_s(self, msg, *args, **kwargs): def info_s(self, msg, *args, **kwargs):
if self.safe_logs is False: if self.safe_logs is False:
self.info(msg, *args, **kwargs) self.info(msg, *args, **kwargs)
class BSXLogAdapter(logging.LoggerAdapter):
def __init__(self, logger, prefix):
super().__init__(logger, {})
self.prefix = prefix
def process(self, msg, kwargs):
return f"{self.prefix} {msg}", kwargs
def addr(self, addr: str) -> str:
return self.logger.addr(addr)
def id(self, concept_id: bytes, prefix: str = "") -> str:
return self.logger.id(concept_id, prefix)
def info_s(self, msg, *args, **kwargs):
return self.logger.info_s(msg, *args, **kwargs)

View File

@@ -95,7 +95,7 @@ def prepareDataDir(
fp.write("fallbackfee=0.01\n") fp.write("fallbackfee=0.01\n")
fp.write("acceptnonstdtxn=0\n") fp.write("acceptnonstdtxn=0\n")
fp.write("txindex=1\n") fp.write("txindex=1\n")
fp.write("wallet=wallet.dat\n") fp.write("wallet=bsx_wallet\n")
fp.write("findpeers=0\n") fp.write("findpeers=0\n")
@@ -290,7 +290,7 @@ def wait_for_event(
def wait_for_offer(delay_event, swap_client, offer_id, wait_for=20): def wait_for_offer(delay_event, swap_client, offer_id, wait_for=20):
logging.info("wait_for_offer %s", offer_id.hex()) logging.info(f"wait_for_offer {offer_id.hex()}")
for i in range(wait_for): for i in range(wait_for):
if delay_event.is_set(): if delay_event.is_set():
raise ValueError("Test stopped.") raise ValueError("Test stopped.")

View File

@@ -112,7 +112,7 @@ def prepareOtherDir(datadir, nodeId, conf_file="dash.conf"):
fp.write("acceptnonstdtxn=0\n") fp.write("acceptnonstdtxn=0\n")
if conf_file == "bitcoin.conf": if conf_file == "bitcoin.conf":
fp.write("wallet=wallet.dat\n") fp.write("wallet=bsx_wallet\n")
def prepareDir(datadir, nodeId, network_key, network_pubkey): def prepareDir(datadir, nodeId, network_key, network_pubkey):
@@ -137,7 +137,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
fp.write("debug=1\n") fp.write("debug=1\n")
fp.write("debugexclude=libevent\n") fp.write("debugexclude=libevent\n")
fp.write("zmqpubsmsg=tcp://127.0.0.1:" + str(BASE_ZMQ_PORT + nodeId) + "\n") fp.write("zmqpubsmsg=tcp://127.0.0.1:" + str(BASE_ZMQ_PORT + nodeId) + "\n")
fp.write("wallet=wallet.dat\n") fp.write("wallet=bsx_wallet\n")
fp.write("fallbackfee=0.01\n") fp.write("fallbackfee=0.01\n")
fp.write("acceptnonstdtxn=0\n") fp.write("acceptnonstdtxn=0\n")
@@ -313,7 +313,7 @@ class Test(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
btc_data_dir, btc_data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
"bitcoin-wallet", "bitcoin-wallet",
) )
except Exception: except Exception:
@@ -321,7 +321,7 @@ class Test(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
btc_data_dir, btc_data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
"bitcoin-wallet", "bitcoin-wallet",
) )
cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND)) cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND))
@@ -333,7 +333,7 @@ class Test(unittest.TestCase):
if os.path.exists(os.path.join(DASH_BINDIR, 'dash-wallet')): if os.path.exists(os.path.join(DASH_BINDIR, 'dash-wallet')):
logging.info('Creating DASH wallet.') logging.info('Creating DASH wallet.')
callrpc_cli(DASH_BINDIR, dash_data_dir, 'regtest', '-wallet=wallet.dat create', 'dash-wallet') callrpc_cli(DASH_BINDIR, dash_data_dir, 'regtest', '-wallet=bsx_wallet create', 'dash-wallet')
""" """
cls.daemons.append(startDaemon(dash_data_dir, DASH_BINDIR, DASHD)) cls.daemons.append(startDaemon(dash_data_dir, DASH_BINDIR, DASHD))
logging.info("Started %s %d", DASHD, cls.daemons[-1].handle.pid) logging.info("Started %s %d", DASHD, cls.daemons[-1].handle.pid)
@@ -346,7 +346,7 @@ class Test(unittest.TestCase):
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
"particl-wallet", "particl-wallet",
) )
except Exception: except Exception:
@@ -354,7 +354,7 @@ class Test(unittest.TestCase):
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
"particl-wallet", "particl-wallet",
) )
cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD)) cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD))
@@ -410,7 +410,7 @@ class Test(unittest.TestCase):
waitForRPC(dashRpc, delay_event, rpc_command="getblockchaininfo") waitForRPC(dashRpc, delay_event, rpc_command="getblockchaininfo")
if len(dashRpc("listwallets")) < 1: if len(dashRpc("listwallets")) < 1:
dashRpc("createwallet wallet.dat") dashRpc("createwallet wbsx_wallet")
sc.start() sc.start()

View File

@@ -141,7 +141,7 @@ class Test(TestFunctions):
dogeRpc = make_rpc_func(i, base_rpc_port=DOGE_BASE_RPC_PORT) dogeRpc = make_rpc_func(i, base_rpc_port=DOGE_BASE_RPC_PORT)
waitForRPC(dogeRpc, test_delay_event, rpc_command="getblockchaininfo") waitForRPC(dogeRpc, test_delay_event, rpc_command="getblockchaininfo")
if len(dogeRpc("listwallets")) < 1: if len(dogeRpc("listwallets")) < 1:
dogeRpc("createwallet", ["wallet.dat", False, True, "", False, False]) dogeRpc("createwallet", ["bsx_wallet", False, True, "", False, False])
wif_prefix: int = 239 wif_prefix: int = 239
wif = toWIF(wif_prefix, bytes.fromhex(cls.doge_seeds[i]), False) wif = toWIF(wif_prefix, bytes.fromhex(cls.doge_seeds[i]), False)
dogeRpc("sethdseed", [True, wif]) dogeRpc("sethdseed", [True, wif])

View File

@@ -160,7 +160,7 @@ class Test(BaseTest):
FIRO_BINDIR, FIRO_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
"firo-wallet", "firo-wallet",
) )

View File

@@ -216,7 +216,7 @@ class Test(unittest.TestCase):
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
"particl-wallet", "particl-wallet",
) )
@@ -286,7 +286,7 @@ class Test(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
"bitcoin-wallet", "bitcoin-wallet",
) )

View File

@@ -161,7 +161,7 @@ class TestNMC(BasicSwapTest):
if len(nmc_rpc("listwallets")) < 1: if len(nmc_rpc("listwallets")) < 1:
nmc_rpc( nmc_rpc(
"createwallet", "createwallet",
["wallet.dat", False, True, "", False, NMC_USE_DESCRIPTORS], ["bsx_wallet", False, True, "", False, NMC_USE_DESCRIPTORS],
) )
if NMC_USE_DESCRIPTORS: if NMC_USE_DESCRIPTORS:
nmc_rpc( nmc_rpc(

View File

@@ -118,7 +118,7 @@ def prepareOtherDir(datadir, nodeId, conf_file="pivx.conf"):
fp.write(f"paramsdir={params_dir}\n") fp.write(f"paramsdir={params_dir}\n")
if conf_file == "bitcoin.conf": if conf_file == "bitcoin.conf":
fp.write("wallet=wallet.dat\n") fp.write("wallet=bsx_wallet\n")
def prepareDir(datadir, nodeId, network_key, network_pubkey): def prepareDir(datadir, nodeId, network_key, network_pubkey):
@@ -143,7 +143,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
fp.write("debug=1\n") fp.write("debug=1\n")
fp.write("debugexclude=libevent\n") fp.write("debugexclude=libevent\n")
fp.write("zmqpubsmsg=tcp://127.0.0.1:" + str(BASE_ZMQ_PORT + nodeId) + "\n") fp.write("zmqpubsmsg=tcp://127.0.0.1:" + str(BASE_ZMQ_PORT + nodeId) + "\n")
fp.write("wallet=wallet.dat\n") fp.write("wallet=bsx_wallet\n")
fp.write("fallbackfee=0.01\n") fp.write("fallbackfee=0.01\n")
fp.write("acceptnonstdtxn=0\n") fp.write("acceptnonstdtxn=0\n")
@@ -324,7 +324,7 @@ class Test(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
btc_data_dir, btc_data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
"bitcoin-wallet", "bitcoin-wallet",
) )
except Exception: except Exception:
@@ -332,7 +332,7 @@ class Test(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
btc_data_dir, btc_data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
"bitcoin-wallet", "bitcoin-wallet",
) )
cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND)) cls.daemons.append(startDaemon(btc_data_dir, cfg.BITCOIN_BINDIR, cfg.BITCOIND))
@@ -352,7 +352,7 @@ class Test(unittest.TestCase):
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
"particl-wallet", "particl-wallet",
) )
except Exception: except Exception:
@@ -360,7 +360,7 @@ class Test(unittest.TestCase):
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
"particl-wallet", "particl-wallet",
) )
cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD)) cls.daemons.append(startDaemon(data_dir, cfg.PARTICL_BINDIR, cfg.PARTICLD))

View File

@@ -313,7 +313,7 @@ class Test(unittest.TestCase):
ltc_datadir = os.path.join(test_path, "litecoin") ltc_datadir = os.path.join(test_path, "litecoin")
rv = json.loads( rv = json.loads(
callcoincli( callcoincli(
ltc_cli_path, ltc_datadir, "getwalletinfo", wallet="wallet.dat" ltc_cli_path, ltc_datadir, "getwalletinfo", wallet="bsx_wallet"
) )
) )
assert "unlocked_until" in rv assert "unlocked_until" in rv
@@ -474,7 +474,7 @@ class Test(unittest.TestCase):
ltc_datadir = os.path.join(test_path, "litecoin") ltc_datadir = os.path.join(test_path, "litecoin")
rv = json.loads( rv = json.loads(
callcoincli( callcoincli(
ltc_cli_path, ltc_datadir, "getwalletinfo", wallet="wallet.dat" ltc_cli_path, ltc_datadir, "getwalletinfo", wallet="bsx_wallet"
) )
) )
assert "unlocked_until" in rv assert "unlocked_until" in rv
@@ -653,7 +653,7 @@ class Test(unittest.TestCase):
logging.info("Check both LTC wallets are encrypted and mweb seeds match.") logging.info("Check both LTC wallets are encrypted and mweb seeds match.")
rv = json.loads( rv = json.loads(
callcoincli( callcoincli(
ltc_cli_path, ltc_datadir, "getwalletinfo", wallet="wallet.dat" ltc_cli_path, ltc_datadir, "getwalletinfo", wallet="bsx_wallet"
) )
) )
assert "unlocked_until" in rv assert "unlocked_until" in rv
@@ -769,7 +769,7 @@ class Test(unittest.TestCase):
) )
walletdir = os.path.join(test_path, "regtest", "wallets", "bdb_wallet") walletdir = os.path.join(test_path, "regtest", "wallets", "bdb_wallet")
walletpath = os.path.join(walletdir, "wallet.dat") walletpath = os.path.join(walletdir, "bsx_wallet")
db = berkeleydb.db.DB() db = berkeleydb.db.DB()
db.open( db.open(
@@ -812,10 +812,10 @@ class Test(unittest.TestCase):
], ],
) )
bkp_path = os.path.join(walletdir, "wallet.dat" + ".bkp") bkp_path = os.path.join(walletdir, "bsx_wallet" + ".bkp")
for i in range(1000): for i in range(1000):
if os.path.exists(bkp_path): if os.path.exists(bkp_path):
bkp_path = os.path.join(walletdir, "wallet.dat" + f".bkp{i}") bkp_path = os.path.join(walletdir, "bsx_wallet" + f".bkp{i}")
assert os.path.exists(bkp_path) is False assert os.path.exists(bkp_path) is False
if os.path.isfile(walletpath): if os.path.isfile(walletpath):
@@ -940,7 +940,7 @@ class Test(unittest.TestCase):
) )
logging.info(f"Looking for hdchain for {seedid_bytes.hex()}") logging.info(f"Looking for hdchain for {seedid_bytes.hex()}")
walletdir = os.path.join(test_path, "regtest", "wallets", "bdb_wallet2") walletdir = os.path.join(test_path, "regtest", "wallets", "bdb_wallet2")
walletpath = os.path.join(walletdir, "wallet.dat") walletpath = os.path.join(walletdir, "bsx_wallet")
found_hdchain = False found_hdchain = False
max_key_count = 4000000 # arbitrary max_key_count = 4000000 # arbitrary
with open(walletpath, "rb") as fp: with open(walletpath, "rb") as fp:
@@ -1134,7 +1134,7 @@ class Test(unittest.TestCase):
) )
walletdir = os.path.join(test_path, "regtest", "wallets", "descr_wallet") walletdir = os.path.join(test_path, "regtest", "wallets", "descr_wallet")
walletpath = os.path.join(walletdir, "wallet.dat") walletpath = os.path.join(walletdir, "bsx_wallet")
orig_active_descriptors = [] orig_active_descriptors = []
with sqlite3.connect(walletpath) as conn: with sqlite3.connect(walletpath) as conn:
@@ -1234,10 +1234,10 @@ class Test(unittest.TestCase):
"descr_wallet", "descr_wallet",
], ],
) )
bkp_path = os.path.join(walletdir, "wallet.dat" + ".bkp") bkp_path = os.path.join(walletdir, "bsx_wallet" + ".bkp")
for i in range(1000): for i in range(1000):
if os.path.exists(bkp_path): if os.path.exists(bkp_path):
bkp_path = os.path.join(walletdir, "wallet.dat" + f".bkp{i}") bkp_path = os.path.join(walletdir, "bsx_wallet" + f".bkp{i}")
assert os.path.exists(bkp_path) is False assert os.path.exists(bkp_path) is False
if os.path.isfile(walletpath): if os.path.isfile(walletpath):

View File

@@ -154,7 +154,7 @@ class Test(TestBase):
num_blocks = 431 num_blocks = 431
self.ltc_addr = callltcnoderpc( self.ltc_addr = callltcnoderpc(
1, "getnewaddress", ["mining_addr", "bech32"], wallet="wallet.dat" 1, "getnewaddress", ["mining_addr", "bech32"], wallet="bsx_wallet"
) )
logging.info("Mining %d Litecoin blocks to %s", num_blocks, self.ltc_addr) logging.info("Mining %d Litecoin blocks to %s", num_blocks, self.ltc_addr)
callltcnoderpc(1, "generatetoaddress", [num_blocks, self.ltc_addr]) callltcnoderpc(1, "generatetoaddress", [num_blocks, self.ltc_addr])
@@ -162,7 +162,7 @@ class Test(TestBase):
mweb_addr = callltcnoderpc( mweb_addr = callltcnoderpc(
1, "getnewaddress", ["mweb_addr", "mweb"], wallet="mweb" 1, "getnewaddress", ["mweb_addr", "mweb"], wallet="mweb"
) )
callltcnoderpc(1, "sendtoaddress", [mweb_addr, 1], wallet="wallet.dat") callltcnoderpc(1, "sendtoaddress", [mweb_addr, 1], wallet="bsx_wallet")
num_blocks = 69 num_blocks = 69
callltcnoderpc(1, "generatetoaddress", [num_blocks, self.ltc_addr]) callltcnoderpc(1, "generatetoaddress", [num_blocks, self.ltc_addr])

View File

@@ -124,7 +124,7 @@ def callbtcrpc(
node_id, node_id,
method, method,
params=[], params=[],
wallet="wallet.dat", wallet="bsx_wallet",
base_rpc_port=BITCOIN_RPC_PORT_BASE + PORT_OFS, base_rpc_port=BITCOIN_RPC_PORT_BASE + PORT_OFS,
): ):
auth = "test_btc_{0}:test_btc_pwd_{0}".format(node_id) auth = "test_btc_{0}:test_btc_pwd_{0}".format(node_id)
@@ -153,7 +153,7 @@ def callnmcrpc(
node_id, node_id,
method, method,
params=[], params=[],
wallet="wallet.dat", wallet="bsx_wallet",
base_rpc_port=NAMECOIN_RPC_PORT_BASE + PORT_OFS, base_rpc_port=NAMECOIN_RPC_PORT_BASE + PORT_OFS,
): ):
auth = "test_nmc_{0}:test_nmc_pwd_{0}".format(node_id) auth = "test_nmc_{0}:test_nmc_pwd_{0}".format(node_id)
@@ -336,7 +336,7 @@ def start_processes(self):
if "litecoin" in self.test_coins_list: if "litecoin" in self.test_coins_list:
self.ltc_addr = callltcrpc( self.ltc_addr = callltcrpc(
0, "getnewaddress", ["mining_addr"], wallet="wallet.dat" 0, "getnewaddress", ["mining_addr"], wallet="bsx_wallet"
) )
num_blocks: int = 431 num_blocks: int = 431
have_blocks: int = callltcrpc(0, "getblockcount") have_blocks: int = callltcrpc(0, "getblockcount")
@@ -346,7 +346,7 @@ def start_processes(self):
0, 0,
"generatetoaddress", "generatetoaddress",
[num_blocks - have_blocks, self.ltc_addr], [num_blocks - have_blocks, self.ltc_addr],
wallet="wallet.dat", wallet="bsx_wallet",
) )
# https://github.com/litecoin-project/litecoin/issues/807 # https://github.com/litecoin-project/litecoin/issues/807
@@ -354,7 +354,7 @@ def start_processes(self):
mweb_addr = callltcrpc( mweb_addr = callltcrpc(
0, "getnewaddress", ["mweb_addr", "mweb"], wallet="mweb" 0, "getnewaddress", ["mweb_addr", "mweb"], wallet="mweb"
) )
callltcrpc(0, "sendtoaddress", [mweb_addr, 1.0], wallet="wallet.dat") callltcrpc(0, "sendtoaddress", [mweb_addr, 1.0], wallet="bsx_wallet")
num_blocks = 69 num_blocks = 69
have_blocks: int = callltcrpc(0, "getblockcount") have_blocks: int = callltcrpc(0, "getblockcount")
@@ -362,7 +362,7 @@ def start_processes(self):
0, 0,
"generatetoaddress", "generatetoaddress",
[500 - have_blocks, self.ltc_addr], [500 - have_blocks, self.ltc_addr],
wallet="wallet.dat", wallet="bsx_wallet",
) )
if "decred" in self.test_coins_list: if "decred" in self.test_coins_list:
@@ -413,7 +413,7 @@ def start_processes(self):
if "bitcoincash" in self.test_coins_list: if "bitcoincash" in self.test_coins_list:
self.bch_addr = callbchrpc( self.bch_addr = callbchrpc(
0, "getnewaddress", ["mining_addr"], wallet="wallet.dat" 0, "getnewaddress", ["mining_addr"], wallet="bsx_wallet"
) )
num_blocks: int = 200 num_blocks: int = 200
have_blocks: int = callbchrpc(0, "getblockcount") have_blocks: int = callbchrpc(0, "getblockcount")
@@ -427,7 +427,7 @@ def start_processes(self):
0, 0,
"generatetoaddress", "generatetoaddress",
[num_blocks - have_blocks, self.bch_addr], [num_blocks - have_blocks, self.bch_addr],
wallet="wallet.dat", wallet="bsx_wallet",
) )
if "dogecoin" in self.test_coins_list: if "dogecoin" in self.test_coins_list:

View File

@@ -144,7 +144,7 @@ class TestBCH(BasicSwapTest):
BITCOINCASH_BINDIR, BITCOINCASH_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
bch_wallet_bin, bch_wallet_bin,
) )
except Exception as e: except Exception as e:
@@ -172,7 +172,7 @@ class TestBCH(BasicSwapTest):
"getnewaddress", "getnewaddress",
["mining_addr"], ["mining_addr"],
base_rpc_port=BCH_BASE_RPC_PORT, base_rpc_port=BCH_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
if not cls.restore_instance: if not cls.restore_instance:
num_blocks: int = 200 num_blocks: int = 200
@@ -182,7 +182,7 @@ class TestBCH(BasicSwapTest):
"generatetoaddress", "generatetoaddress",
[num_blocks, cls.bch_addr], [num_blocks, cls.bch_addr],
base_rpc_port=BCH_BASE_RPC_PORT, base_rpc_port=BCH_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
@classmethod @classmethod

View File

@@ -1999,7 +1999,7 @@ class BasicSwapTest(TestFunctions):
assert addr1_info[key_id_field] == addr_int1_info[key_id_field] assert addr1_info[key_id_field] == addr_int1_info[key_id_field]
assert original_seed_id == after_seed_id assert original_seed_id == after_seed_id
finally: finally:
ci.setActiveWallet("wallet.dat") ci.setActiveWallet("bsx_wallet")
chain_client_settings["manage_daemon"] = False chain_client_settings["manage_daemon"] = False
def test_015_changetype(self): def test_015_changetype(self):

View File

@@ -229,22 +229,24 @@ class Test(unittest.TestCase):
== "0dde9df8660d3e0f28fe00d648b70e0323e9c192fe9b94f1cf7138515e877725" == "0dde9df8660d3e0f28fe00d648b70e0323e9c192fe9b94f1cf7138515e877725"
) )
sum_secp256k1 = ci_btc.sumPubkeys( pk_secp256k1 = ci_btc.sumPubkeys(
ci_btc.getPubkey(keys[0]), ci_btc.getPubkey(keys[1]) ci_btc.getPubkey(keys[0]), ci_btc.getPubkey(keys[1])
) )
assert ( assert (
sum_secp256k1.hex() pk_secp256k1.hex()
== "028c30392e35620af0787b363a03cf9a695336759664436e1f609481c869541a5c" == "028c30392e35620af0787b363a03cf9a695336759664436e1f609481c869541a5c"
) )
sum_ed25519 = ci_xmr.sumPubkeys( pk_ed25519 = ci_xmr.sumPubkeys(
ci_xmr.getPubkey(keys[0]), ci_xmr.getPubkey(keys[1]) ci_xmr.getPubkey(keys[0]), ci_xmr.getPubkey(keys[1])
) )
assert ( assert (
sum_ed25519.hex() pk_ed25519.hex()
== "4b2dd2dc9acc9be7efed4fdbfb96f0002aeb9e4c8638c5b24562a7158b283626" == "4b2dd2dc9acc9be7efed4fdbfb96f0002aeb9e4c8638c5b24562a7158b283626"
) )
assert pk_secp256k1 == ci_btc.getPubkey(sum_secp256k1)
def test_ecdsa_otves(self): def test_ecdsa_otves(self):
ci = self.ci_btc() ci = self.ci_btc()
vk_sign = ci.getNewRandomKey() vk_sign = ci.getNewRandomKey()

View File

@@ -88,7 +88,7 @@ class Test(BaseTest):
"getnewaddress", "getnewaddress",
["initial funds", "bech32"], ["initial funds", "bech32"],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
callnoderpc( callnoderpc(
@@ -99,7 +99,7 @@ class Test(BaseTest):
"sendtoaddress", "sendtoaddress",
[ltc_addr1, 1000], [ltc_addr1, 1000],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
wait_for_balance( wait_for_balance(
@@ -975,7 +975,7 @@ class Test(BaseTest):
"getnewaddress", "getnewaddress",
["Withdrawal test", "legacy"], ["Withdrawal test", "legacy"],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
wallets0 = read_json_api(TEST_HTTP_PORT + 0, "wallets") wallets0 = read_json_api(TEST_HTTP_PORT + 0, "wallets")
assert float(wallets0["LTC"]["balance"]) > 100 assert float(wallets0["LTC"]["balance"]) > 100

View File

@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2020-2024 tecnovert # Copyright (c) 2020-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.
@@ -164,6 +164,7 @@ def prepare_swapclient_dir(
"bindir": cfg.PARTICL_BINDIR, "bindir": cfg.PARTICL_BINDIR,
"blocks_confirmed": 2, # Faster testing "blocks_confirmed": 2, # Faster testing
"anon_tx_ring_size": 5, # Faster testing "anon_tx_ring_size": 5, # Faster testing
"wallet_name": "bsx_wallet",
}, },
"bitcoin": { "bitcoin": {
"connection_type": "rpc", "connection_type": "rpc",
@@ -176,6 +177,7 @@ def prepare_swapclient_dir(
"use_segwit": True, "use_segwit": True,
"use_descriptors": BTC_USE_DESCRIPTORS, "use_descriptors": BTC_USE_DESCRIPTORS,
"use_legacy_key_paths": BTC_USE_LEGACY_KEY_PATHS, "use_legacy_key_paths": BTC_USE_LEGACY_KEY_PATHS,
"wallet_name": "bsx_wallet",
}, },
}, },
"check_progress_seconds": 2, "check_progress_seconds": 2,
@@ -263,9 +265,7 @@ def waitForXMRNode(rpc_offset, max_tries=7):
except Exception as ex: except Exception as ex:
if i < max_tries: if i < max_tries:
logging.warning( logging.warning(
"Can't connect to XMR RPC: %s. Retrying in %d second/s.", f"Can't connect to XMR RPC: {ex}. Retrying in {i + 1} second/s."
str(ex),
(i + 1),
) )
time.sleep(i + 1) time.sleep(i + 1)
raise ValueError("waitForXMRNode failed") raise ValueError("waitForXMRNode failed")
@@ -281,9 +281,7 @@ def waitForXMRWallet(rpc_offset, auth, max_tries=7):
except Exception as ex: except Exception as ex:
if i < max_tries: if i < max_tries:
logging.warning( logging.warning(
"Can't connect to XMR wallet RPC: %s. Retrying in %d second/s.", f"Can't connect to XMR wallet RPC: {ex}. Retrying in {i + 1} second/s."
str(ex),
(i + 1),
) )
time.sleep(i + 1) time.sleep(i + 1)
raise ValueError("waitForXMRWallet failed") raise ValueError("waitForXMRWallet failed")
@@ -304,7 +302,7 @@ def run_coins_loop(cls):
cls.coins_loop() cls.coins_loop()
except Exception as e: except Exception as e:
logging.warning("run_coins_loop " + str(e)) logging.warning("run_coins_loop " + str(e))
test_delay_event.wait(1.0) test_delay_event.wait(cls.coins_loop_delay)
def run_loop(cls): def run_loop(cls):
@@ -336,6 +334,7 @@ class BaseTest(unittest.TestCase):
xmr_addr = None xmr_addr = None
btc_addr = None btc_addr = None
ltc_addr = None ltc_addr = None
coins_loop_delay = 1.0
@classmethod @classmethod
def getRandomPubkey(cls): def getRandomPubkey(cls):
@@ -345,7 +344,7 @@ class BaseTest(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
if signal_event.is_set(): if signal_event.is_set():
raise ValueError("Test has been cancelled.") raise ValueError("Test has been cancelled")
test_delay_event.clear() test_delay_event.clear()
random.seed(time.time()) random.seed(time.time())
@@ -400,7 +399,7 @@ class BaseTest(unittest.TestCase):
cls.prepareTestDir() cls.prepareTestDir()
try: try:
logging.info("Preparing coin nodes.") logging.info("Preparing coin nodes")
part_wallet_bin = "particl-wallet" + (".exe" if os.name == "nt" else "") part_wallet_bin = "particl-wallet" + (".exe" if os.name == "nt" else "")
for i in range(NUM_NODES): for i in range(NUM_NODES):
if not cls.restore_instance: if not cls.restore_instance:
@@ -411,14 +410,14 @@ class BaseTest(unittest.TestCase):
part_wallet_bin, part_wallet_bin,
) )
): ):
logging.warning(f"{part_wallet_bin} not found.") logging.warning(f"{part_wallet_bin} not found")
else: else:
try: try:
callrpc_cli( callrpc_cli(
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
part_wallet_bin, part_wallet_bin,
) )
except Exception as e: except Exception as e:
@@ -429,7 +428,7 @@ class BaseTest(unittest.TestCase):
cfg.PARTICL_BINDIR, cfg.PARTICL_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
part_wallet_bin, part_wallet_bin,
) )
@@ -507,7 +506,7 @@ class BaseTest(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat -legacy create", "-wallet=bsx_wallet -legacy create",
btc_wallet_bin, btc_wallet_bin,
) )
except Exception as e: except Exception as e:
@@ -518,7 +517,7 @@ class BaseTest(unittest.TestCase):
cfg.BITCOIN_BINDIR, cfg.BITCOIN_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
btc_wallet_bin, btc_wallet_bin,
) )
@@ -540,7 +539,7 @@ class BaseTest(unittest.TestCase):
) )
# wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors # wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors
rpc_func( rpc_func(
"createwallet", ["wallet.dat", False, True, "", False, True] "createwallet", ["bsx_wallet", False, True, "", False, True]
) )
rpc_func("createwallet", ["bsx_watch", True, True, "", False, True]) rpc_func("createwallet", ["bsx_watch", True, True, "", False, True])
else: else:
@@ -570,7 +569,7 @@ class BaseTest(unittest.TestCase):
cfg.LITECOIN_BINDIR, cfg.LITECOIN_BINDIR,
data_dir, data_dir,
"regtest", "regtest",
"-wallet=wallet.dat create", "-wallet=bsx_wallet create",
ltc_wallet_bin, ltc_wallet_bin,
) )
@@ -623,10 +622,8 @@ class BaseTest(unittest.TestCase):
) )
for i in range(NUM_XMR_NODES): for i in range(NUM_XMR_NODES):
cls.xmr_wallet_auth.append( cls.xmr_wallet_auth.append((f"test{i}", f"test_pass{i}"))
("test{0}".format(i), "test_pass{0}".format(i)) logging.info(f"Creating XMR wallet {i}")
)
logging.info("Creating XMR wallet %i", i)
waitForXMRWallet(i, cls.xmr_wallet_auth[i]) waitForXMRWallet(i, cls.xmr_wallet_auth[i])
@@ -729,10 +726,10 @@ class BaseTest(unittest.TestCase):
"getnewaddress", "getnewaddress",
["mining_addr", "bech32"], ["mining_addr", "bech32"],
base_rpc_port=BTC_BASE_RPC_PORT, base_rpc_port=BTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
num_blocks = 400 # Mine enough to activate segwit num_blocks = 400 # Mine enough to activate segwit
logging.info("Mining %d Bitcoin blocks to %s", num_blocks, cls.btc_addr) logging.info(f"Mining {num_blocks} Bitcoin blocks to {cls.btc_addr}")
callnoderpc( callnoderpc(
0, 0,
"generatetoaddress", "generatetoaddress",
@@ -745,7 +742,7 @@ class BaseTest(unittest.TestCase):
"getnewaddress", "getnewaddress",
["initial addr"], ["initial addr"],
base_rpc_port=BTC_BASE_RPC_PORT, base_rpc_port=BTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
for i in range(5): for i in range(5):
callnoderpc( callnoderpc(
@@ -753,7 +750,7 @@ class BaseTest(unittest.TestCase):
"sendtoaddress", "sendtoaddress",
[btc_addr1, 100], [btc_addr1, 100],
base_rpc_port=BTC_BASE_RPC_PORT, base_rpc_port=BTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
# Switch addresses so wallet amounts stay constant # Switch addresses so wallet amounts stay constant
@@ -763,7 +760,7 @@ class BaseTest(unittest.TestCase):
.ci(Coins.BTC) .ci(Coins.BTC)
.pubkey_to_segwit_address(void_block_rewards_pubkey) .pubkey_to_segwit_address(void_block_rewards_pubkey)
) )
logging.info("Mining %d Bitcoin blocks to %s", num_blocks, cls.btc_addr) logging.info(f"Mining {num_blocks} Bitcoin blocks to {cls.btc_addr}")
callnoderpc( callnoderpc(
0, 0,
"generatetoaddress", "generatetoaddress",
@@ -798,17 +795,17 @@ class BaseTest(unittest.TestCase):
"getnewaddress", "getnewaddress",
["mining_addr", "bech32"], ["mining_addr", "bech32"],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
logging.info( logging.info(
"Mining %d Litecoin blocks to %s", num_blocks, cls.ltc_addr f"Mining {num_blocks} Litecoin blocks to {cls.ltc_addr}"
) )
callnoderpc( callnoderpc(
0, 0,
"generatetoaddress", "generatetoaddress",
[num_blocks, cls.ltc_addr], [num_blocks, cls.ltc_addr],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
num_blocks = 31 num_blocks = 31
@@ -825,7 +822,7 @@ class BaseTest(unittest.TestCase):
"generatetoaddress", "generatetoaddress",
[num_blocks, cls.ltc_addr], [num_blocks, cls.ltc_addr],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
# https://github.com/litecoin-project/litecoin/issues/807 # https://github.com/litecoin-project/litecoin/issues/807
@@ -835,14 +832,14 @@ class BaseTest(unittest.TestCase):
"getnewaddress", "getnewaddress",
["mweb_addr", "mweb"], ["mweb_addr", "mweb"],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
callnoderpc( callnoderpc(
0, 0,
"sendtoaddress", "sendtoaddress",
[mweb_addr, 1], [mweb_addr, 1],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
ltc_addr1 = callnoderpc( ltc_addr1 = callnoderpc(
@@ -850,7 +847,7 @@ class BaseTest(unittest.TestCase):
"getnewaddress", "getnewaddress",
["initial addr"], ["initial addr"],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
for i in range(5): for i in range(5):
callnoderpc( callnoderpc(
@@ -858,7 +855,7 @@ class BaseTest(unittest.TestCase):
"sendtoaddress", "sendtoaddress",
[ltc_addr1, 100], [ltc_addr1, 100],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
num_blocks = 69 num_blocks = 69
@@ -872,7 +869,7 @@ class BaseTest(unittest.TestCase):
"generatetoaddress", "generatetoaddress",
[num_blocks, cls.ltc_addr], [num_blocks, cls.ltc_addr],
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
checkForks( checkForks(
@@ -880,7 +877,7 @@ class BaseTest(unittest.TestCase):
0, 0,
"getblockchaininfo", "getblockchaininfo",
base_rpc_port=LTC_BASE_RPC_PORT, base_rpc_port=LTC_BASE_RPC_PORT,
wallet="wallet.dat", wallet="bsx_wallet",
) )
) )