diff --git a/Cargo.lock b/Cargo.lock index 3adf9c8..459a725 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -339,6 +339,29 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "backuplit" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2dae796e5f2385c46b9dcb7ac25ec6d3929a05b98953a98bec3bc5cc9bf319" +dependencies = [ + "anyhow", + "clap", + "flate2", + "google-cloud", + "inotify", + "tar", + "tokio", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + [[package]] name = "base64" version = "0.13.1" @@ -696,9 +719,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -718,9 +741,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -783,6 +806,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -814,6 +846,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "ct-logs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" +dependencies = [ + "sct 0.6.1", +] + [[package]] name = "darling" version = "0.20.8" @@ -1069,6 +1110,7 @@ dependencies = [ "axum", "axum-macros", "axum-otel-metrics", + "backuplit", "bitcoin 0.29.2", "bitcoin_hashes 0.13.0", "chrono", @@ -1082,6 +1124,8 @@ dependencies = [ "fedimint-rocksdb", "fedimint-wallet-client", "futures-util", + "google-cloud", + "inotify", "itertools 0.12.1", "lazy_static", "lightning-invoice", @@ -1446,6 +1490,34 @@ dependencies = [ "subtle", ] +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys 0.52.0", +] + +[[package]] +name = "fixedbitset" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" + +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1674,6 +1746,30 @@ dependencies = [ "web-sys", ] +[[package]] +name = "google-cloud" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a517f0235af652d334a021b81aa2e8f18a77512c26be18722debb7d405912f80" +dependencies = [ + "chrono", + "futures", + "http 0.2.12", + "hyper 0.14.28", + "hyper-rustls 0.22.1", + "jsonwebtoken", + "percent-encoding", + "prost", + "prost-types", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tonic", + "tonic-build", +] + [[package]] name = "group" version = "0.12.1" @@ -1697,10 +1793,10 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap", + "indexmap 2.2.5", "slab", "tokio", - "tokio-util", + "tokio-util 0.7.10", "tracing", ] @@ -1716,10 +1812,10 @@ dependencies = [ "futures-sink", "futures-util", "http 1.1.0", - "indexmap", + "indexmap 2.2.5", "slab", "tokio", - "tokio-util", + "tokio-util 0.7.10", "tracing", ] @@ -1733,6 +1829,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.3" @@ -1743,6 +1845,15 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "heck" version = "0.4.1" @@ -1788,6 +1899,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -1900,6 +2020,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "hyper-rustls" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" +dependencies = [ + "ct-logs", + "futures-util", + "hyper 0.14.28", + "log", + "rustls 0.19.1", + "rustls-native-certs", + "tokio", + "tokio-rustls 0.22.0", + "webpki 0.21.4", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -2058,6 +2195,16 @@ dependencies = [ "quote", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + [[package]] name = "indexmap" version = "2.2.5" @@ -2068,6 +2215,28 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "inotify" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdd168d97690d0b8c412d6b6c10360277f4d7ee495c5d0d5d5fe0854923255cc" +dependencies = [ + "bitflags 1.3.2", + "futures-core", + "inotify-sys", + "libc", + "tokio", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "inout" version = "0.1.3" @@ -2084,6 +2253,15 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.10.5" @@ -2155,7 +2333,7 @@ dependencies = [ "thiserror", "tokio", "tokio-rustls 0.25.0", - "tokio-util", + "tokio-util 0.7.10", "tracing", "url", "webpki-roots 0.26.1", @@ -2222,6 +2400,20 @@ dependencies = [ "url", ] +[[package]] +name = "jsonwebtoken" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afabcc15e437a6484fc4f12d0fd63068fe457bf93f1c148d3d9649c60b103f32" +dependencies = [ + "base64 0.12.3", + "pem", + "ring 0.16.20", + "serde", + "serde_json", + "simple_asn1", +] + [[package]] name = "keccak" version = "0.1.5" @@ -2461,6 +2653,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + [[package]] name = "multimint" version = "0.1.13" @@ -2519,12 +2717,32 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -2617,7 +2835,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap", + "indexmap 2.2.5", "js-sys", "once_cell", "pin-project-lite", @@ -2765,12 +2983,33 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pem" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" +dependencies = [ + "base64 0.13.1", + "once_cell", + "regex", +] + [[package]] name = "percent-encoding" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petgraph" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +dependencies = [ + "fixedbitset", + "indexmap 1.9.3", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -2879,6 +3118,57 @@ dependencies = [ "thiserror", ] +[[package]] +name = "prost" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e6984d2f1a23009bd270b8bb56d0926810a3d483f59c987d77969e9d8e840b2" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d3ebd75ac2679c2af3a92246639f9fcc8a442ee420719cc4fe195b98dd5fa3" +dependencies = [ + "bytes", + "heck 0.3.3", + "itertools 0.9.0", + "log", + "multimap", + "petgraph", + "prost", + "prost-types", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "169a15f3008ecb5160cba7d37bcd690a7601b6d30cfb87a117d45e59d52af5d4" +dependencies = [ + "anyhow", + "itertools 0.9.0", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-types" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b518d7cdd93dab1d1122cf07fa9a60771836c668dde9d9e2a139f957f0d9f1bb" +dependencies = [ + "bytes", + "prost", +] + [[package]] name = "protobuf" version = "2.28.0" @@ -3007,7 +3297,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-rustls", + "hyper-rustls 0.24.2", "hyper-tls", "ipnet", "js-sys", @@ -3102,6 +3392,19 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64 0.13.1", + "log", + "ring 0.16.20", + "sct 0.6.1", + "webpki 0.21.4", +] + [[package]] name = "rustls" version = "0.20.9" @@ -3110,8 +3413,8 @@ checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", "ring 0.16.20", - "sct", - "webpki", + "sct 0.7.1", + "webpki 0.22.4", ] [[package]] @@ -3123,7 +3426,7 @@ dependencies = [ "log", "ring 0.17.8", "rustls-webpki 0.101.7", - "sct", + "sct 0.7.1", ] [[package]] @@ -3140,6 +3443,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092" +dependencies = [ + "openssl-probe", + "rustls 0.19.1", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -3203,6 +3518,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring 0.16.20", + "untrusted 0.7.1", +] + [[package]] name = "sct" version = "0.7.1" @@ -3426,6 +3751,17 @@ dependencies = [ "libc", ] +[[package]] +name = "simple_asn1" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692ca13de57ce0613a363c8c2f1de925adebc81b04c923ac60c5488bb44abe4b" +dependencies = [ + "chrono", + "num-bigint", + "num-traits", +] + [[package]] name = "slab" version = "0.4.9" @@ -3570,6 +3906,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tar" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.10.1" @@ -3669,9 +4016,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.36.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -3708,6 +4055,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" +dependencies = [ + "rustls 0.19.1", + "tokio", + "webpki 0.21.4", +] + [[package]] name = "tokio-rustls" version = "0.23.4" @@ -3716,7 +4074,7 @@ checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ "rustls 0.20.9", "tokio", - "webpki", + "webpki 0.22.4", ] [[package]] @@ -3761,7 +4119,7 @@ dependencies = [ "futures-core", "pin-project-lite", "tokio", - "tokio-util", + "tokio-util 0.7.10", ] [[package]] @@ -3776,6 +4134,20 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "tokio-util" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -3803,11 +4175,53 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ - "indexmap", + "indexmap 2.2.5", "toml_datetime", "winnow", ] +[[package]] +name = "tonic" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ac42cd97ac6bd2339af5bcabf105540e21e45636ec6fa6aae5e85d44db31be0" +dependencies = [ + "async-stream", + "async-trait", + "base64 0.13.1", + "bytes", + "futures-core", + "futures-util", + "h2 0.3.25", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", + "percent-encoding", + "pin-project", + "prost", + "prost-derive", + "tokio", + "tokio-rustls 0.22.0", + "tokio-stream", + "tokio-util 0.6.10", + "tower", + "tower-service", + "tracing", + "tracing-futures", +] + +[[package]] +name = "tonic-build" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c695de27302f4697191dda1c7178131a8cb805463dda02864acb80fe1322fdcf" +dependencies = [ + "proc-macro2", + "prost-build", + "quote", + "syn 1.0.109", +] + [[package]] name = "tower" version = "0.4.13" @@ -3816,9 +4230,13 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "indexmap 1.9.3", "pin-project", "pin-project-lite", + "rand", + "slab", "tokio", + "tokio-util 0.7.10", "tower-layer", "tower-service", "tracing", @@ -3888,6 +4306,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "tracing-log" version = "0.2.0" @@ -3969,6 +4397,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "untrusted" version = "0.7.1" @@ -4150,6 +4584,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring 0.16.20", + "untrusted 0.7.1", +] + [[package]] name = "webpki" version = "0.22.4" @@ -4175,6 +4619,18 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -4366,6 +4822,17 @@ dependencies = [ "tap", ] +[[package]] +name = "xattr" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" +dependencies = [ + "libc", + "linux-raw-sys", + "rustix", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/Cargo.toml b/Cargo.toml index 63865f1..f8adb42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,3 @@ [workspace] -members = [ - "multimint", - "fedimint-clientd", -] +members = ["multimint", "fedimint-clientd"] resolver = "2" diff --git a/fedimint-clientd/Cargo.toml b/fedimint-clientd/Cargo.toml index 48bc684..5519f92 100644 --- a/fedimint-clientd/Cargo.toml +++ b/fedimint-clientd/Cargo.toml @@ -40,3 +40,6 @@ futures-util = "0.3.30" clap = { version = "4.4.13", features = ["derive", "env"] } multimint = { path = "../multimint" } axum-otel-metrics = "0.8.0" +inotify = "0.10.2" +google-cloud = { version = "0.2.1", features = ["storage"] } +backuplit = "0.1.0" diff --git a/fedimint-clientd/src/main.rs b/fedimint-clientd/src/main.rs index b97b894..40aa50a 100644 --- a/fedimint-clientd/src/main.rs +++ b/fedimint-clientd/src/main.rs @@ -24,6 +24,8 @@ use state::AppState; // use tower_http::cors::{Any, CorsLayer}; use tower_http::validate_request::ValidateRequestHeaderLayer; +use crate::utils::start_backup_daemon; + #[derive(Clone, Debug, ValueEnum, PartialEq)] enum Mode { Rest, @@ -63,6 +65,58 @@ struct Cli { /// Mode: ws, rest #[clap(long, env = "FEDIMINT_CLIENTD_MODE", default_value = "rest")] mode: Mode, + + /// Enable Google Cloud backup + #[clap(long, env = "USE_GOOGLE_CLOUD_BACKUP")] + use_google_cloud_backup: bool, + + /// Google Cloud Storage Bucket ID + #[clap( + long, + env = "GOOGLE_CLOUD_BACKUP_BUCKET_ID", + required_if_eq("use_google_cloud_backup", "true") + )] + google_cloud_backup_bucket_id: Option, + + /// Google Cloud Storage Credentials + #[clap( + long, + env = "GOOGLE_CLOUD_BACKUP_CREDENTIALS", + required_if_eq("use_google_cloud_backup", "true") + )] + google_cloud_backup_credentials: Option, + + /// Google Cloud Storage Backup Name + #[clap( + long, + env = "GOOGLE_CLOUD_BACKUP_NAME", + required_if_eq("use_google_cloud_backup", "true") + )] + google_cloud_backup_name: Option, + + /// Google Cloud Storage Backup Trigger + #[clap( + long, + env = "GOOGLE_CLOUD_BACKUP_TRIGGER", + required_if_eq("use_google_cloud_backup", "true") + )] + google_cloud_backup_trigger: Option, + + /// Google Cloud Backup Interval Type (seconds, minutes, hours, days) + #[clap( + long, + env = "GOOGLE_CLOUD_BACKUP_INTERVAL_TYPE", + required_if_eq("use_google_cloud_backup", "true") + )] + google_cloud_backup_interval_type: Option, + + /// Google Cloud Backup Interval Value + #[clap( + long, + env = "GOOGLE_CLOUD_BACKUP_INTERVAL_VALUE", + required_if_eq("use_google_cloud_backup", "true") + )] + google_cloud_backup_interval_value: Option, } // const PID_FILE: &str = "/tmp/fedimint_http.pid"; @@ -73,8 +127,9 @@ async fn main() -> Result<()> { dotenv::dotenv().ok(); let cli: Cli = Cli::parse(); + start_backup_daemon(&cli).await?; - let mut state = AppState::new(cli.db_path).await?; + let mut state = AppState::new(cli.db_path.clone()).await?; let manual_secret = match cli.manual_secret { Some(secret) => Some(secret), diff --git a/fedimint-clientd/src/utils.rs b/fedimint-clientd/src/utils.rs index 5321a72..cd1413a 100644 --- a/fedimint-clientd/src/utils.rs +++ b/fedimint-clientd/src/utils.rs @@ -1,6 +1,9 @@ -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use anyhow::{anyhow, Result}; +use backuplit::{BackupTrigger, BackuplitBuilder}; + +use crate::Cli; // Helper function to convert SystemTime to u64 pub fn system_time_to_u64(time: SystemTime) -> Result { @@ -9,3 +12,42 @@ pub fn system_time_to_u64(time: SystemTime) -> Result { Err(_) => Err(anyhow!("some error")), } } + +pub async fn start_backup_daemon(cli: &Cli) -> Result<(), anyhow::Error> { + if let Some(bucket_id) = cli.google_cloud_backup_bucket_id.clone() { + if let Some(credential) = cli.google_cloud_backup_credentials.clone() { + if let Some(name) = cli.google_cloud_backup_name.clone() { + if let (Some(interval_type), Some(interval_value)) = ( + cli.google_cloud_backup_interval_type.as_ref(), + cli.google_cloud_backup_interval_value, + ) { + let trigger = match interval_type.as_str() { + "seconds" => BackupTrigger::Interval(Duration::from_secs(interval_value)), + "minutes" => { + BackupTrigger::Interval(Duration::from_secs(interval_value * 60)) + } + "hours" => { + BackupTrigger::Interval(Duration::from_secs(interval_value * 3600)) + } + "days" => { + BackupTrigger::Interval(Duration::from_secs(interval_value * 86400)) + } + _ => BackupTrigger::default(), + }; + let backup = BackuplitBuilder::new() + .dir_path(cli.db_path.clone()) + .bucket_id(bucket_id) + .credential(credential) + .backup_name(name) + .backup_trigger(trigger) + .build(); + backup.watch_and_backup().await; + + return Ok(()); + } + } + } + } + + Err(anyhow!("Backup configuration is incomplete. To use Google Cloud Backup, you must provide a bucket ID, credentials, and name.")) +}