Remove plyvel dependency.

I can't get it to run under docker in windows.
2024-05-20_merge
tecnovert 6 years ago
parent 6c0d82abe6
commit a49be16f9c
No known key found for this signature in database
GPG Key ID: 13F13651C9CF0D6B
  1. 1
      .travis.yml
  2. 12
      Dockerfile
  3. 107
      basicswap/basicswap.py
  4. 1
      setup.py

@ -17,7 +17,6 @@ before_script:
- if [ ! -d "$BITCOIN_BINDIR" ]; then cd "/opt/binaries" && wget https://bitcoincore.org/bin/bitcoin-core-0.18.0/bitcoin-0.18.0-x86_64-linux-gnu.tar.gz && tar xvf bitcoin-0.18.0-x86_64-linux-gnu.tar.gz ; fi - if [ ! -d "$BITCOIN_BINDIR" ]; then cd "/opt/binaries" && wget https://bitcoincore.org/bin/bitcoin-core-0.18.0/bitcoin-0.18.0-x86_64-linux-gnu.tar.gz && tar xvf bitcoin-0.18.0-x86_64-linux-gnu.tar.gz ; fi
- if [ ! -d "$LITECOIN_BINDIR" ]; then cd "/opt/binaries" && wget https://download.litecoin.org/litecoin-0.17.1/linux/litecoin-0.17.1-x86_64-linux-gnu.tar.gz && tar xvf litecoin-0.17.1-x86_64-linux-gnu.tar.gz ; fi - if [ ! -d "$LITECOIN_BINDIR" ]; then cd "/opt/binaries" && wget https://download.litecoin.org/litecoin-0.17.1/linux/litecoin-0.17.1-x86_64-linux-gnu.tar.gz && tar xvf litecoin-0.17.1-x86_64-linux-gnu.tar.gz ; fi
- if [ ! -d "$PARTICL_BINDIR" ]; then cd "/opt/binaries" && wget https://github.com/particl/particl-core/releases/download/v0.18.0.12/particl-0.18.0.12-x86_64-linux-gnu_nousb.tar.gz && tar xvf particl-0.18.0.12-x86_64-linux-gnu_nousb.tar.gz ; fi - if [ ! -d "$PARTICL_BINDIR" ]; then cd "/opt/binaries" && wget https://github.com/particl/particl-core/releases/download/v0.18.0.12/particl-0.18.0.12-x86_64-linux-gnu_nousb.tar.gz && tar xvf particl-0.18.0.12-x86_64-linux-gnu_nousb.tar.gz ; fi
- cd
script: script:
- cd $TRAVIS_BUILD_DIR - cd $TRAVIS_BUILD_DIR
- export PARTICL_BINDIR=/opt/binaries/particl-0.18.0.12/bin/ - export PARTICL_BINDIR=/opt/binaries/particl-0.18.0.12/bin/

@ -20,11 +20,13 @@ RUN PARTICL_VERSION=0.18.0.12 PARTICL_VERSION_TAG= PARTICL_ARCH=x86_64-linux-gnu
mkdir -p ${LITECOIN_BINDIR}; \ mkdir -p ${LITECOIN_BINDIR}; \
tar -xvf litecoin-0.17.1-x86_64-linux-gnu.tar.gz -C ${LITECOIN_BINDIR} --strip-components 2 litecoin-0.17.1/bin/litecoind litecoin-0.17.1/bin/litecoin-cli tar -xvf litecoin-0.17.1-x86_64-linux-gnu.tar.gz -C ${LITECOIN_BINDIR} --strip-components 2 litecoin-0.17.1/bin/litecoind litecoin-0.17.1/bin/litecoin-cli
# Change to git clone # TODO: move coindata dir out of src dir
COPY . /opt/basicswap #COPY . /opt/basicswap
#RUN ls /opt/basicswap; \
RUN ls /opt/basicswap; \ # cd /opt/basicswap; \
cd /opt/basicswap; \ RUN wget -O bs.zip https://github.com/tecnovert/basicswap/archive/master.zip; \
unzip bs.zip; \
cd basicswap-master; \
protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \ protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \
pip3 install .; pip3 install .;

@ -13,7 +13,6 @@ import threading
import traceback import traceback
import struct import struct
import hashlib import hashlib
import plyvel
import subprocess import subprocess
import logging import logging
import sqlalchemy as sa import sqlalchemy as sa
@ -55,8 +54,6 @@ SMSG_SECONDS_IN_DAY = 86400
CURRENT_DB_VERSION = 1 CURRENT_DB_VERSION = 1
DBT_DATA = ord('d')
MIN_OFFER_VALID_TIME = 60 * 10 MIN_OFFER_VALID_TIME = 60 * 10
MAX_OFFER_VALID_TIME = 60 * 60 * 48 MAX_OFFER_VALID_TIME = 60 * 60 * 48
@ -271,6 +268,18 @@ def replaceAddrPrefix(addr, coin_type, chain_name, addr_type='pubkey_address'):
Base = declarative_base() Base = declarative_base()
class DBKVInt(Base):
__tablename__ = 'kv_int'
key = sa.Column(sa.String, primary_key=True)
value = sa.Column(sa.Integer)
class DBKVString(Base):
__tablename__ = 'kv_string'
key = sa.Column(sa.String, primary_key=True)
value = sa.Column(sa.String)
class Offer(Base): class Offer(Base):
__tablename__ = 'offers' __tablename__ = 'offers'
@ -436,19 +445,24 @@ class BasicSwap():
Base.metadata.create_all(self.engine) Base.metadata.create_all(self.engine)
self.session_factory = sessionmaker(bind=self.engine, expire_on_commit=False) self.session_factory = sessionmaker(bind=self.engine, expire_on_commit=False)
self.db_path = os.path.join(data_dir, 'db') session = scoped_session(self.session_factory)
db = plyvel.DB(self.db_path, create_if_missing=True) try:
n = db.get(bytes([DBT_DATA]) + b'db_version') self.db_version = session.query(DBKVInt).filter_by(key='db_version').first().value
if n is None: except Exception:
self.log.info('First run') self.log.info('First run')
self.db_version = CURRENT_DB_VERSION self.db_version = CURRENT_DB_VERSION
db.put(bytes([DBT_DATA]) + b'db_version', struct.pack('>i', self.db_version)) session.add(DBKVInt(
else: key='db_version',
self.db_version = struct.unpack('>i', n)[0] value=self.db_version
))
session.commit()
n = db.get(bytes([DBT_DATA]) + b'contract_count') try:
self._contract_count = 0 if n is None else struct.unpack('>i', n)[0] self._contract_count = session.query(DBKVInt).filter_by(key='contract_count').first().value
db.close() except Exception:
self._contract_count = 0
session.close()
session.remove()
self.zmqContext = zmq.Context() self.zmqContext = zmq.Context()
self.zmqSubscriber = self.zmqContext.socket(zmq.SUB) self.zmqSubscriber = self.zmqContext.socket(zmq.SUB)
@ -563,11 +577,7 @@ class BasicSwap():
if db_version >= CURRENT_DB_VERSION: if db_version >= CURRENT_DB_VERSION:
return return
self.log.info('Upgrading leveldb Database from version %d to %d.', db_version, CURRENT_DB_VERSION) self.log.info('Upgrading Database from version %d to %d.', db_version, CURRENT_DB_VERSION)
db = plyvel.DB(self.db_path, create_if_missing=True)
db.put(bytes([DBT_DATA]) + b'db_version', struct.pack('>i', CURRENT_DB_VERSION))
db.close()
def waitForDaemonRPC(self): def waitForDaemonRPC(self):
for i in range(21): for i in range(21):
@ -787,32 +797,63 @@ class BasicSwap():
def cacheNewAddressForCoin(self, coin_type): def cacheNewAddressForCoin(self, coin_type):
self.log.debug('cacheNewAddressForCoin %s', coin_type) self.log.debug('cacheNewAddressForCoin %s', coin_type)
db = plyvel.DB(self.db_path, create_if_missing=True) key_str = 'receive_addr_' + chainparams[coin_type]['name']
dbkey = bytes([DBT_DATA]) + bytes('receive_addr_' + chainparams[coin_type]['name'], 'utf-8') session = scoped_session(self.session_factory)
addr = self.getReceiveAddressForCoin(coin_type) addr = self.getReceiveAddressForCoin(coin_type)
db.put(dbkey, bytes(addr, 'utf-8')) self.mxDB.acquire()
db.close() try:
session = scoped_session(self.session_factory)
try:
kv = session.query(DBKVString).filter_by(key=key_str).first()
kv.value = addr
except Exception:
kv = DBKVString(
key=key_str,
value=addr
)
session.add(kv)
session.commit()
session.close()
session.remove()
finally:
self.mxDB.release()
return addr return addr
def getCachedAddressForCoin(self, coin_type): def getCachedAddressForCoin(self, coin_type):
self.log.debug('getCachedAddressForCoin %s', coin_type) self.log.debug('getCachedAddressForCoin %s', coin_type)
# TODO: auto refresh after used # TODO: auto refresh after used
db = plyvel.DB(self.db_path, create_if_missing=True)
dbkey = bytes([DBT_DATA]) + bytes('receive_addr_' + chainparams[coin_type]['name'], 'utf-8') key_str = 'receive_addr_' + chainparams[coin_type]['name']
dbval = db.get(dbkey) self.mxDB.acquire()
if dbval is None: try:
session = scoped_session(self.session_factory)
try:
addr = session.query(DBKVString).filter_by(key=key_str).first().value
except Exception:
addr = self.getReceiveAddressForCoin(coin_type) addr = self.getReceiveAddressForCoin(coin_type)
db.put(dbkey, bytes(addr, 'utf-8')) session.add(DBKVString(
else: key=key_str,
addr = dbval.decode('utf-8') value=addr
db.close() ))
session.commit()
session.close()
session.remove()
finally:
self.mxDB.release()
return addr return addr
def getNewContractId(self): def getNewContractId(self):
self.mxDB.acquire()
try:
self._contract_count += 1 self._contract_count += 1
db = plyvel.DB(self.db_path, create_if_missing=True) session = scoped_session(self.session_factory)
db.put(bytes([DBT_DATA]) + b'contract_count', struct.pack('>i', self._contract_count)) self.engine.execute('UPDATE kv_int SET value = {} WHERE KEY="contract_count"'.format(self._contract_count))
db.close() session.commit()
session.close()
session.remove()
finally:
self.mxDB.release()
return self._contract_count return self._contract_count
def getProofOfFunds(self, coin_type, amount_for): def getProofOfFunds(self, coin_type, amount_for):

@ -24,7 +24,6 @@ setuptools.setup(
], ],
install_requires=[ install_requires=[
"pyzmq", "pyzmq",
"plyvel",
"protobuf", "protobuf",
"sqlalchemy", "sqlalchemy",
], ],

Loading…
Cancel
Save