From 6a43e919853d29c35695cac7dba91a43e7b5e999 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Fri, 28 Jun 2024 17:54:40 +0200 Subject: [PATCH 1/5] refactor: ChainDataProvider trait --- Cargo.lock | 650 ++++++++++++++++++++----------------- Cargo.toml | 6 +- src/chain/client.rs | 97 +++--- src/chain/mod.rs | 2 +- src/chain/types.rs | 16 + src/claimer/constructor.rs | 14 +- src/claimer/mod.rs | 38 +-- src/main.rs | 6 +- 8 files changed, 460 insertions(+), 369 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4573d3..925c0e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -43,52 +43,59 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", ] +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-trait" version = "0.1.80" @@ -113,17 +120,11 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" @@ -135,10 +136,10 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "http-body-util", - "hyper", + "hyper 1.3.1", "hyper-util", "itoa", "matchit", @@ -168,8 +169,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "http-body-util", "mime", "pin-project-lite", @@ -182,9 +183,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -195,6 +196,22 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" @@ -207,18 +224,42 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bitcoin" version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" dependencies = [ - "bech32", - "bitcoin-internals", - "bitcoin_hashes", - "hex-conservative", + "bech32 0.10.0-beta", + "bitcoin-internals 0.2.0", + "bitcoin_hashes 0.13.0", + "hex-conservative 0.1.2", + "hex_lit", + "secp256k1 0.28.2", + "serde", +] + +[[package]] +name = "bitcoin" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +dependencies = [ + "base58ck", + "bech32 0.11.0", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", "hex_lit", - "secp256k1", + "secp256k1 0.29.0", "serde", ] @@ -231,20 +272,56 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + [[package]] name = "bitcoin-private" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +[[package]] +name = "bitcoin-units" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5" +dependencies = [ + "bitcoin-internals 0.3.0", + "serde", +] + [[package]] name = "bitcoin_hashes" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.2", + "serde", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.1", "serde", ] @@ -256,9 +333,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "built" @@ -283,12 +360,13 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.94" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] @@ -312,9 +390,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "core-foundation" @@ -336,8 +414,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" name = "covclaim" version = "0.1.0" dependencies = [ + "async-trait", "axum", - "base64", + "base64 0.22.1", "built", "crossbeam-channel", "diesel", @@ -345,6 +424,7 @@ dependencies = [ "dotenvy", "elements", "env_logger", + "esplora-client", "hex", "log", "num_cpus", @@ -398,15 +478,15 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "darling" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" +checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" dependencies = [ "darling_core", "darling_macro", @@ -414,9 +494,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" +checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" dependencies = [ "fnv", "ident_case", @@ -428,9 +508,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" +checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", @@ -444,7 +524,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -528,9 +608,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elements" @@ -538,7 +618,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd6b8388053196e6b2702a45418078a654680ce9e1fd91799f51f67a40118ff5" dependencies = [ - "bitcoin", + "bitcoin 0.31.2", "secp256k1-zkp", "serde", "serde_json", @@ -584,19 +664,32 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", ] +[[package]] +name = "esplora-client" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b546e91283ebfc56337de34e0cf814e3ad98083afde593b8e58495ee5355d0e" +dependencies = [ + "bitcoin 0.32.2", + "hex-conservative 0.2.1", + "log", + "reqwest", + "serde", +] + [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fnv" @@ -692,9 +785,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -703,9 +796,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "git2" @@ -713,7 +806,7 @@ version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "libc", "libgit2-sys", "log", @@ -722,16 +815,16 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.5" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ - "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "http", + "futures-util", + "http 0.2.12", "indexmap 2.2.6", "slab", "tokio", @@ -747,9 +840,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" @@ -774,9 +867,18 @@ dependencies = [ [[package]] name = "hex-conservative" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" + +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] [[package]] name = "hex_lit" @@ -784,6 +886,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.1.0" @@ -795,6 +908,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.0" @@ -802,27 +926,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http", + "http 1.1.0", ] [[package]] name = "http-body-util" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", - "futures-core", - "http", - "http-body", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -838,76 +962,73 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "1.3.1" +version = "0.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" dependencies = [ "bytes", "futures-channel", + "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", "pin-project-lite", - "smallvec", + "socket2", "tokio", + "tower-service", + "tracing", "want", ] [[package]] -name = "hyper-rustls" -version = "0.27.2" +name = "hyper" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" dependencies = [ + "bytes", + "futures-channel", "futures-util", - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", "tokio", - "tokio-rustls", - "tower-service", ] [[package]] name = "hyper-tls" -version = "0.6.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "http-body-util", - "hyper", - "hyper-util", + "hyper 0.14.29", "native-tls", "tokio", "tokio-native-tls", - "tower-service", ] [[package]] name = "hyper-util" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" dependencies = [ "bytes", - "futures-channel", "futures-util", - "http", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.3.1", "pin-project-lite", - "socket2", "tokio", - "tower", - "tower-service", - "tracing", ] [[package]] @@ -967,7 +1088,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "serde", ] @@ -977,6 +1098,12 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itoa" version = "1.0.11" @@ -985,9 +1112,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -1001,17 +1128,11 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libgit2-sys" @@ -1037,9 +1158,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.16" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" dependencies = [ "cc", "libc", @@ -1049,15 +1170,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1077,9 +1198,9 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "migrations_internals" @@ -1110,9 +1231,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -1130,11 +1251,10 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "lazy_static", "libc", "log", "openssl", @@ -1154,9 +1274,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -1173,9 +1293,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -1192,7 +1312,7 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -1232,9 +1352,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -1242,15 +1362,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -1311,9 +1431,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.80" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1390,18 +1510,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -1411,9 +1531,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -1422,29 +1542,26 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" -version = "0.12.5" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", "futures-util", "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.29", "hyper-tls", - "hyper-util", "ipnet", "js-sys", "log", @@ -1457,10 +1574,11 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper 0.1.2", "system-configuration", "tokio", "tokio-native-tls", + "tokio-socks", "tower-service", "url", "wasm-bindgen", @@ -1469,91 +1587,45 @@ dependencies = [ "winreg", ] -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", "windows-sys 0.52.0", ] -[[package]] -name = "rustls" -version = "0.23.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" -dependencies = [ - "once_cell", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - [[package]] name = "rustls-pemfile" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" -dependencies = [ - "base64", - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" - -[[package]] -name = "rustls-webpki" -version = "0.102.4" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", + "base64 0.21.7", ] [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" @@ -1585,9 +1657,20 @@ version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ - "bitcoin_hashes", + "bitcoin_hashes 0.13.0", "rand", - "secp256k1-sys", + "secp256k1-sys 0.9.2", + "serde", +] + +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "bitcoin_hashes 0.13.0", + "secp256k1-sys 0.10.0", "serde", ] @@ -1600,6 +1683,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + [[package]] name = "secp256k1-zkp" version = "0.10.0" @@ -1607,7 +1699,7 @@ source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev= dependencies = [ "bitcoin-private", "rand", - "secp256k1", + "secp256k1 0.28.2", "secp256k1-zkp-sys", "serde", ] @@ -1618,16 +1710,16 @@ version = "0.9.1" source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24588a0c9e271badd61959294848c665d#60e631c24588a0c9e271badd61959294848c665d" dependencies = [ "cc", - "secp256k1-sys", + "secp256k1-sys 0.9.2", ] [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -1636,9 +1728,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -1712,7 +1804,7 @@ version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" dependencies = [ - "base64", + "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", @@ -1738,9 +1830,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1762,37 +1854,25 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.59" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -1846,18 +1926,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", @@ -1897,9 +1977,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -1951,21 +2031,22 @@ dependencies = [ ] [[package]] -name = "tokio-rustls" -version = "0.26.0" +name = "tokio-socks" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" dependencies = [ - "rustls", - "rustls-pki-types", + "either", + "futures-util", + "thiserror", "tokio", ] [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", @@ -1973,7 +2054,6 @@ dependencies = [ "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -2032,10 +2112,10 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "bytes", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", "http-body-util", "pin-project-lite", "tower-layer", @@ -2101,17 +2181,11 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -2120,15 +2194,15 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" dependencies = [ "getrandom", ] @@ -2389,25 +2463,19 @@ dependencies = [ [[package]] name = "winreg" -version = "0.52.0" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", "windows-sys 0.48.0", ] -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" - [[package]] name = "zeromq" -version = "0.4.0" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb0560d00172817b7f7c2265060783519c475702ae290b154115ca75e976d4d0" +checksum = "9ad3ffd65d6ae06a9eece312a64c3dfa2151a70a5c99051e2080828653cbda45" dependencies = [ "async-trait", "asynchronous-codec", diff --git a/Cargo.toml b/Cargo.toml index d045c0b..e23cf60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ diesel_migrations = "2.2.0" dotenvy = "0.15.7" env_logger = "0.11.3" log = "0.4.22" -zeromq = { version = "0.4.0", features = ["tokio", "tcp-transport"] } -reqwest = { version = "0.12.5", features = ["json"] } +zeromq = { version = "0.3.5", features = ["tokio", "tcp-transport"] } +reqwest = { version = "0.11.27", features = ["json"] } serde_json = "1.0.118" base64 = "0.22.1" serde = { version = "1.0.203", features = ["derive"] } @@ -32,6 +32,8 @@ crossbeam-channel = "0.5.13" r2d2 = "0.8.10" rayon = "1.10.0" num_cpus = "1.16.0" +esplora-client = { version = "0.9.0", default-features = false, features = ["async-https"] } +async-trait = "0.1.80" [patch.crates-io] secp256k1-zkp = { git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d" } diff --git a/src/chain/client.rs b/src/chain/client.rs index 6c08c41..530de34 100644 --- a/src/chain/client.rs +++ b/src/chain/client.rs @@ -1,6 +1,4 @@ -use std::error::Error; -use std::fs; - +use async_trait::async_trait; use base64::prelude::*; use crossbeam_channel::Receiver; use elements::{Block, Transaction}; @@ -9,8 +7,10 @@ use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize, Serializer}; use serde_json::json; +use std::error::Error; +use std::fs; -use crate::chain::types::{NetworkInfo, ZmqNotification}; +use crate::chain::types::{ChainDataProvider, NetworkInfo, ZmqNotification}; use crate::chain::zmq::ZmqClient; enum StringOrU64 { @@ -78,41 +78,6 @@ impl ChainClient { Ok(self) } - pub fn get_tx_receiver(self) -> Receiver { - self.zmq_client.tx_receiver.clone() - } - - pub fn get_block_receiver(self) -> Receiver { - self.zmq_client.block_receiver.clone() - } - - pub async fn get_block_count(self) -> Result> { - self.request::("getblockcount").await - } - - pub async fn get_block_hash(self, height: u64) -> Result> { - self.request_params::("getblockhash", vec![height]) - .await - } - - pub async fn get_block(self, hash: String) -> Result> { - let mut params = Vec::::new(); - params.push(StringOrU64::Str(hash)); - params.push(StringOrU64::Num(0)); - - let block_hex = self.request_params::("getblock", params).await?; - - Self::parse_hex(block_hex) - } - - pub async fn get_transaction(self, hash: String) -> Result> { - let tx_hex = self - .request_params::("getrawtransaction", vec![hash]) - .await?; - - Self::parse_hex(tx_hex) - } - pub async fn get_network_info(self) -> Result> { self.request::("getnetworkinfo").await } @@ -122,11 +87,6 @@ impl ChainClient { .await } - pub async fn send_raw_transaction(self, hex: String) -> Result> { - self.request_params::("sendrawtransaction", vec![hex]) - .await - } - async fn request(self, method: &str) -> Result> { self.request_params(method, Vec::::new()).await } @@ -182,3 +142,52 @@ impl ChainClient { } } } + +#[async_trait] +impl ChainDataProvider for ChainClient { + async fn get_block_count(&self) -> Result> { + self.clone().request::("getblockcount").await + } + + async fn get_block_hash(&self, height: u64) -> Result> { + self.clone() + .request_params::("getblockhash", vec![height]) + .await + } + + async fn get_block(&self, hash: String) -> Result> { + let mut params = Vec::::new(); + params.push(StringOrU64::Str(hash)); + params.push(StringOrU64::Num(0)); + + let block_hex = self + .clone() + .request_params::("getblock", params) + .await?; + + Self::parse_hex(block_hex) + } + + async fn send_raw_transaction(&self, hex: String) -> Result> { + self.clone() + .request_params::("sendrawtransaction", vec![hex]) + .await + } + + async fn get_transaction(&self, hash: String) -> Result> { + let tx_hex = self + .clone() + .request_params::("getrawtransaction", vec![hash]) + .await?; + + Self::parse_hex(tx_hex) + } + + fn get_tx_receiver(&self) -> Receiver { + self.zmq_client.tx_receiver.clone() + } + + fn get_block_receiver(&self) -> Receiver { + self.zmq_client.block_receiver.clone() + } +} diff --git a/src/chain/mod.rs b/src/chain/mod.rs index a8abba9..1570c55 100644 --- a/src/chain/mod.rs +++ b/src/chain/mod.rs @@ -1,3 +1,3 @@ pub mod client; -mod types; +pub mod types; mod zmq; diff --git a/src/chain/types.rs b/src/chain/types.rs index 6057c4a..54769da 100644 --- a/src/chain/types.rs +++ b/src/chain/types.rs @@ -1,4 +1,20 @@ +use axum::async_trait; +use crossbeam_channel::Receiver; +use elements::{Block, Transaction}; use serde::Deserialize; +use std::error::Error; + +#[async_trait] +pub trait ChainDataProvider { + async fn get_block_count(&self) -> Result>; + async fn get_block_hash(&self, height: u64) -> Result>; + async fn get_block(&self, hash: String) -> Result>; + async fn send_raw_transaction(&self, hex: String) -> Result>; + async fn get_transaction(&self, hash: String) -> Result>; + + fn get_tx_receiver(&self) -> Receiver; + fn get_block_receiver(&self) -> Receiver; +} #[derive(Debug, Clone, Deserialize)] pub struct NetworkInfo { diff --git a/src/claimer/constructor.rs b/src/claimer/constructor.rs index 34f48b7..bf8cfea 100644 --- a/src/claimer/constructor.rs +++ b/src/claimer/constructor.rs @@ -1,7 +1,4 @@ use diesel::internal::derives::multiconnection::chrono::{TimeDelta, Utc}; -use std::error::Error; -use std::ops::Sub; - use elements::bitcoin::Witness; use elements::confidential::{Asset, AssetBlindingFactor, Nonce, Value, ValueBlindingFactor}; use elements::script::Builder; @@ -12,9 +9,12 @@ use elements::{ TxOut, TxOutWitness, }; use log::{debug, error, info, trace, warn}; +use std::error::Error; +use std::ops::Sub; +use std::sync::Arc; use tokio::time; -use crate::chain::client::ChainClient; +use crate::chain::types::ChainDataProvider; use crate::claimer::tree::SwapTree; use crate::db; use crate::db::models::PendingCovenant; @@ -22,7 +22,7 @@ use crate::db::models::PendingCovenant; #[derive(Clone)] pub struct Constructor { db: db::Pool, - chain_client: ChainClient, + chain_client: Arc>, sweep_time: u64, sweep_interval: u64, address_params: &'static AddressParams, @@ -31,7 +31,7 @@ pub struct Constructor { impl Constructor { pub fn new( db: db::Pool, - chain_client: ChainClient, + chain_client: Arc>, sweep_time: u64, sweep_interval: u64, address_params: &'static AddressParams, @@ -322,7 +322,7 @@ impl Constructor { let tx_hex = hex::encode(elements::pset::serialize::Serialize::serialize(&tx)); trace!("Broadcasting transaction {}", tx_hex); - match self.chain_client.clone().send_raw_transaction(tx_hex).await { + match self.chain_client.send_raw_transaction(tx_hex).await { Ok(_) => match db::helpers::set_covenant_claimed(self.db, covenant.output_script) { Ok(_) => Ok(tx), Err(err) => Err(Box::new(err)), diff --git a/src/claimer/mod.rs b/src/claimer/mod.rs index e6ea398..f3029fb 100644 --- a/src/claimer/mod.rs +++ b/src/claimer/mod.rs @@ -1,14 +1,14 @@ use crossbeam_channel::Receiver; -use std::cmp; -use std::error::Error; - use elements::{AddressParams, Transaction}; use log::{debug, error, info, trace, warn}; use rayon::iter::IntoParallelRefIterator; use rayon::iter::ParallelIterator; +use std::cmp; +use std::error::Error; +use std::sync::Arc; use tokio::runtime::Builder; -use crate::chain::client::ChainClient; +use crate::chain::types::ChainDataProvider; use crate::claimer::constructor::Constructor; use crate::db; use crate::db::helpers::get_pending_covenant_for_output; @@ -21,14 +21,14 @@ const MAX_PARALLEL_REQUESTS: usize = 15; #[derive(Clone)] pub struct Claimer { db: db::Pool, - chain_client: ChainClient, + chain_client: Arc>, constructor: Constructor, } impl Claimer { pub fn new( db: db::Pool, - chain_client: ChainClient, + chain_client: Arc>, sweep_time: u64, sweep_interval: u64, address_param: &'static AddressParams, @@ -113,7 +113,7 @@ impl Claimer { } async fn rescan(self) -> Result> { - let block_count = self.chain_client.clone().get_block_count().await?; + let block_count = self.chain_client.get_block_count().await?; trace!("Current block height: {}", block_count); let rescan_height = match db::helpers::get_block_height(self.db.clone()) { @@ -156,26 +156,22 @@ impl Claimer { while let Ok(height) = receiver.recv() { let self_clone = self_clone.clone(); runtime.block_on(async move { - let block_hash = - match self_clone.chain_client.clone().get_block_hash(height).await { - Ok(res) => res, - Err(err) => { - error!("Could not get block hash of {}: {}", height, err); - return; - } - }; - let block = match self_clone - .chain_client - .clone() - .get_block(block_hash.clone()) - .await + let block_hash = match self_clone.chain_client.get_block_hash(height).await { Ok(res) => res, Err(err) => { - error!("Could not get block {}: {}", block_hash, err); + error!("Could not get block hash of {}: {}", height, err); return; } }; + let block = + match self_clone.chain_client.get_block(block_hash.clone()).await { + Ok(res) => res, + Err(err) => { + error!("Could not get block {}: {}", block_hash, err); + return; + } + }; debug!( "Rescanning block {} ({}) with {} transactions", diff --git a/src/main.rs b/src/main.rs index 1c14b48..c314646 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ -use std::env; - use dotenvy::dotenv; use elements::AddressParams; use log::{debug, error, info}; +use std::env; +use std::sync::Arc; mod api; mod chain; @@ -74,7 +74,7 @@ async fn main() { let claimer = claimer::Claimer::new( db.clone(), - elements, + Arc::new(Box::new(elements)), env::var("SWEEP_TIME") .expect("SWEEP_TIME must be set") .parse::() From 98d8c7f098db569d08a0abea66fe9318ec94ac29 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Fri, 28 Jun 2024 21:07:27 +0200 Subject: [PATCH 2/5] feat: Esplora chain backend --- .env | 14 +- Cargo.lock | 156 ++------------------ Cargo.toml | 1 - src/chain/client.rs | 29 +--- src/chain/esplora.rs | 294 +++++++++++++++++++++++++++++++++++++ src/chain/mod.rs | 2 + src/chain/types.rs | 3 +- src/chain/utils.rs | 14 ++ src/claimer/constructor.rs | 6 +- src/claimer/mod.rs | 6 +- src/main.rs | 76 +++++++--- 11 files changed, 404 insertions(+), 197 deletions(-) create mode 100644 src/chain/esplora.rs create mode 100644 src/chain/utils.rs diff --git a/.env b/.env index 0d2f762..5774ee3 100644 --- a/.env +++ b/.env @@ -8,13 +8,25 @@ SWEEP_TIME=120 SWEEP_INTERVAL=30 # Possible values: mainnet, testnet, regtest -NETWORK=regtest +NETWORK=mainnet # Rest API configuration API_HOST=127.0.0.1 API_PORT=1234 +# Chain backend to use +# Options: +# - elements +# - esplora +CHAIN_BACKEND=esplora + # Configuration of the Elements daemon to connect to ELEMENTS_HOST=127.0.0.1 ELEMENTS_PORT=18884 ELEMENTS_COOKIE=/home/michael/Git/TypeScript/boltz-backend/docker/regtest/data/core/cookies/.elements-cookie + +# Configuration of the Esplora backend +ESPLORA_ENDPOINT=https://blockstream.info/liquid/api + +# Poll interval for new blocks in seconds +ESPLORA_POLL_INTERVAL=10 diff --git a/Cargo.lock b/Cargo.lock index 925c0e3..de88165 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,12 +90,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - [[package]] name = "async-trait" version = "0.1.80" @@ -196,16 +190,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base58ck" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" -dependencies = [ - "bitcoin-internals 0.3.0", - "bitcoin_hashes 0.14.0", -] - [[package]] name = "base64" version = "0.21.7" @@ -224,42 +208,18 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" -[[package]] -name = "bech32" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" - [[package]] name = "bitcoin" version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" dependencies = [ - "bech32 0.10.0-beta", - "bitcoin-internals 0.2.0", - "bitcoin_hashes 0.13.0", - "hex-conservative 0.1.2", - "hex_lit", - "secp256k1 0.28.2", - "serde", -] - -[[package]] -name = "bitcoin" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" -dependencies = [ - "base58ck", - "bech32 0.11.0", - "bitcoin-internals 0.3.0", - "bitcoin-io", - "bitcoin-units", - "bitcoin_hashes 0.14.0", - "hex-conservative 0.2.1", + "bech32", + "bitcoin-internals", + "bitcoin_hashes", + "hex-conservative", "hex_lit", - "secp256k1 0.29.0", + "secp256k1", "serde", ] @@ -272,56 +232,20 @@ dependencies = [ "serde", ] -[[package]] -name = "bitcoin-internals" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" -dependencies = [ - "serde", -] - -[[package]] -name = "bitcoin-io" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" - [[package]] name = "bitcoin-private" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" -[[package]] -name = "bitcoin-units" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5" -dependencies = [ - "bitcoin-internals 0.3.0", - "serde", -] - [[package]] name = "bitcoin_hashes" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals 0.2.0", - "hex-conservative 0.1.2", - "serde", -] - -[[package]] -name = "bitcoin_hashes" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" -dependencies = [ - "bitcoin-io", - "hex-conservative 0.2.1", + "bitcoin-internals", + "hex-conservative", "serde", ] @@ -424,7 +348,6 @@ dependencies = [ "dotenvy", "elements", "env_logger", - "esplora-client", "hex", "log", "num_cpus", @@ -618,7 +541,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd6b8388053196e6b2702a45418078a654680ce9e1fd91799f51f67a40118ff5" dependencies = [ - "bitcoin 0.31.2", + "bitcoin", "secp256k1-zkp", "serde", "serde_json", @@ -672,19 +595,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "esplora-client" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b546e91283ebfc56337de34e0cf814e3ad98083afde593b8e58495ee5355d0e" -dependencies = [ - "bitcoin 0.32.2", - "hex-conservative 0.2.1", - "log", - "reqwest", - "serde", -] - [[package]] name = "fastrand" version = "2.1.0" @@ -871,15 +781,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" -[[package]] -name = "hex-conservative" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" -dependencies = [ - "arrayvec", -] - [[package]] name = "hex_lit" version = "0.1.1" @@ -1578,7 +1479,6 @@ dependencies = [ "system-configuration", "tokio", "tokio-native-tls", - "tokio-socks", "tower-service", "url", "wasm-bindgen", @@ -1657,20 +1557,9 @@ version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ - "bitcoin_hashes 0.13.0", + "bitcoin_hashes", "rand", - "secp256k1-sys 0.9.2", - "serde", -] - -[[package]] -name = "secp256k1" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" -dependencies = [ - "bitcoin_hashes 0.13.0", - "secp256k1-sys 0.10.0", + "secp256k1-sys", "serde", ] @@ -1683,15 +1572,6 @@ dependencies = [ "cc", ] -[[package]] -name = "secp256k1-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" -dependencies = [ - "cc", -] - [[package]] name = "secp256k1-zkp" version = "0.10.0" @@ -1699,7 +1579,7 @@ source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev= dependencies = [ "bitcoin-private", "rand", - "secp256k1 0.28.2", + "secp256k1", "secp256k1-zkp-sys", "serde", ] @@ -1710,7 +1590,7 @@ version = "0.9.1" source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24588a0c9e271badd61959294848c665d#60e631c24588a0c9e271badd61959294848c665d" dependencies = [ "cc", - "secp256k1-sys 0.9.2", + "secp256k1-sys", ] [[package]] @@ -2030,18 +1910,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-socks" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" -dependencies = [ - "either", - "futures-util", - "thiserror", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.11" diff --git a/Cargo.toml b/Cargo.toml index e23cf60..dbe9d07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,6 @@ crossbeam-channel = "0.5.13" r2d2 = "0.8.10" rayon = "1.10.0" num_cpus = "1.16.0" -esplora-client = { version = "0.9.0", default-features = false, features = ["async-https"] } async-trait = "0.1.80" [patch.crates-io] diff --git a/src/chain/client.rs b/src/chain/client.rs index 530de34..36a84ea 100644 --- a/src/chain/client.rs +++ b/src/chain/client.rs @@ -10,7 +10,7 @@ use serde_json::json; use std::error::Error; use std::fs; -use crate::chain::types::{ChainDataProvider, NetworkInfo, ZmqNotification}; +use crate::chain::types::{ChainBackend, NetworkInfo, ZmqNotification}; use crate::chain::zmq::ZmqClient; enum StringOrU64 { @@ -78,10 +78,6 @@ impl ChainClient { Ok(self) } - pub async fn get_network_info(self) -> Result> { - self.request::("getnetworkinfo").await - } - pub async fn get_zmq_notifications(self) -> Result, Box> { self.request::>("getzmqnotifications") .await @@ -128,23 +124,14 @@ impl ChainClient { Ok(res.result.unwrap()) } - - fn parse_hex(hex_str: String) -> Result> { - match elements::encode::deserialize( - match hex::decode(hex_str) { - Ok(res) => res, - Err(err) => return Err(Box::new(err)), - } - .as_ref(), - ) { - Ok(block) => Ok(block), - Err(e) => Err(Box::new(e)), - } - } } #[async_trait] -impl ChainDataProvider for ChainClient { +impl ChainBackend for ChainClient { + async fn get_network_info(&self) -> Result> { + self.clone().request::("getnetworkinfo").await + } + async fn get_block_count(&self) -> Result> { self.clone().request::("getblockcount").await } @@ -165,7 +152,7 @@ impl ChainDataProvider for ChainClient { .request_params::("getblock", params) .await?; - Self::parse_hex(block_hex) + crate::chain::utils::parse_hex(block_hex) } async fn send_raw_transaction(&self, hex: String) -> Result> { @@ -180,7 +167,7 @@ impl ChainDataProvider for ChainClient { .request_params::("getrawtransaction", vec![hash]) .await?; - Self::parse_hex(tx_hex) + crate::chain::utils::parse_hex(tx_hex) } fn get_tx_receiver(&self) -> Receiver { diff --git a/src/chain/esplora.rs b/src/chain/esplora.rs new file mode 100644 index 0000000..3a0c18a --- /dev/null +++ b/src/chain/esplora.rs @@ -0,0 +1,294 @@ +use std::error::Error; +use std::time::Duration; + +use async_trait::async_trait; +use crossbeam_channel::{Receiver, Sender}; +use elements::{Block, Transaction}; +use log::{error, info, warn}; +use reqwest::Response; +use serde::de::DeserializeOwned; +use tokio::{task, time}; + +use crate::chain::types::{ChainBackend, NetworkInfo}; + +#[derive(Debug, Clone)] +pub struct EsploraClient { + endpoint: String, + poll_interval: u64, + + // To keep the channel alive + // This is just a stub; streaming transactions is not supported with Esplora + #[allow(dead_code)] + tx_sender: Sender, + tx_receiver: Receiver, + + block_sender: Sender, + block_receiver: Receiver, +} + +impl EsploraClient { + pub fn new(endpoint: String, poll_interval: u64) -> Self { + let trimmed_endpoint = match endpoint.strip_suffix("/") { + Some(s) => s.to_string(), + None => endpoint, + }; + + let (tx_sender, tx_receiver) = crossbeam_channel::bounded::(1); + let (block_sender, block_receiver) = crossbeam_channel::unbounded::(); + + EsploraClient { + tx_sender, + tx_receiver, + block_sender, + block_receiver, + + poll_interval, + endpoint: trimmed_endpoint, + } + } + + pub fn connect(&self) { + let clone = self.clone(); + + task::spawn(async move { + info!( + "Polling for new blocks every {} seconds", + clone.poll_interval + ); + let mut interval = time::interval(Duration::from_secs(clone.poll_interval)); + + let mut last_known_block = match clone.get_block_count().await { + Ok(res) => res, + Err(err) => { + error!("Could not get latest block: {}", err); + return; + } + }; + + loop { + interval.tick().await; + + let latest_block = match clone.get_block_count().await { + Ok(res) => res, + Err(err) => { + warn!("Could not get latest block: {}", err); + continue; + } + }; + + for height in last_known_block + 1..latest_block + 1 { + let block_hash = match clone.get_block_hash(height).await { + Ok(hash) => hash, + Err(err) => { + warn!("Could not get block hash for height {}: {}", height, err); + continue; + } + }; + let block = match clone.get_block(block_hash.clone()).await { + Ok(block) => block, + Err(err) => { + warn!("Could not get block with hash {}: {}", block_hash, err); + continue; + } + }; + match clone.block_sender.send(block) { + Ok(_) => {} + Err(err) => { + warn!("Could not send block update: {}", err); + continue; + } + }; + } + + last_known_block = latest_block; + } + }); + } + + async fn request( + &self, + is_post: bool, + method: &str, + body: Option, + ) -> Result> { + Ok(self + .send_request(is_post, method, body) + .await? + .json::() + .await?) + } + + async fn request_string( + &self, + is_post: bool, + method: &str, + body: Option, + ) -> Result> { + Ok(self + .send_request(is_post, method, body) + .await? + .text() + .await?) + } + + async fn request_bytes( + &self, + is_post: bool, + method: &str, + body: Option, + ) -> Result, Box> { + Ok(self + .send_request(is_post, method, body) + .await? + .bytes() + .await? + .to_vec()) + } + + async fn send_request( + &self, + is_post: bool, + method: &str, + body: Option, + ) -> Result { + let url = format!("{}/{}", self.endpoint, method); + + let client = reqwest::Client::new(); + let mut req = match is_post { + true => client.post(url), + false => client.get(url), + }; + + if body.is_some() { + req = req.body(body.unwrap()) + } + + let res = req.send().await?; + match res.error_for_status() { + Ok(res) => Ok(res), + Err(err) => Err(err), + } + } +} + +#[async_trait] +impl ChainBackend for EsploraClient { + async fn get_network_info(&self) -> Result> { + // Send some request to make the endpoint is valid + self.get_block_count().await?; + + return Ok(NetworkInfo { + subversion: "Esplora".to_string(), + }); + } + + async fn get_block_count(&self) -> Result> { + self.request::(false, "blocks/tip/height", None).await + } + + async fn get_block_hash(&self, height: u64) -> Result> { + self.request_string(false, format!("block-height/{}", height).as_str(), None) + .await + } + + async fn get_block(&self, hash: String) -> Result> { + let block_hex = self + .request_bytes(false, format!("block/{}/raw", hash).as_str(), None) + .await?; + Ok(elements::encode::deserialize(&block_hex)?) + } + + async fn send_raw_transaction(&self, hex: String) -> Result> { + self.request_string(true, "/tx", Some(hex)).await + } + + async fn get_transaction(&self, hash: String) -> Result> { + let tx_hex = self + .request_bytes(false, format!("tx/{}/raw", hash).as_str(), None) + .await?; + Ok(elements::encode::deserialize(&tx_hex)?) + } + + fn get_tx_receiver(&self) -> Receiver { + return self.tx_receiver.clone(); + } + + fn get_block_receiver(&self) -> Receiver { + return self.block_receiver.clone(); + } +} + +#[cfg(test)] +mod esplora_client_test { + use crate::chain::esplora::EsploraClient; + use crate::chain::types::ChainBackend; + + const ENDPOINT: &str = "https://blockstream.info/liquid/api/"; + + #[test] + fn test_trim_suffix() { + assert_eq!( + EsploraClient::new(ENDPOINT.to_string(), 0).endpoint, + "https://blockstream.info/liquid/api" + ); + assert_eq!( + EsploraClient::new("https://blockstream.info/liquid/api".to_string(), 0).endpoint, + "https://blockstream.info/liquid/api" + ); + } + + #[tokio::test] + async fn test_new() { + let client = EsploraClient::new(ENDPOINT.to_string(), 0); + + let info = client.get_network_info().await.unwrap(); + assert_eq!(info.subversion, "Esplora"); + } + + #[tokio::test] + async fn test_get_block_count() { + let client = EsploraClient::new(ENDPOINT.to_string(), 0); + + let count = client.get_block_count().await.unwrap(); + assert!(count > 2920403); + } + + #[tokio::test] + async fn test_get_block_hash() { + let client = EsploraClient::new(ENDPOINT.to_string(), 0); + + let hash = client.get_block_hash(2920407).await.unwrap(); + assert_eq!( + hash, + "4a1f9addaea74ef4132005fa1411abebb3f968b8cb766af93547c77b6207d619" + ); + } + + #[tokio::test] + async fn test_get_block() { + let client = EsploraClient::new(ENDPOINT.to_string(), 0); + + let block_hash = "5510868513d80a64371cdedfef49327dc2cd452b32b93cbcd70ddeddcc7bef66"; + let block = client.get_block(block_hash.to_string()).await.unwrap(); + assert_eq!(block.block_hash().to_string(), block_hash); + assert_eq!(block.txdata.len(), 3); + } + + #[tokio::test] + async fn test_get_transaction() { + let client = EsploraClient::new(ENDPOINT.to_string(), 0); + + let tx_hash = "dc2505641c10af5fe0ffd8f1bfc14e9608e73137009c69b6ee0d1fe8ce9784d6"; + let block = client.get_transaction(tx_hash.to_string()).await.unwrap(); + assert_eq!(block.txid().to_string(), tx_hash); + } + + #[tokio::test] + async fn test_get_transaction_not_found() { + let client = EsploraClient::new(ENDPOINT.to_string(), 0); + + let tx_hash = "not found"; + let block = client.get_transaction(tx_hash.to_string()).await; + assert!(block.err().is_some()); + } +} diff --git a/src/chain/mod.rs b/src/chain/mod.rs index 1570c55..c942892 100644 --- a/src/chain/mod.rs +++ b/src/chain/mod.rs @@ -1,3 +1,5 @@ pub mod client; +pub mod esplora; pub mod types; +mod utils; mod zmq; diff --git a/src/chain/types.rs b/src/chain/types.rs index 54769da..73f6441 100644 --- a/src/chain/types.rs +++ b/src/chain/types.rs @@ -5,7 +5,8 @@ use serde::Deserialize; use std::error::Error; #[async_trait] -pub trait ChainDataProvider { +pub trait ChainBackend { + async fn get_network_info(&self) -> Result>; async fn get_block_count(&self) -> Result>; async fn get_block_hash(&self, height: u64) -> Result>; async fn get_block(&self, hash: String) -> Result>; diff --git a/src/chain/utils.rs b/src/chain/utils.rs new file mode 100644 index 0000000..d2584ea --- /dev/null +++ b/src/chain/utils.rs @@ -0,0 +1,14 @@ +use std::error::Error; + +pub fn parse_hex(hex_str: String) -> Result> { + match elements::encode::deserialize( + match hex::decode(hex_str) { + Ok(res) => res, + Err(err) => return Err(Box::new(err)), + } + .as_ref(), + ) { + Ok(block) => Ok(block), + Err(e) => Err(Box::new(e)), + } +} diff --git a/src/claimer/constructor.rs b/src/claimer/constructor.rs index bf8cfea..fd2231a 100644 --- a/src/claimer/constructor.rs +++ b/src/claimer/constructor.rs @@ -14,7 +14,7 @@ use std::ops::Sub; use std::sync::Arc; use tokio::time; -use crate::chain::types::ChainDataProvider; +use crate::chain::types::ChainBackend; use crate::claimer::tree::SwapTree; use crate::db; use crate::db::models::PendingCovenant; @@ -22,7 +22,7 @@ use crate::db::models::PendingCovenant; #[derive(Clone)] pub struct Constructor { db: db::Pool, - chain_client: Arc>, + chain_client: Arc>, sweep_time: u64, sweep_interval: u64, address_params: &'static AddressParams, @@ -31,7 +31,7 @@ pub struct Constructor { impl Constructor { pub fn new( db: db::Pool, - chain_client: Arc>, + chain_client: Arc>, sweep_time: u64, sweep_interval: u64, address_params: &'static AddressParams, diff --git a/src/claimer/mod.rs b/src/claimer/mod.rs index f3029fb..e3931ac 100644 --- a/src/claimer/mod.rs +++ b/src/claimer/mod.rs @@ -8,7 +8,7 @@ use std::error::Error; use std::sync::Arc; use tokio::runtime::Builder; -use crate::chain::types::ChainDataProvider; +use crate::chain::types::ChainBackend; use crate::claimer::constructor::Constructor; use crate::db; use crate::db::helpers::get_pending_covenant_for_output; @@ -21,14 +21,14 @@ const MAX_PARALLEL_REQUESTS: usize = 15; #[derive(Clone)] pub struct Claimer { db: db::Pool, - chain_client: Arc>, + chain_client: Arc>, constructor: Constructor, } impl Claimer { pub fn new( db: db::Pool, - chain_client: Arc>, + chain_client: Arc>, sweep_time: u64, sweep_interval: u64, address_param: &'static AddressParams, diff --git a/src/main.rs b/src/main.rs index c314646..61491e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ +use std::env; +use std::sync::Arc; + use dotenvy::dotenv; use elements::AddressParams; use log::{debug, error, info}; -use std::env; -use std::sync::Arc; + +use crate::chain::types::ChainBackend; mod api; mod chain; @@ -44,37 +47,21 @@ async fn main() { }; info!("Connected to database"); - let elements = match chain::client::ChainClient::new( - env::var("ELEMENTS_HOST").expect("ELEMENTS_HOST must be set"), - env::var("ELEMENTS_PORT") - .expect("ELEMENTS_PORT must be est") - .parse::() - .expect("ELEMENTS_PORT invalid"), - env::var("ELEMENTS_COOKIE").expect("ELEMENTS_COOKIE must be set"), - ) - .connect() - .await - { - Ok(client) => client, - Err(err) => { - error!("Could not connect to Elements client: {}", err); - std::process::exit(1); - } - }; + let elements = get_chain_backend().await; - let connect_res = match elements.clone().get_network_info().await { + let connect_res = match elements.get_network_info().await { Ok(res) => res, Err(err) => { - error!("Could not connect to Elements: {}", err); + error!("Could not connect to chain backend: {}", err); std::process::exit(1); } }; - info!("Connected to Elements: {}", connect_res.subversion); + info!("Connected to chain backend: {}", connect_res.subversion); let claimer = claimer::Claimer::new( db.clone(), - Arc::new(Box::new(elements)), + elements, env::var("SWEEP_TIME") .expect("SWEEP_TIME must be set") .parse::() @@ -99,6 +86,49 @@ async fn main() { server.await.unwrap().expect("could not start server"); } +async fn get_chain_backend() -> Arc> { + let backend = env::var("CHAIN_BACKEND").unwrap_or("elements".to_string()); + info!("Using {} chain backend", backend); + let client: Box = match backend.as_str() { + "elements" => { + match chain::client::ChainClient::new( + env::var("ELEMENTS_HOST").expect("ELEMENTS_HOST must be set"), + env::var("ELEMENTS_PORT") + .expect("ELEMENTS_PORT must be est") + .parse::() + .expect("ELEMENTS_PORT invalid"), + env::var("ELEMENTS_COOKIE").expect("ELEMENTS_COOKIE must be set"), + ) + .connect() + .await + { + Ok(client) => Box::new(client), + Err(err) => { + error!("Could not connect to Elements client: {}", err); + std::process::exit(1); + } + } + } + "esplora" => { + let client = chain::esplora::EsploraClient::new( + env::var("ESPLORA_ENDPOINT").expect("ESPLORA_ENDPOINT must be set"), + env::var("ESPLORA_POLL_INTERVAL") + .expect("ESPLORA_POLL_INTERVAL must be set") + .parse::() + .expect("ESPLORA_POLL_INTERVAL invalid"), + ); + client.connect(); + Box::new(client) + } + &_ => { + error!("Unknown chain backend: {}", backend); + std::process::exit(1); + } + }; + + return Arc::new(client); +} + fn get_address_params() -> &'static AddressParams { let network = env::var("NETWORK").expect("NETWORK must be set"); debug!("Using network: {network}"); From 462cf73d62da9f6d658e824a410e1bc8085b1029 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Fri, 28 Jun 2024 21:28:02 +0200 Subject: [PATCH 3/5] chore: run CI on all branches --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77e8aeb..b19838f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,6 @@ name: CI -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] +on: [ push, pull_request ] env: CARGO_TERM_COLOR: always From c1fa08a4053ad09b8b427415fcd3e57235787133 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Fri, 28 Jun 2024 21:51:17 +0200 Subject: [PATCH 4/5] feat: Esplora request rate limiter --- .env | 4 +++ Cargo.lock | 45 ++++++++++++++++++++++++ Cargo.toml | 1 + src/chain/esplora.rs | 82 ++++++++++++++++++++++++++++++++++++-------- src/main.rs | 23 +++++++++---- 5 files changed, 134 insertions(+), 21 deletions(-) diff --git a/.env b/.env index 5774ee3..3f77dc8 100644 --- a/.env +++ b/.env @@ -30,3 +30,7 @@ ESPLORA_ENDPOINT=https://blockstream.info/liquid/api # Poll interval for new blocks in seconds ESPLORA_POLL_INTERVAL=10 + +# Max reqs/second for the Esplora endpoint; useful when hitting rate limits +# Set to 0 to disable +ESPLORA_MAX_REQUESTS_PER_SECOND=5 diff --git a/Cargo.lock b/Cargo.lock index de88165..db514c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,6 +312,17 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "clocksource" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "129026dd5a8a9592d96916258f3a5379589e513ea5e86aeb0bd2530286e44e9e" +dependencies = [ + "libc", + "time", + "winapi", +] + [[package]] name = "colorchoice" version = "1.0.1" @@ -352,6 +363,7 @@ dependencies = [ "log", "num_cpus", "r2d2", + "ratelimit", "rayon", "reqwest", "serde", @@ -1389,6 +1401,17 @@ dependencies = [ "getrandom", ] +[[package]] +name = "ratelimit" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c1bb13e2dcfa2232ac6887157aad8d9b3fe4ca57f7c8d4938ff5ea9be742300" +dependencies = [ + "clocksource", + "parking_lot", + "thiserror", +] + [[package]] name = "rayon" version = "1.10.0" @@ -2172,6 +2195,28 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index dbe9d07..090f657 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ r2d2 = "0.8.10" rayon = "1.10.0" num_cpus = "1.16.0" async-trait = "0.1.80" +ratelimit = "0.9.1" [patch.crates-io] secp256k1-zkp = { git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d" } diff --git a/src/chain/esplora.rs b/src/chain/esplora.rs index 3a0c18a..e5f4f81 100644 --- a/src/chain/esplora.rs +++ b/src/chain/esplora.rs @@ -1,21 +1,25 @@ use std::error::Error; +use std::sync::Arc; use std::time::Duration; use async_trait::async_trait; use crossbeam_channel::{Receiver, Sender}; use elements::{Block, Transaction}; -use log::{error, info, warn}; +use log::{error, info, trace, warn}; +use ratelimit::Ratelimiter; use reqwest::Response; use serde::de::DeserializeOwned; use tokio::{task, time}; use crate::chain::types::{ChainBackend, NetworkInfo}; -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct EsploraClient { endpoint: String, poll_interval: u64, + rate_limit: Option>, + // To keep the channel alive // This is just a stub; streaming transactions is not supported with Esplora #[allow(dead_code)] @@ -27,7 +31,11 @@ pub struct EsploraClient { } impl EsploraClient { - pub fn new(endpoint: String, poll_interval: u64) -> Self { + pub fn new( + endpoint: String, + poll_interval: u64, + max_reqs_per_second: u64, + ) -> Result> { let trimmed_endpoint = match endpoint.strip_suffix("/") { Some(s) => s.to_string(), None => endpoint, @@ -36,15 +44,32 @@ impl EsploraClient { let (tx_sender, tx_receiver) = crossbeam_channel::bounded::(1); let (block_sender, block_receiver) = crossbeam_channel::unbounded::(); - EsploraClient { + let rate_limit: Option>; + + if max_reqs_per_second > 0 { + info!( + "Rate limiting requests at {} requests/second", + max_reqs_per_second + ); + rate_limit = Some(Arc::new( + Ratelimiter::builder(max_reqs_per_second, Duration::from_secs(1)) + .max_tokens(max_reqs_per_second) + .build()?, + )); + } else { + info!("Not rate limiting"); + rate_limit = None; + } + + Ok(EsploraClient { tx_sender, + rate_limit, tx_receiver, block_sender, - block_receiver, - poll_interval, + block_receiver, endpoint: trimmed_endpoint, - } + }) } pub fn connect(&self) { @@ -91,6 +116,11 @@ impl EsploraClient { continue; } }; + trace!( + "Got block {} ({})", + block.header.height, + block.header.block_hash() + ); match clone.block_sender.send(block) { Ok(_) => {} Err(err) => { @@ -163,12 +193,30 @@ impl EsploraClient { req = req.body(body.unwrap()) } + self.wait_rate_limit(); let res = req.send().await?; match res.error_for_status() { Ok(res) => Ok(res), Err(err) => Err(err), } } + + fn wait_rate_limit(&self) { + if self.rate_limit.is_none() { + return; + } + + loop { + match self.rate_limit.clone().unwrap().try_wait() { + Ok(_) => { + break; + } + Err(time) => { + std::thread::sleep(time); + } + } + } + } } #[async_trait] @@ -228,18 +276,22 @@ mod esplora_client_test { #[test] fn test_trim_suffix() { assert_eq!( - EsploraClient::new(ENDPOINT.to_string(), 0).endpoint, + EsploraClient::new(ENDPOINT.to_string(), 0, 0) + .unwrap() + .endpoint, "https://blockstream.info/liquid/api" ); assert_eq!( - EsploraClient::new("https://blockstream.info/liquid/api".to_string(), 0).endpoint, + EsploraClient::new("https://blockstream.info/liquid/api".to_string(), 0, 0) + .unwrap() + .endpoint, "https://blockstream.info/liquid/api" ); } #[tokio::test] async fn test_new() { - let client = EsploraClient::new(ENDPOINT.to_string(), 0); + let client = EsploraClient::new(ENDPOINT.to_string(), 0, 0).unwrap(); let info = client.get_network_info().await.unwrap(); assert_eq!(info.subversion, "Esplora"); @@ -247,7 +299,7 @@ mod esplora_client_test { #[tokio::test] async fn test_get_block_count() { - let client = EsploraClient::new(ENDPOINT.to_string(), 0); + let client = EsploraClient::new(ENDPOINT.to_string(), 0, 0).unwrap(); let count = client.get_block_count().await.unwrap(); assert!(count > 2920403); @@ -255,7 +307,7 @@ mod esplora_client_test { #[tokio::test] async fn test_get_block_hash() { - let client = EsploraClient::new(ENDPOINT.to_string(), 0); + let client = EsploraClient::new(ENDPOINT.to_string(), 0, 0).unwrap(); let hash = client.get_block_hash(2920407).await.unwrap(); assert_eq!( @@ -266,7 +318,7 @@ mod esplora_client_test { #[tokio::test] async fn test_get_block() { - let client = EsploraClient::new(ENDPOINT.to_string(), 0); + let client = EsploraClient::new(ENDPOINT.to_string(), 0, 0).unwrap(); let block_hash = "5510868513d80a64371cdedfef49327dc2cd452b32b93cbcd70ddeddcc7bef66"; let block = client.get_block(block_hash.to_string()).await.unwrap(); @@ -276,7 +328,7 @@ mod esplora_client_test { #[tokio::test] async fn test_get_transaction() { - let client = EsploraClient::new(ENDPOINT.to_string(), 0); + let client = EsploraClient::new(ENDPOINT.to_string(), 0, 0).unwrap(); let tx_hash = "dc2505641c10af5fe0ffd8f1bfc14e9608e73137009c69b6ee0d1fe8ce9784d6"; let block = client.get_transaction(tx_hash.to_string()).await.unwrap(); @@ -285,7 +337,7 @@ mod esplora_client_test { #[tokio::test] async fn test_get_transaction_not_found() { - let client = EsploraClient::new(ENDPOINT.to_string(), 0); + let client = EsploraClient::new(ENDPOINT.to_string(), 0, 0).unwrap(); let tx_hash = "not found"; let block = client.get_transaction(tx_hash.to_string()).await; diff --git a/src/main.rs b/src/main.rs index 61491e6..bfa0252 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,12 @@ use std::env; use std::sync::Arc; +use crate::chain::esplora::EsploraClient; +use crate::chain::types::ChainBackend; use dotenvy::dotenv; use elements::AddressParams; use log::{debug, error, info}; -use crate::chain::types::ChainBackend; - mod api; mod chain; mod claimer; @@ -110,15 +110,26 @@ async fn get_chain_backend() -> Arc> { } } "esplora" => { - let client = chain::esplora::EsploraClient::new( + match EsploraClient::new( env::var("ESPLORA_ENDPOINT").expect("ESPLORA_ENDPOINT must be set"), env::var("ESPLORA_POLL_INTERVAL") .expect("ESPLORA_POLL_INTERVAL must be set") .parse::() .expect("ESPLORA_POLL_INTERVAL invalid"), - ); - client.connect(); - Box::new(client) + env::var("ESPLORA_MAX_REQUESTS_PER_SECOND") + .expect("ESPLORA_MAX_REQUESTS_PER_SECOND must be set") + .parse::() + .expect("ESPLORA_MAX_REQUESTS_PER_SECOND invalid"), + ) { + Ok(client) => { + client.connect(); + Box::new(client) + } + Err(err) => { + error!("Could not create Esplora client: {}", err); + std::process::exit(1); + } + } } &_ => { error!("Unknown chain backend: {}", backend); From 6d9c12da43250bb5b0054403fd70916239db8d8d Mon Sep 17 00:00:00 2001 From: michael1011 Date: Fri, 28 Jun 2024 21:56:49 +0200 Subject: [PATCH 5/5] chore: update README --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 81a3bf1..3b79f5f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # covclaim -This is a daemon that connects to Elements via RPC and ZMQ and watches the chain for claimable covenants of Boltz reverse swaps and broadcasts them. +This is a daemon that connects to Elements via RPC and ZMQ or an Esplora REST API and watches the chain for claimable +covenants of Boltz swaps and broadcasts them. + +## Building + +The latest stable version of Rust is required to build covclaim. + +```bash +cargo build --release +``` ## Configuration