From d15cf3dd6fd45ce16cbc804a2d26260567b44d75 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sun, 20 Nov 2022 20:58:10 +0200 Subject: [PATCH] guix: Add guix.scm --- .gitignore | 1 + README.md | 20 ++++++ basicswap/config.py | 2 +- bin/basicswap_prepare.py | 69 ++++++++++--------- guix.scm | 144 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 - setup.py | 1 - 7 files changed, 203 insertions(+), 35 deletions(-) create mode 100644 guix.scm diff --git a/.gitignore b/.gitignore index f3a524e..39f38f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ old/ +build/ *.pyc __pycache__ /dist/ diff --git a/README.md b/README.md index 7f6d067..802be65 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Simple Atomic Swap Network - Proof of Concept + ## Overview Simple atomic swap experiment, doesn't have many interesting features yet. @@ -13,8 +14,27 @@ Other nodes can be run in pruned mode. A node must be run for each coin type traded. In the future it should be possible to use data from explorers instead of running a node. + ## Currently a work in progress Not ready for real-world use. Discuss development and help with testing in the matrix channel [#basicswap:matrix.org](https://riot.im/app/#/room/#basicswap:matrix.org) + + +## Guix + +Start a development environment + + guix shell --pure -D -f guix.scm + + +Run tests + + export PYTHONPATH=$(pwd) + + # Prepare coin binaries - required once + python ./bin/basicswap-prepare.py -preparebinonly --withcoins=monero,bitcoin,particl,litecoin + + pytest -vs tests/basicswap/test_run.py::Test::test_02_part_ltc + diff --git a/basicswap/config.py b/basicswap/config.py index 33483f9..245c4d1 100644 --- a/basicswap/config.py +++ b/basicswap/config.py @@ -10,7 +10,7 @@ CONFIG_FILENAME = 'basicswap.json' BASICSWAP_DATADIR = os.getenv('BASICSWAP_DATADIR', '~/.basicswap') DEFAULT_ALLOW_CORS = False TEST_DATADIRS = os.path.expanduser(os.getenv('DATADIRS', '/tmp/basicswap')) -DEFAULT_TEST_BINDIR = os.path.expanduser(os.getenv('DEFAULT_TEST_BINDIR', '~/tmp/bin')) +DEFAULT_TEST_BINDIR = os.path.expanduser(os.getenv('DEFAULT_TEST_BINDIR', '~/.basicswap/bin')) bin_suffix = ('.exe' if os.name == 'nt' else '') PARTICL_BINDIR = os.path.expanduser(os.getenv('PARTICL_BINDIR', os.path.join(DEFAULT_TEST_BINDIR, 'particl'))) diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 345a011..2189eaf 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -890,38 +890,38 @@ def printVersion(): def printHelp(): - logger.info('Usage: basicswap-prepare ') - logger.info('\n--help, -h Print help.') - logger.info('--version, -v Print version.') - logger.info('--datadir=PATH Path to basicswap data directory, default:{}.'.format(cfg.BASICSWAP_DATADIR)) - logger.info('--bindir=PATH Path to cores directory, default:datadir/bin.') - logger.info('--mainnet Run in mainnet mode.') - logger.info('--testnet Run in testnet mode.') - logger.info('--regtest Run in regtest mode.') - logger.info('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated,\n' - + ' "auto" to create a wallet automatically - No mnemonic.' - + ' "none" to disable wallet initialisation.') - logger.info('--withcoin= Prepare system to run daemon for coin.') - logger.info('--withoutcoin= Do not prepare system to run daemon for coin.') - logger.info('--addcoin= Add coin to existing setup.') - logger.info('--disablecoin= Make coin inactive.') - logger.info('--preparebinonly Don\'t prepare settings or datadirs.') - logger.info('--nocores Don\'t download and extract any coin clients.') - logger.info('--usecontainers Expect each core to run in a unique container.') - logger.info('--portoffset=n Raise all ports by n.') - logger.info('--htmlhost= Interface to host html server on, default:127.0.0.1.') - logger.info('--wshost= Interface to host websocket server on, disable by setting to "none", default:127.0.0.1.') - logger.info('--xmrrestoreheight=n Block height to restore Monero wallet from, default:{}.'.format(DEFAULT_XMR_RESTORE_HEIGHT)) - logger.info('--noextractover Prevent extracting cores if files exist. Speeds up tests') - logger.info('--usetorproxy Use TOR proxy during setup. Note that some download links may be inaccessible over TOR.') - logger.info('--enabletor Setup Basicswap instance to use TOR.') - logger.info('--disabletor Setup Basicswap instance to not use TOR.') - logger.info('--usebtcfastsync Initialise the BTC chain with a snapshot from btcpayserver FastSync.\n' - + ' See https://github.com/btcpayserver/btcpayserver-docker/blob/master/contrib/FastSync/README.md') - logger.info('--initwalletsonly Setup coin wallets only.') - logger.info('--keysdirpath Speed up tests by preloading all PGP keys in directory.') - - logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys())) + print('Usage: basicswap-prepare ') + print('\n--help, -h Print help.') + print('--version, -v Print version.') + print('--datadir=PATH Path to basicswap data directory, default:{}.'.format(cfg.BASICSWAP_DATADIR)) + print('--bindir=PATH Path to cores directory, default:datadir/bin.') + print('--mainnet Run in mainnet mode.') + print('--testnet Run in testnet mode.') + print('--regtest Run in regtest mode.') + print('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated,\n' + + ' "auto" to create a wallet automatically - No mnemonic.' + + ' "none" to disable wallet initialisation.') + print('--withcoin= Prepare system to run daemon for coin.') + print('--withoutcoin= Do not prepare system to run daemon for coin.') + print('--addcoin= Add coin to existing setup.') + print('--disablecoin= Make coin inactive.') + print('--preparebinonly Don\'t prepare settings or datadirs.') + print('--nocores Don\'t download and extract any coin clients.') + print('--usecontainers Expect each core to run in a unique container.') + print('--portoffset=n Raise all ports by n.') + print('--htmlhost= Interface to host html server on, default:127.0.0.1.') + print('--wshost= Interface to host websocket server on, disable by setting to "none", default:127.0.0.1.') + print('--xmrrestoreheight=n Block height to restore Monero wallet from, default:{}.'.format(DEFAULT_XMR_RESTORE_HEIGHT)) + print('--noextractover Prevent extracting cores if files exist. Speeds up tests') + print('--usetorproxy Use TOR proxy during setup. Note that some download links may be inaccessible over TOR.') + print('--enabletor Setup Basicswap instance to use TOR.') + print('--disabletor Setup Basicswap instance to not use TOR.') + print('--usebtcfastsync Initialise the BTC chain with a snapshot from btcpayserver FastSync.\n' + + ' See https://github.com/btcpayserver/btcpayserver-docker/blob/master/contrib/FastSync/README.md') + print('--initwalletsonly Setup coin wallets only.') + print('--keysdirpath Speed up tests by preloading all PGP keys in directory.') + + print('\n' + 'Known coins: {}'.format(', '.join(known_coins.keys()))) def finalise_daemon(d): @@ -1452,6 +1452,11 @@ def main(): else: with open(config_path) as fs: settings = json.load(fs) + + # Add temporary default config for any coins that have not been added + for c in with_coins: + if c not in settings['chainclients']: + settings['chainclients'][c] = chainclients[c] else: for c in with_coins: withchainclients[c] = chainclients[c] diff --git a/guix.scm b/guix.scm new file mode 100644 index 0000000..ff927c3 --- /dev/null +++ b/guix.scm @@ -0,0 +1,144 @@ +(use-modules + (guix packages) + ((guix licenses) #:prefix license:) + (guix build-system python) + (guix build-system gnu) + (guix git-download) + (guix download) + (gnu packages) + (gnu packages pkg-config) + (gnu packages autotools) + (gnu packages certs) + (gnu packages check) + (gnu packages databases) + (gnu packages finance) + (gnu packages gnupg) + (gnu packages protobuf) + (gnu packages python) + (gnu packages python-build) + (gnu packages python-crypto) + (gnu packages python-xyz) + (gnu packages libffi) + (gnu packages license)) + +(define libsecp256k1-anonswap + (package + (name "libsecp256k1-anonswap") + (version "anonswap_v0.1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/tecnovert/secp256k1") + (commit version))) + (sha256 + (base32 + "1lrcc5gjywlzvrgwzifva4baa2nsvwr3h0wmkc71q0zhag9pjbah")) + (file-name (git-file-name name version)))) + (build-system gnu-build-system) + (arguments + '(#:configure-flags '("--enable-shared" + "--disable-dependency-tracking" + "--with-valgrind=no" + "--enable-experimental" + "--enable-module-recovery" + "--enable-module-ecdh" + "--enable-benchmark=no" + "--enable-tests=no" + "--enable-module-ed25519" + "--enable-module-generator" + "--enable-module-dleag" + "--enable-module-ecdsaotves" + ))) + (native-inputs + (list autoconf automake libtool)) + (synopsis "C library for EC operations on curve secp256k1") + (description + "Optimized C library for EC operations on curve secp256k1.\n") + (home-page "https://github.com/bitcoin-core/secp256k1") + (license license:unlicense))) + + +(define python-coincurve-anonswap + (package + (name "python-coincurve-anonswap") + (version "anonswap_v0.1") + (source + (origin + (method git-fetch) + (uri + (git-reference + (url "https://github.com/tecnovert/coincurve") + (commit version))) + (file-name + (git-file-name name version)) + (sha256 + (base32 "0vyzvpp2s21js01185qbm1lgs4ps4hki2d6yzprfsjqap1i5qhmp")))) + (build-system python-build-system) + (arguments + '(#:tests? #f ;XXX fails to load "libsecp256k1.dll" + #:phases (modify-phases %standard-phases + (add-after 'unpack 'patch-libsec256k1-path + (lambda _ + (substitute* "setup.py" + (("if has_system_lib\\(\\)") + "if True") + ((", 'requests'") + "") + (("download_library\\(self\\)") + ""))))))) + (propagated-inputs + (list + libsecp256k1-anonswap + python-asn1crypto + python-cffi)) + (native-inputs + (list + python-setuptools + pkg-config + )) + (synopsis "Python libsecp256k1 wrapper") + (description "Python libsecp256k1 wrapper.") + (home-page "https://github.com/tecnovert/coincurve") + (license license:bsd-3))) + +(define python-sqlalchemy-1.4.39 + (package + (inherit python-sqlalchemy) + (version "1.4.39") + (source + (origin + (method url-fetch) + (uri (pypi-uri "SQLAlchemy" version)) + (sha256 + (base32 "09sx2lghywnm7qj1xm8xc3xrgj40bndfh2hbiaq4cfvm71h8k541")))))) + +(package + (name "basicswap") + (version "0.11.49") + (source #f) + (build-system python-build-system) + (propagated-inputs + (list + gnupg + nss-certs + python-coincurve-anonswap + python-pycryptodome + python-pylint + python-pyflakes + python-pytest + python-protobuf + python-sqlalchemy-1.4.39 + python-pyzmq + python-gnupg + python-jinja2 + python-pysocks + python-mnemonic + )) + (native-inputs + (list + python-setuptools + )) + (synopsis "Simple Atomic Swap Network - Proof of Concept") + (description #f) + (home-page "https://github.com/tecnovert/basicswap") + (license license:bsd-3)) diff --git a/requirements.txt b/requirements.txt index c9f3242..19422ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ protobuf sqlalchemy==1.4.39 python-gnupg Jinja2 -requests pycryptodome PySocks mnemonic diff --git a/setup.py b/setup.py index ecd767b..ff7740c 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,6 @@ setuptools.setup( "sqlalchemy==1.4.39", "python-gnupg", "Jinja2", - "requests", "pycryptodome", "PySocks", "mnemonic",