mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 10:28:10 +01:00
Add check for minimum sqlite version.
This commit is contained in:
@@ -1023,6 +1023,12 @@ class BasicSwap(BaseApp):
|
||||
self.log.info(f"SQLite version: {sqlite3.sqlite_version}")
|
||||
self.log.debug(f"Timezone offset: {time.timezone} ({time.tzname[0]})")
|
||||
|
||||
MIN_SQLITE_VERSION = (3, 35, 0) # Upsert
|
||||
if sqlite3.sqlite_version_info < MIN_SQLITE_VERSION:
|
||||
raise RuntimeError(
|
||||
"SQLite {} or higher required.".format(".".join(MIN_SQLITE_VERSION))
|
||||
)
|
||||
|
||||
upgradeDatabase(self, self.db_version)
|
||||
upgradeDatabaseData(self, self.db_data_version)
|
||||
|
||||
|
||||
@@ -658,10 +658,7 @@ class CoinRates(Table):
|
||||
last_updated = Column("integer")
|
||||
|
||||
|
||||
def create_db(db_path: str, log) -> None:
|
||||
con = None
|
||||
try:
|
||||
con = sqlite3.connect(db_path)
|
||||
def create_db_(con, log) -> None:
|
||||
c = con.cursor()
|
||||
|
||||
g = globals().copy()
|
||||
@@ -734,6 +731,12 @@ def create_db(db_path: str, log) -> None:
|
||||
query += ")"
|
||||
c.execute(query)
|
||||
|
||||
|
||||
def create_db(db_path: str, log) -> None:
|
||||
con = None
|
||||
try:
|
||||
con = sqlite3.connect(db_path)
|
||||
create_db_(con, log)
|
||||
con.commit()
|
||||
finally:
|
||||
if con:
|
||||
|
||||
@@ -175,10 +175,12 @@ Close the terminal and open a new one to update the python symlinks.
|
||||
|
||||
### Basicswap
|
||||
|
||||
If installing on an older distro such as Debian 11 you may need to use a newer Python/SQLite version, see ["Use a Different Python Version" in notes.md](notes.md#Use-a-Different-Python-Version)
|
||||
|
||||
export SWAP_DATADIR=$HOME/coinswaps
|
||||
python3 -m venv "$SWAP_DATADIR/venv"
|
||||
. $SWAP_DATADIR/venv/bin/activate && python -V
|
||||
|
||||
. $SWAP_DATADIR/venv/bin/activate && python -V
|
||||
cd $SWAP_DATADIR
|
||||
git clone https://github.com/basicswap/basicswap.git
|
||||
cd $SWAP_DATADIR/basicswap
|
||||
|
||||
15
doc/notes.md
15
doc/notes.md
@@ -103,6 +103,21 @@ Test:
|
||||
basicswap-prepare.exe --help
|
||||
|
||||
|
||||
## Use a Different Python Version
|
||||
|
||||
[uv](https://github.com/astral-sh/uv) can create a virtual environment for a different version of Python (and consequently SQLite).
|
||||
|
||||
Run:
|
||||
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
source $HOME/.local/bin/env
|
||||
uv venv -p 3.10 "$SWAP_DATADIR/venv" --seed
|
||||
|
||||
Instead of:
|
||||
|
||||
python3 -m venv "$SWAP_DATADIR/venv"
|
||||
|
||||
|
||||
## Private Offers
|
||||
|
||||
To send a private offer:
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
import random
|
||||
import secrets
|
||||
import threading
|
||||
import unittest
|
||||
|
||||
import basicswap.contrib.ed25519_fast as edf
|
||||
@@ -24,6 +26,7 @@ from coincurve.ecdsaotves import (
|
||||
from coincurve.keys import PrivateKey
|
||||
|
||||
from basicswap.contrib.mnemonic import Mnemonic
|
||||
from basicswap.db import create_db_, DBMethods, KnownIdentity
|
||||
from basicswap.util import i2b, h2b
|
||||
from basicswap.util.address import decodeAddress
|
||||
from basicswap.util.crypto import ripemd160, hash160, blake256
|
||||
@@ -51,6 +54,9 @@ from basicswap.messages_npb import (
|
||||
from basicswap.contrib.test_framework.script import hash160 as hash160_btc
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
def test_serialise_num(self):
|
||||
@@ -556,6 +562,31 @@ class Test(unittest.TestCase):
|
||||
mnemonic_recovered: str = Mnemonic("english").to_mnemonic(entropy0)
|
||||
assert mnemonic_recovered == mnemonics[0]
|
||||
|
||||
def test_db(self):
|
||||
db_test = DBMethods()
|
||||
db_test.sqlite_file = ":memory:"
|
||||
db_test.mxDB = threading.Lock()
|
||||
cursor = db_test.openDB()
|
||||
try:
|
||||
create_db_(db_test._db_con, logger)
|
||||
# Test upsert
|
||||
ki = KnownIdentity()
|
||||
ki.address = "test"
|
||||
ki.label = "test"
|
||||
db_test.add(ki, cursor)
|
||||
ki.record_id = 1
|
||||
ki.address = "test1"
|
||||
ki.label = "test1"
|
||||
try:
|
||||
db_test.add(ki, cursor, upsert=False)
|
||||
except Exception as e:
|
||||
assert "UNIQUE constraint failed" in str(e)
|
||||
else:
|
||||
raise ValueError("Should have errored.")
|
||||
db_test.add(ki, cursor, upsert=True)
|
||||
finally:
|
||||
db_test.closeDB(cursor)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user