diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b176d84..9d606e81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,22 @@ jobs: - name: Run BDK regression script run: ./swap/tests/bdk.sh + sqlx_test: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3.1.0 + + - uses: Swatinem/rust-cache@v2.0.2 + + - name: Install sqlx-cli + run: cargo install sqlx-cli + + - name: Run sqlite_dev_setup.sh script + run: | + cd swap + ./sqlite_dev_setup.sh + build: strategy: matrix: diff --git a/.gitignore b/.gitignore index 905e678b..9b4798c4 100644 --- a/.gitignore +++ b/.gitignore @@ -159,4 +159,5 @@ flycheck_*.el # End of https://www.toptal.com/developers/gitignore/api/rust,clion+all,emacs *.log -.vscode \ No newline at end of file +.vscode +swap/tempdb diff --git a/Cargo.lock b/Cargo.lock index 8c9bf7fb..0e19140f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ "getrandom 0.2.6", "once_cell", @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "atoi" -version = "0.4.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" dependencies = [ "num-traits", ] @@ -488,9 +488,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.0.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "bzip2" @@ -720,18 +720,18 @@ checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] name = "crc" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10c2722795460108a7872e1cd933a85d6ec38abc4baecad51028f702da28889f" +checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "1.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" +checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" [[package]] name = "crc32fast" @@ -767,9 +767,9 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.1" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6cb3c7f5b8e51bc3ebb73a2327ad4abdbd119dc13223f14f961d2f38486756" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1002,10 +1002,10 @@ dependencies = [ ] [[package]] -name = "dotenv" -version = "0.15.0" +name = "dotenvy" +version = "0.15.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" [[package]] name = "dtoa" @@ -1103,24 +1103,30 @@ dependencies = [ [[package]] name = "enum-iterator" -version = "0.6.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79a6321a1197d7730510c7e3f6cb80432dfefecb32426de8cea0aa19b4bb8d7" +checksum = "45a0ac4aeb3a18f92eaf09c6bb9b3ac30ff61ca95514fc58cbead1c9a6bf5401" dependencies = [ "enum-iterator-derive", ] [[package]] name = "enum-iterator-derive" -version = "0.6.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e94aa31f7c0dc764f57896dc615ddd76fc13b0d5dca7eb6cc5e018a5a09ec06" +checksum = "828de45d0ca18782232dfb8f3ea9cc428e8ced380eb26a520baaacfc70de39ce" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "1.7.0" @@ -1173,6 +1179,18 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project 1.0.5", + "spin 0.9.4", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1372,9 +1390,9 @@ dependencies = [ [[package]] name = "getset" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24b328c01a4d71d2d8173daa93562a73ab0fe85616876f02500f53d82948c504" +checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1394,9 +1412,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.13.20" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9831e983241f8c5591ed53f17d874833e2fa82cac2625f3888c50cbfe136cba" +checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c" dependencies = [ "bitflags", "libc", @@ -1450,11 +1468,11 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.7.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" dependencies = [ - "hashbrown 0.11.2", + "hashbrown 0.12.3", ] [[package]] @@ -1471,6 +1489,9 @@ name = "heck" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -1797,9 +1818,9 @@ checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libgit2-sys" -version = "0.12.21+1.1.0" +version = "0.13.4+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86271bacd72b2b9e854c3dcfb82efd538f15f870e4c11af66900effb462f6825" +checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1" dependencies = [ "cc", "libc", @@ -2100,9 +2121,9 @@ dependencies = [ [[package]] name = "libsqlite3-sys" -version = "0.22.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" dependencies = [ "cc", "pkg-config", @@ -2584,6 +2605,12 @@ dependencies = [ "windows-sys 0.32.0", ] +[[package]] +name = "paste" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" + [[package]] name = "pem" version = "1.1.0" @@ -2934,9 +2961,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.9" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -3190,7 +3217,7 @@ dependencies = [ "cc", "libc", "once_cell", - "spin", + "spin 0.5.2", "untrusted", "web-sys", "winapi", @@ -3327,9 +3354,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.4" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" [[package]] name = "rusty-fork" @@ -3528,7 +3555,6 @@ version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ - "indexmap", "itoa 1.0.1", "ryu", "serde", @@ -3699,9 +3725,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.6.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "snow" @@ -3762,10 +3788,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] -name = "sqlformat" -version = "0.1.8" +name = "spin" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + +[[package]] +name = "sqlformat" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87e292b4291f154971a43c3774364e2cbcaec599d3f5bf6fa9d122885dbc38a" dependencies = [ "itertools", "nom 7.0.0", @@ -3774,9 +3809,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.5.9" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7911b0031a0247af40095838002999c7a52fba29d9739e93326e71a5a1bc9d43" +checksum = "9249290c05928352f71c077cc44a464d880c63f26f7534728cca008e135c0428" dependencies = [ "sqlx-core", "sqlx-macros", @@ -3784,9 +3819,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.9" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aec89bfaca8f7737439bad16d52b07f1ccd0730520d3bf6ae9d069fe4b641fb1" +checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" dependencies = [ "ahash", "atoi", @@ -3794,28 +3829,31 @@ dependencies = [ "byteorder", "bytes", "crc", - "crossbeam-channel", "crossbeam-queue", - "crossbeam-utils", + "dotenvy", "either", + "event-listener", + "flume", "futures-channel", "futures-core", + "futures-executor", "futures-intrusive", "futures-util", "hashlink", "hex", "indexmap", - "itoa 0.4.7", + "itoa 1.0.1", "libc", "libsqlite3-sys", "log", "memchr", "once_cell", - "parking_lot 0.11.2", + "paste", "percent-encoding", - "rustls 0.19.0", + "rustls 0.20.2", + "rustls-pemfile", "serde", - "sha2 0.9.8", + "sha2 0.10.6", "smallvec", "sqlformat", "sqlx-rt", @@ -3823,27 +3861,25 @@ dependencies = [ "thiserror", "tokio-stream", "url", - "webpki 0.21.4", - "webpki-roots 0.21.0", - "whoami", + "webpki-roots 0.22.2", ] [[package]] name = "sqlx-macros" -version = "0.5.9" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584866c833511b1a152e87a7ee20dee2739746f60c858b3c5209150bc4b466f5" +checksum = "b850fa514dc11f2ee85be9d055c512aa866746adfacd1cb42d867d68e6a5b0d9" dependencies = [ - "dotenv", + "dotenvy", "either", - "heck 0.3.2", + "heck 0.4.0", "hex", "once_cell", "proc-macro2", "quote", "serde", "serde_json", - "sha2 0.9.8", + "sha2 0.10.6", "sqlx-core", "sqlx-rt", "syn", @@ -3852,13 +3888,13 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.5.9" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d1bd069de53442e7a320f525a6d4deb8bb0621ac7a55f7eccbc2b58b57f43d0" +checksum = "24c5b2d25fa654cc5f841750b8e1cdedbe21189bf9a9382ee90bfa9dd3562396" dependencies = [ "once_cell", "tokio", - "tokio-rustls 0.22.0", + "tokio-rustls 0.23.1", ] [[package]] @@ -4266,9 +4302,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.4" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c535f53c0cfa1acace62995a8994fc9cc1f12d202420da96ff306ee24d576469" +checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" dependencies = [ "futures-core", "pin-project-lite 0.2.9", @@ -4705,9 +4741,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "vergen" -version = "7.0.0" +version = "7.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4db743914c971db162f35bf46601c5a63ec4452e61461937b4c1ab817a60c12e" +checksum = "447f9238a4553957277b3ee09d80babeae0811f1b3baefb093de1c0448437a37" dependencies = [ "anyhow", "cfg-if 1.0.0", @@ -4892,16 +4928,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "whoami" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7741161a40200a867c96dfa5574544efa4178cf4c8f770b62dd1cc0362d7ae1" -dependencies = [ - "wasm-bindgen", - "web-sys", -] - [[package]] name = "widestring" version = "0.5.1" diff --git a/bors.toml b/bors.toml index 49146fac..e02a79db 100644 --- a/bors.toml +++ b/bors.toml @@ -1,6 +1,7 @@ status = [ "static_analysis", "bdk_test", + "sqlx_test", "build (x86_64-unknown-linux-gnu, ubuntu-latest)", "build (armv7-unknown-linux-gnueabihf, ubuntu-latest)", "build (x86_64-apple-darwin, macos-latest)", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index c900137f..cd5bdf81 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -48,7 +48,7 @@ serde_json = "1" serde_with = { version = "1", features = [ "macros" ] } sha2 = "0.10" sigma_fun = { git = "https://github.com/LLFourn/secp256kfun", default-features = false, features = [ "ed25519", "serde", "secp256k1", "alloc" ] } -sqlx = { version = "0.5", features = [ "sqlite", "runtime-tokio-rustls", "offline" ] } +sqlx = { version = "0.6", features = [ "sqlite", "runtime-tokio-rustls", "offline" ] } structopt = "0.3" strum = { version = "0.24", features = [ "derive" ] } thiserror = "1" diff --git a/swap/sqlite_dev_setup.sh b/swap/sqlite_dev_setup.sh old mode 100644 new mode 100755 index d07a763a..67d2c9da --- a/swap/sqlite_dev_setup.sh +++ b/swap/sqlite_dev_setup.sh @@ -1,6 +1,14 @@ -# crated temporary DB -# run the migration scripts to create the tables -# prepare the sqlx-data.json rust mappings +#!/bin/bash + +# run this script from the swap dir +# make sure you have sqlx-cli installed: cargo install sqlx-cli + +# this script creates a temporary sqlite database +# then runs the migration scripts to create the tables (migrations folder) +# then it prepares the offline sqlx-data.json rust mappings DATABASE_URL=sqlite:tempdb cargo sqlx database create DATABASE_URL=sqlite:tempdb cargo sqlx migrate run -DATABASE_URL=sqlite:./swap/tempdb cargo sqlx prepare -- --bin swap \ No newline at end of file +# needs the absolute path here +# https://github.com/launchbadge/sqlx/issues/1399 +DB_PATH=$(readlink -f tempdb) +DATABASE_URL="sqlite:$DB_PATH" cargo sqlx prepare -- --bin swap diff --git a/swap/sqlx-data.json b/swap/sqlx-data.json index 61254fc2..fd50cd87 100644 --- a/swap/sqlx-data.json +++ b/swap/sqlx-data.json @@ -1,7 +1,6 @@ { "db": "SQLite", "081c729a0f1ad6e4ff3e13d6702c946bc4d37d50f40670b4f51d2efcce595aa6": { - "query": "\n SELECT peer_id\n FROM peers\n WHERE swap_id = ?\n ", "describe": { "columns": [ { @@ -10,26 +9,26 @@ "type_info": "Text" } ], - "parameters": { - "Right": 1 - }, "nullable": [ false - ] - } + ], + "parameters": { + "Right": 1 + } + }, + "query": "\n SELECT peer_id\n FROM peers\n WHERE swap_id = ?\n " }, "0ab84c094964968e96a3f2bf590d9ae92227d057386921e0e57165b887de3c75": { - "query": "\n insert into peer_addresses (\n peer_id,\n address\n ) values (?, ?);\n ", "describe": { "columns": [], + "nullable": [], "parameters": { "Right": 2 - }, - "nullable": [] - } + } + }, + "query": "\n insert into peer_addresses (\n peer_id,\n address\n ) values (?, ?);\n " }, "1ec38c85e7679b2eb42b3df75d9098772ce44fdb8db3012d3c2410d828b74157": { - "query": "\n SELECT swap_id, state\n FROM (\n SELECT max(id), swap_id, state\n FROM swap_states\n GROUP BY swap_id\n )\n ", "describe": { "columns": [ { @@ -43,37 +42,37 @@ "type_info": "Text" } ], - "parameters": { - "Right": 0 - }, "nullable": [ false, false - ] - } + ], + "parameters": { + "Right": 0 + } + }, + "query": "\n SELECT swap_id, state\n FROM (\n SELECT max(id), swap_id, state\n FROM swap_states\n GROUP BY swap_id\n )\n " }, "2a356078a41b321234adf2aa385b501749f907f7c422945a8bdda2b6274f5225": { - "query": "\n insert into peers (\n swap_id,\n peer_id\n ) values (?, ?);\n ", "describe": { "columns": [], + "nullable": [], "parameters": { "Right": 2 - }, - "nullable": [] - } + } + }, + "query": "\n insert into peers (\n swap_id,\n peer_id\n ) values (?, ?);\n " }, "50a5764546f69c118fa0b64120da50f51073d36257d49768de99ff863e3511e0": { - "query": "\n insert into monero_addresses (\n swap_id,\n address\n ) values (?, ?);\n ", "describe": { "columns": [], + "nullable": [], "parameters": { "Right": 2 - }, - "nullable": [] - } + } + }, + "query": "\n insert into monero_addresses (\n swap_id,\n address\n ) values (?, ?);\n " }, "88f761a4f7a0429cad1df0b1bebb1c0a27b2a45656549b23076d7542cfa21ecf": { - "query": "\n SELECT state\n FROM swap_states\n WHERE swap_id = ?\n ORDER BY id desc\n LIMIT 1;\n\n ", "describe": { "columns": [ { @@ -82,16 +81,16 @@ "type_info": "Text" } ], - "parameters": { - "Right": 1 - }, "nullable": [ false - ] - } + ], + "parameters": { + "Right": 1 + } + }, + "query": "\n SELECT state\n FROM swap_states\n WHERE swap_id = ?\n ORDER BY id desc\n LIMIT 1;\n\n " }, "a0eb85d04ee3842c52291dad4d225941d1141af735922fcbc665868997fce304": { - "query": "\n SELECT address\n FROM peer_addresses\n WHERE peer_id = ?\n ", "describe": { "columns": [ { @@ -100,26 +99,26 @@ "type_info": "Text" } ], - "parameters": { - "Right": 1 - }, "nullable": [ false - ] - } + ], + "parameters": { + "Right": 1 + } + }, + "query": "\n SELECT address\n FROM peer_addresses\n WHERE peer_id = ?\n " }, "b703032b4ddc627a1124817477e7a8e5014bdc694c36a14053ef3bb2fc0c69b0": { - "query": "\n insert into swap_states (\n swap_id,\n entered_at,\n state\n ) values (?, ?, ?);\n ", "describe": { "columns": [], + "nullable": [], "parameters": { "Right": 3 - }, - "nullable": [] - } + } + }, + "query": "\n insert into swap_states (\n swap_id,\n entered_at,\n state\n ) values (?, ?, ?);\n " }, "ce270dd4a4b9615695a79864240c5401e2122077365e5e5a19408c068c7f9454": { - "query": "\n SELECT address\n FROM monero_addresses\n WHERE swap_id = ?\n ", "describe": { "columns": [ { @@ -128,12 +127,13 @@ "type_info": "Text" } ], - "parameters": { - "Right": 1 - }, "nullable": [ false - ] - } + ], + "parameters": { + "Right": 1 + } + }, + "query": "\n SELECT address\n FROM monero_addresses\n WHERE swap_id = ?\n " } } \ No newline at end of file