From faedfa625de54166ca7f4da39e5bc864881082a4 Mon Sep 17 00:00:00 2001 From: Shady Khalifa Date: Fri, 22 Dec 2023 15:22:46 +0200 Subject: [PATCH] Add Database CLI tool --- Cargo.lock | 659 ++++++++++++++++++++++++++++++++++++------- Cargo.toml | 2 +- auth-sled/src/lib.rs | 40 ++- auth/Cargo.toml | 2 + auth/src/model.rs | 30 ++ db-cli/Cargo.toml | 14 + db-cli/README.md | 30 ++ db-cli/src/main.rs | 114 ++++++++ src/error.rs | 3 +- 9 files changed, 782 insertions(+), 112 deletions(-) create mode 100644 db-cli/Cargo.toml create mode 100644 db-cli/README.md create mode 100644 db-cli/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 94a05a8..f03d08f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,6 +159,166 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +[[package]] +name = "argh" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7af5ba06967ff7214ce4c7419c7d185be7ecd6cc4965a8f6e1d8ce0398aad219" +dependencies = [ + "argh_derive", + "argh_shared", +] + +[[package]] +name = "argh_derive" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56df0aeedf6b7a2fc67d06db35b09684c3e8da0c95f8f27685cb17e08413d87a" +dependencies = [ + "argh_shared", + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "argh_shared" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5693f39141bda5760ecc4111ab08da40565d1771038c4a0250f03457ec707531" +dependencies = [ + "serde", +] + +[[package]] +name = "ark-bls12-377" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb00293ba84f51ce3bd026bd0de55899c4e68f0a39a5728cebae3a73ffdc0a4f" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + [[package]] name = "array-bytes" version = "6.1.0" @@ -315,7 +475,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -332,7 +492,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -458,6 +618,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", + "rand 0.8.5", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -834,6 +996,33 @@ dependencies = [ "thiserror", ] +[[package]] +name = "color-eyre" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + [[package]] name = "concurrent-queue" version = "2.3.0" @@ -895,6 +1084,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" +[[package]] +name = "constcat" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7e35aee659887cbfb97aaf227ac12cad1a9d7c71e55ff3376839ed4e282d08" + [[package]] name = "convert_case" version = "0.4.0" @@ -1140,7 +1335,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -1201,7 +1396,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -1223,7 +1418,21 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core 0.20.3", "quote", - "syn 2.0.37", + "syn 2.0.42", +] + +[[package]] +name = "db-cli" +version = "0.1.0" +dependencies = [ + "argh", + "color-eyre", + "serde", + "serde_json", + "tracing", + "tracing-subscriber 0.3.17", + "webb-auth-sled", + "webb-proposals", ] [[package]] @@ -1301,7 +1510,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -1698,7 +1907,7 @@ dependencies = [ "regex", "serde", "serde_json", - "syn 2.0.37", + "syn 2.0.42", "toml", "walkdir", ] @@ -1716,7 +1925,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -1742,7 +1951,7 @@ dependencies = [ "serde", "serde_json", "strum 0.25.0", - "syn 2.0.37", + "syn 2.0.42", "tempfile", "thiserror", "tiny-keccak", @@ -1894,7 +2103,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -2040,16 +2249,16 @@ dependencies = [ "smallvec", "sp-api", "sp-arithmetic", - "sp-core", + "sp-core 21.0.0", "sp-core-hashing-proc-macro", - "sp-debug-derive", + "sp-debug-derive 8.0.0", "sp-inherents", "sp-io", "sp-runtime", "sp-staking", "sp-state-machine", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "sp-tracing", + "sp-tracing 10.0.0", "sp-weights", "tt-call", ] @@ -2069,7 +2278,7 @@ dependencies = [ "proc-macro-warning", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -2078,10 +2287,10 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -2091,7 +2300,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0 dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -2198,7 +2407,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3104,7 +3313,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3118,7 +3327,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3129,7 +3338,7 @@ checksum = "c12469fc165526520dff2807c2975310ab47cf7190a45b99b49a7dc8befab17b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3140,7 +3349,7 @@ checksum = "b8fb85ec1620619edf2984a7693497d4ec88a9665d8b87e942856884c92dbf2a" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3400,10 +3609,10 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3435,7 +3644,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58659ed77836b3a2ec0b7d5e894d9b18880a45c3898be6332baf90daa0f06afb" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro-error", "proc-macro2", "quote", @@ -3535,6 +3744,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "parity-scale-codec" version = "3.6.5" @@ -3556,7 +3771,7 @@ version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -3682,7 +3897,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3750,7 +3965,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3788,7 +4003,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3900,7 +4115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b69d39aab54d069e7f2fe8cb970493e7834601ca2d8c65fd7bbd183578080d1" dependencies = [ "proc-macro2", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3924,7 +4139,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit", + "toml_edit 0.19.10", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +dependencies = [ + "toml_datetime", + "toml_edit 0.20.2", ] [[package]] @@ -3965,7 +4190,7 @@ checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -3985,7 +4210,7 @@ checksum = "606c4ba35817e2922a308af55ad51bab3645b59eae5c570d4a6cf07e36bd493b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", "version_check", "yansi", ] @@ -4159,7 +4384,7 @@ checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -4355,7 +4580,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn 2.0.37", + "syn 2.0.42", "unicode-xid", ] @@ -4619,7 +4844,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27873eb6005868f8cc72dcfe109fae664cf51223d35387bc2f28be4c28d94c47" dependencies = [ "darling 0.14.4", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -4647,7 +4872,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "995491f110efdc6bea96d6a746140e32bfceb4ea47510750a5467295a4707a25" dependencies = [ "darling 0.14.4", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -4673,7 +4898,7 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -4820,6 +5045,15 @@ dependencies = [ "secp256k1-sys 0.8.1", ] +[[package]] +name = "secp256k1" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5" +dependencies = [ + "secp256k1-sys 0.9.1", +] + [[package]] name = "secp256k1-sys" version = "0.6.1" @@ -4838,6 +5072,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd97a086ec737e30053fd5c46f097465d25bb81dd3608825f65298c4c98be83" +dependencies = [ + "cc", +] + [[package]] name = "secrecy" version = "0.8.0" @@ -4893,9 +5136,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] @@ -4911,13 +5154,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -5287,8 +5530,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api-proc-macro", - "sp-core", - "sp-externalities", + "sp-core 21.0.0", + "sp-externalities 0.19.0", "sp-metadata-ir", "sp-runtime", "sp-state-machine", @@ -5306,10 +5549,10 @@ dependencies = [ "Inflector", "blake2", "expander", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -5320,7 +5563,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", + "sp-core 21.0.0", "sp-io", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", ] @@ -5371,11 +5614,11 @@ dependencies = [ "secrecy", "serde", "sp-core-hashing 9.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "sp-debug-derive", - "sp-externalities", - "sp-runtime-interface", + "sp-debug-derive 8.0.0", + "sp-externalities 0.19.0", + "sp-runtime-interface 17.0.0", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "sp-storage", + "sp-storage 13.0.0", "ss58-registry", "substrate-bip39", "thiserror", @@ -5384,6 +5627,52 @@ dependencies = [ "zeroize", ] +[[package]] +name = "sp-core" +version = "27.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92c65ecfdb86fa1c4809b06a2a83d6f3bdb1ef4fe4c5a4f6df19229030d5283" +dependencies = [ + "array-bytes", + "bip39", + "bitflags 1.3.2", + "blake2", + "bounded-collections", + "bs58 0.5.0", + "dyn-clonable", + "ed25519-zebra", + "futures", + "hash-db", + "hash256-std-hasher", + "impl-serde", + "itertools 0.10.5", + "libsecp256k1", + "log", + "merlin 2.0.1", + "parity-scale-codec", + "parking_lot 0.12.1", + "paste", + "primitive-types", + "rand 0.8.5", + "scale-info", + "schnorrkel 0.9.1", + "secp256k1 0.28.0", + "secrecy", + "serde", + "sp-core-hashing 14.0.0", + "sp-debug-derive 13.0.0", + "sp-externalities 0.24.0", + "sp-runtime-interface 23.0.0", + "sp-std 13.0.0", + "sp-storage 18.0.0", + "ss58-registry", + "substrate-bip39", + "thiserror", + "tracing", + "w3f-bls", + "zeroize", +] + [[package]] name = "sp-core-hashing" version = "9.0.0" @@ -5412,6 +5701,20 @@ dependencies = [ "twox-hash", ] +[[package]] +name = "sp-core-hashing" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1936171e56a51272757760cc50883d2a8c37c650b3602a0aeed05b0c4fffc5f1" +dependencies = [ + "blake2b_simd", + "byteorder", + "digest 0.10.7", + "sha2 0.10.8", + "sha3", + "twox-hash", +] + [[package]] name = "sp-core-hashing-proc-macro" version = "9.0.0" @@ -5419,7 +5722,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0 dependencies = [ "quote", "sp-core-hashing 9.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -5429,7 +5732,18 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0 dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", +] + +[[package]] +name = "sp-debug-derive" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fd2c660c3e940df93f4920b183cc103443d66503f68189fa7e4b3f09996a18" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.42", ] [[package]] @@ -5440,7 +5754,19 @@ dependencies = [ "environmental", "parity-scale-codec", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "sp-storage", + "sp-storage 13.0.0", +] + +[[package]] +name = "sp-externalities" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac0a1df458d0bba69bc011a3b0197049396272e497b207ad161289e7518b74bf" +dependencies = [ + "environmental", + "parity-scale-codec", + "sp-std 13.0.0", + "sp-storage 18.0.0", ] [[package]] @@ -5470,13 +5796,13 @@ dependencies = [ "parity-scale-codec", "rustversion", "secp256k1 0.24.3", - "sp-core", - "sp-externalities", + "sp-core 21.0.0", + "sp-externalities 0.19.0", "sp-keystore", - "sp-runtime-interface", + "sp-runtime-interface 17.0.0", "sp-state-machine", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "sp-tracing", + "sp-tracing 10.0.0", "sp-trie", "tracing", "tracing-core", @@ -5489,8 +5815,8 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0 dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", - "sp-core", - "sp-externalities", + "sp-core 21.0.0", + "sp-externalities 0.19.0", "thiserror", ] @@ -5531,7 +5857,7 @@ dependencies = [ "serde", "sp-application-crypto", "sp-arithmetic", - "sp-core", + "sp-core 21.0.0", "sp-io", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", "sp-weights", @@ -5546,12 +5872,31 @@ dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "primitive-types", - "sp-externalities", - "sp-runtime-interface-proc-macro", + "sp-externalities 0.19.0", + "sp-runtime-interface-proc-macro 11.0.0", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", - "sp-storage", - "sp-tracing", - "sp-wasm-interface", + "sp-storage 13.0.0", + "sp-tracing 10.0.0", + "sp-wasm-interface 14.0.0", + "static_assertions", +] + +[[package]] +name = "sp-runtime-interface" +version = "23.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0093f419cb2ef80c8ecb583ac54e05d1105710eb84add7f9483c8ea882cbaff" +dependencies = [ + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec", + "primitive-types", + "sp-externalities 0.24.0", + "sp-runtime-interface-proc-macro 16.0.0", + "sp-std 13.0.0", + "sp-storage 18.0.0", + "sp-tracing 15.0.0", + "sp-wasm-interface 19.0.0", "static_assertions", ] @@ -5561,10 +5906,24 @@ version = "11.0.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" dependencies = [ "Inflector", - "proc-macro-crate", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.42", +] + +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ebdb4aff8286f5095871b2f950037d690edb0fed0590af5f6735352533a53b6" +dependencies = [ + "Inflector", + "expander", + "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -5576,7 +5935,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core", + "sp-core 21.0.0", "sp-runtime", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", ] @@ -5592,8 +5951,8 @@ dependencies = [ "parking_lot 0.12.1", "rand 0.8.5", "smallvec", - "sp-core", - "sp-externalities", + "sp-core 21.0.0", + "sp-externalities 0.19.0", "sp-panic-handler", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", "sp-trie", @@ -5613,6 +5972,12 @@ name = "sp-std" version = "8.0.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" +[[package]] +name = "sp-std" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71323a3b5f189085d11123ce397b3cdfaec4437071243b51f68a38a4833fbaa7" + [[package]] name = "sp-storage" version = "13.0.0" @@ -5622,10 +5987,24 @@ dependencies = [ "parity-scale-codec", "ref-cast", "serde", - "sp-debug-derive", + "sp-debug-derive 8.0.0", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", ] +[[package]] +name = "sp-storage" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5300c9012180259489a97167f4c45cf3362446e5f0d0c66b6e9342968be8f22" +dependencies = [ + "impl-serde", + "parity-scale-codec", + "ref-cast", + "serde", + "sp-debug-derive 13.0.0", + "sp-std 13.0.0", +] + [[package]] name = "sp-tracing" version = "10.0.0" @@ -5638,6 +6017,19 @@ dependencies = [ "tracing-subscriber 0.2.25", ] +[[package]] +name = "sp-tracing" +version = "15.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b63d14c3214b8b5fe35b67bd61124b5f080cc9d1312b227e0c6cc2a198461e" +dependencies = [ + "parity-scale-codec", + "sp-std 13.0.0", + "tracing", + "tracing-core", + "tracing-subscriber 0.2.25", +] + [[package]] name = "sp-trie" version = "22.0.0" @@ -5653,7 +6045,7 @@ dependencies = [ "parking_lot 0.12.1", "scale-info", "schnellru", - "sp-core", + "sp-core 21.0.0", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", "thiserror", "tracing", @@ -5686,7 +6078,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -5702,6 +6094,20 @@ dependencies = [ "wasmtime", ] +[[package]] +name = "sp-wasm-interface" +version = "19.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4ef2e859d3cde7294c3bf691f8f64244a6a9bb67e53c65729b129318757070e" +dependencies = [ + "anyhow", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "sp-std 13.0.0", + "wasmtime", +] + [[package]] name = "sp-weights" version = "20.0.0" @@ -5712,8 +6118,8 @@ dependencies = [ "serde", "smallvec", "sp-arithmetic", - "sp-core", - "sp-debug-derive", + "sp-core 21.0.0", + "sp-debug-derive 8.0.0", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v1.0.0)", ] @@ -5844,7 +6250,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -5919,7 +6325,7 @@ dependencies = [ "quote", "scale-info", "subxt-metadata", - "syn 2.0.37", + "syn 2.0.42", "thiserror", "tokio", ] @@ -5950,7 +6356,7 @@ dependencies = [ "darling 0.20.3", "proc-macro-error", "subxt-codegen", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -6001,9 +6407,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" dependencies = [ "proc-macro2", "quote", @@ -6069,9 +6475,9 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] @@ -6098,13 +6504,13 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -6224,7 +6630,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] @@ -6283,14 +6689,14 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.19.10", ] [[package]] name = "toml_datetime" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" dependencies = [ "serde", ] @@ -6305,7 +6711,18 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.4.6", +] + +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.0.2", + "toml_datetime", + "winnow 0.5.30", ] [[package]] @@ -6334,19 +6751,29 @@ checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", ] +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber 0.3.17", +] + [[package]] name = "tracing-futures" version = "0.2.5" @@ -6409,6 +6836,7 @@ dependencies = [ "matchers 0.1.0", "nu-ansi-term", "once_cell", + "parking_lot 0.12.1", "regex", "sharded-slab", "smallvec", @@ -6641,6 +7069,30 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "w3f-bls" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7335e4c132c28cc43caef6adb339789e599e39adbe78da0c4d547fad48cbc331" +dependencies = [ + "ark-bls12-377", + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-serialize-derive", + "arrayref", + "constcat", + "digest 0.10.7", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "sha2 0.10.8", + "sha3", + "thiserror", + "zeroize", +] + [[package]] name = "waker-fn" version = "1.1.1" @@ -6706,7 +7158,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", "wasm-bindgen-shared", ] @@ -6740,7 +7192,7 @@ checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6983,7 +7435,9 @@ version = "0.1.0" dependencies = [ "async-trait", "chrono", + "ethers-core", "serde", + "sp-core 27.0.0", "thiserror", "webb-proposals", ] @@ -7257,6 +7711,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.5.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" @@ -7324,5 +7787,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.42", ] diff --git a/Cargo.toml b/Cargo.toml index 37615c9..c02db5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [".", "auth", "auth-sled"] +members = [".", "auth", "auth-sled", "db-cli"] [package] name = "webb-faucet" diff --git a/auth-sled/src/lib.rs b/auth-sled/src/lib.rs index 6c0ec99..0a98bb0 100644 --- a/auth-sled/src/lib.rs +++ b/auth-sled/src/lib.rs @@ -1,8 +1,9 @@ use chrono::{DateTime, Utc}; use std::convert::TryFrom; -use webb_auth::{model::ClaimsData, AuthDb, UserInfo}; +use webb_auth::AuthDb; use webb_proposals::TypedChainId; +pub use webb_auth::model::*; /// SledStore is a store that stores the history of events in a [Sled](https://sled.rs)-based database. #[derive(Clone)] pub struct SledAuthDb { @@ -20,6 +21,19 @@ impl SledAuthDb { }) } + pub fn user_info_tree(&self) -> Result { + self.db.open_tree("users").map_err(Into::into) + } + + pub fn claims_tree( + &self, + chain_id: TypedChainId, + ) -> Result { + self.db + .open_tree(format!("claims-{}", chain_id.chain_id())) + .map_err(Into::into) + } + /// Open a new SledStore in a temporary directory. #[cfg(test)] pub fn open_for_tests() -> Result { @@ -39,7 +53,7 @@ impl AuthDb for SledAuthDb { value: &UserInfo, ) -> Result<(), Self::Error> { let id = u64_to_i64(id)?; - let user_info_tree = self.db.open_tree("users")?; + let user_info_tree = self.user_info_tree()?; let user_info_bytes = serde_json::to_vec(value)?; user_info_tree.insert(id.to_be_bytes(), user_info_bytes)?; Ok(()) @@ -50,7 +64,7 @@ impl AuthDb for SledAuthDb { id: u64, ) -> Result, Self::Error> { let id = u64_to_i64(id)?; - let user_info_tree = self.db.open_tree("users")?; + let user_info_tree = self.user_info_tree()?; user_info_tree .get(id.to_be_bytes()) .map_err(Into::into) @@ -67,9 +81,7 @@ impl AuthDb for SledAuthDb { claim: ClaimsData, ) -> Result, Self::Error> { let id = u64_to_i64(id)?; - let last_claim_tree = self - .db - .open_tree(format!("claims-{}", typed_chain_id.chain_id()))?; + let last_claim_tree = self.claims_tree(typed_chain_id)?; let claims_data_bytes = serde_json::to_vec(&claim)?; last_claim_tree.insert(id.to_be_bytes(), claims_data_bytes)?; Ok(claim.last_claimed_date) @@ -81,9 +93,7 @@ impl AuthDb for SledAuthDb { typed_chain_id: TypedChainId, ) -> Result, Self::Error> { let id = u64_to_i64(id)?; - let last_claim_tree = self - .db - .open_tree(format!("claims-{}", typed_chain_id.chain_id()))?; + let last_claim_tree = self.claims_tree(typed_chain_id)?; last_claim_tree .get(id.to_be_bytes()) .map_err(Into::into) @@ -94,8 +104,12 @@ impl AuthDb for SledAuthDb { } } -fn u64_to_i64(value: u64) -> Result { - i64::try_from(value).map_err(|_| Error::InvalidId(value)) +pub fn u64_to_i64(value: u64) -> Result { + i64::try_from(value).map_err(|_| Error::InvalidU65Id(value)) +} + +pub fn i64_to_u64(value: i64) -> Result { + u64::try_from(value).map_err(|_| Error::InvalidI65Id(value)) } #[derive(thiserror::Error, Debug)] @@ -103,7 +117,9 @@ pub enum Error { #[error("Sled error: {0}")] Sled(#[from] sled::Error), #[error("Invalid ID: {0}")] - InvalidId(u64), + InvalidU65Id(u64), + #[error("Invalid ID: {0}")] + InvalidI65Id(i64), #[error("Invalid Serialization: {0}")] Serde(#[from] serde_json::Error), } diff --git a/auth/Cargo.toml b/auth/Cargo.toml index 6a5b47b..2d8eef0 100644 --- a/auth/Cargo.toml +++ b/auth/Cargo.toml @@ -10,4 +10,6 @@ async-trait = "0.1" chrono = { version = "0.4", features = ["serde"] } serde = "1.0" thiserror = "1.0" +ethers-core = "2.0.10" +sp-core = "27.0" webb-proposals = { git = "https://github.com/webb-tools/webb-rs", rev="a960eaf", features = ["scale"] } diff --git a/auth/src/model.rs b/auth/src/model.rs index e4f04ac..d7b42c5 100644 --- a/auth/src/model.rs +++ b/auth/src/model.rs @@ -1,4 +1,6 @@ use chrono::{DateTime, Utc}; +use ethers_core::types::Address; +use sp_core::crypto::{AccountId32, Ss58Codec}; #[derive( Copy, @@ -55,6 +57,34 @@ impl UniversalWalletAddress { pub fn is_substrate(&self) -> bool { matches!(self, Self::Substrate(..)) } + + pub fn as_ethereum(&self) -> Option
{ + if let Self::Ethereum(v) = self { + Some(Address::from(*v)) + } else { + None + } + } + + pub fn as_substrate(&self) -> Option { + if let Self::Substrate(v) = self { + Some(AccountId32::from(*v)) + } else { + None + } + } +} + +impl core::fmt::Display for UniversalWalletAddress { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Unknown => write!(f, "Unknown"), + Self::Ethereum(v) => write!(f, "{:?}", Address::from(*v)), + Self::Substrate(v) => { + write!(f, "{}", AccountId32::from(*v).to_ss58check()) + } + } + } } #[derive( diff --git a/db-cli/Cargo.toml b/db-cli/Cargo.toml new file mode 100644 index 0000000..c925939 --- /dev/null +++ b/db-cli/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "db-cli" +version = "0.1.0" +edition = "2021" + +[dependencies] +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["parking_lot", "env-filter"] } +color-eyre = "0.6" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +argh = "0.1" +webb-auth-sled = { path = "../auth-sled" } +webb-proposals = { git = "https://github.com/webb-tools/webb-rs", rev="a960eaf", features = ["scale"] } diff --git a/db-cli/README.md b/db-cli/README.md new file mode 100644 index 0000000..c040f5c --- /dev/null +++ b/db-cli/README.md @@ -0,0 +1,30 @@ +## How to use the CLI + +`db-cli` is a command line interface for the database. It reads the database and output all the accounts in a JSON format. + +**Usage:** +```bash +Usage: db-cli -d [-v ] [-e ] [-s ] + +Webb Faucet Database CLI + +Options: + -d, --db sled database path + -v, --verbosity control verbosity level + -e, --evm-output output file for evm addresses + -s, --substrate-output + output file for substrate addresses + --help display usage information +``` + +## Examples + +1. Output all the accounts in the database to stderr +```bash +./db-cli -d ./faucet +``` +2. Output all the accounts in the database to json files + +```bash +./db-cli -d ./faucet -v 2 -e evm.json -s substrate.json +``` diff --git a/db-cli/src/main.rs b/db-cli/src/main.rs new file mode 100644 index 0000000..546e245 --- /dev/null +++ b/db-cli/src/main.rs @@ -0,0 +1,114 @@ +use std::collections::HashSet; + +use argh::FromArgs; +use color_eyre::eyre::Result; +use webb_auth_sled::{ClaimsData, SledAuthDb}; +use webb_proposals::TypedChainId; + +/// Webb Faucet Database CLI +#[derive(Debug, Clone, FromArgs)] +struct Args { + /// sled database path + #[argh(option, short = 'd')] + db: std::path::PathBuf, + + /// control verbosity level + #[argh(option, short = 'v', default = "0")] + verbosity: u8, + /// output file for evm addresses + #[argh(option, short = 'e')] + evm_output: Option, + /// output file for substrate addresses + #[argh(option, short = 's')] + substrate_output: Option, +} + +fn main() -> Result<()> { + color_eyre::install()?; + let args: Args = argh::from_env(); + setup_logger(args.verbosity, "db_cli")?; + tracing::info!("opening db at {:?}", args.db); + let db = SledAuthDb::open(args.db)?; + let chains = [ + // Tangle + TypedChainId::Substrate(1081), + // Tangle Local + TypedChainId::Substrate(1082), + // Athena + TypedChainId::Evm(3884533461), + // Demeter + TypedChainId::Evm(3884533463), + // Hermes + TypedChainId::Evm(3884533462), + // Tangle EVM Testnet + TypedChainId::Evm(4006), + ]; + + let mut accounts = HashSet::new(); + + for chain in chains.iter() { + tracing::debug!( + chain = %chain.chain_id(), + "processing chain claims", + ); + + let chain_accounts = db.claims_tree(*chain)?.iter().flat_map(|kv| { + kv.ok() + .and_then(|(_, v)| { + serde_json::from_slice::(&v).ok() + }) + .map(|c| c.address) + }); + accounts.extend(chain_accounts); + tracing::debug!("Total accounts (so far): {}", accounts.len()); + } + let evm_accounts = accounts + .iter() + .filter_map(|a| a.as_ethereum().map(|v| format!("{:?}", v))) + .collect::>(); + let substrate_accounts = accounts + .iter() + .filter_map(|a| a.as_substrate().map(|v| v.to_string())) + .collect::>(); + if let Some(output) = args.evm_output { + std::fs::write(output, serde_json::to_string_pretty(&evm_accounts)?)?; + } else { + eprintln!("{}", serde_json::to_string_pretty(&evm_accounts)?); + } + if let Some(output) = args.substrate_output { + std::fs::write( + output, + serde_json::to_string_pretty(&substrate_accounts)?, + )?; + } else { + eprintln!("{}", serde_json::to_string_pretty(&substrate_accounts)?); + } + Ok(()) +} + +pub fn setup_logger(verbosity: u8, filter: &str) -> Result<()> { + use tracing::Level; + let log_level = match verbosity { + 0 => Level::ERROR, + 1 => Level::WARN, + 2 => Level::INFO, + 3 => Level::DEBUG, + _ => Level::TRACE, + }; + let directive_1 = format!("{filter}={log_level}") + .parse() + .expect("valid log level"); + let directive_2 = format!("webb_={log_level}") + .parse() + .expect("valid log level"); + let env_filter = tracing_subscriber::EnvFilter::from_default_env() + .add_directive(directive_1) + .add_directive(directive_2); + let logger = tracing_subscriber::fmt() + .with_target(true) + .with_max_level(log_level) + .with_env_filter(env_filter); + let logger = logger.pretty(); + logger.init(); + Ok(()) +} diff --git a/src/error.rs b/src/error.rs index 3c6caf5..830c1bf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -79,7 +79,8 @@ impl<'r, 'o: 'r> Responder<'r, 'o> for Error { }, Status::InternalServerError, ), - webb_auth_sled::Error::InvalidId(_) => ( + webb_auth_sled::Error::InvalidU65Id(_) + | webb_auth_sled::Error::InvalidI65Id(_) => ( ErrorResponse { code: FaucetErrorCode::DataSerializationError, message: self.to_string(),