From d6eb0a5637c0472d0659a26308c8430336919d22 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 8 Jul 2022 15:22:05 -0400 Subject: [PATCH 01/24] Start work on wallet --- Cargo.lock | 177 ++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/subcommand.rs | 15 ++-- src/subcommand/wallet.rs | 17 ++++ 4 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 src/subcommand/wallet.rs diff --git a/Cargo.lock b/Cargo.lock index 4bcbfcff2e..8012323a0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,6 +168,37 @@ dependencies = [ "byteorder", ] +[[package]] +name = "bdk" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec2c4c49915b82a2576bc7dee83d2f274387904b79305e6ae8b622daa0b282c1" +dependencies = [ + "async-trait", + "bdk-macros", + "bitcoin", + "electrum-client", + "js-sys", + "log", + "miniscript", + "rand 0.7.3", + "serde", + "serde_json", + "sled", + "tokio", +] + +[[package]] +name = "bdk-macros" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81c1980e50ae23bb6efa9283ae8679d6ea2c6fa6a99fe62533f65f4a25a1a56c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "bech32" version = "0.8.1" @@ -192,6 +223,7 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05bba324e6baf655b882df672453dbbc527bc938cadd27750ae510aaccc3a66a" dependencies = [ + "base64-compat", "bech32 0.8.1", "bitcoin_hashes", "secp256k1", @@ -576,6 +608,22 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "electrum-client" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ef9b40020912229e947b45d91f9ff96b10d543e0eddd75ff41b9eda24d9c051" +dependencies = [ + "bitcoin", + "log", + "rustls", + "serde", + "serde_json", + "socks", + "webpki", + "webpki-roots", +] + [[package]] name = "encoding_rs" version = "0.8.31" @@ -649,7 +697,7 @@ dependencies = [ "futures-sink", "nanorand", "pin-project", - "spin", + "spin 0.9.3", ] [[package]] @@ -683,6 +731,16 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -786,6 +844,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "gcc" version = "0.3.55" @@ -799,8 +866,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -1315,6 +1384,16 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "miniscript" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da39fc7a8adea97a677337b0091779dd86349226b869053af496584a9b9e5847" +dependencies = [ + "bitcoin", + "serde", +] + [[package]] name = "miniz_oxide" version = "0.5.3" @@ -1510,6 +1589,7 @@ dependencies = [ "anyhow", "axum", "axum-server", + "bdk", "bech32 0.9.0", "bitcoin", "bitcoin_hashes", @@ -2045,6 +2125,21 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -2060,6 +2155,18 @@ dependencies = [ "semver", ] +[[package]] +name = "rustls" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + [[package]] name = "ryu" version = "1.0.10" @@ -2097,6 +2204,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "secp256k1" version = "0.22.1" @@ -2205,6 +2322,22 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +[[package]] +name = "sled" +version = "0.34.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" +dependencies = [ + "crc32fast", + "crossbeam-epoch", + "crossbeam-utils", + "fs2", + "fxhash", + "libc", + "log", + "parking_lot", +] + [[package]] name = "smallvec" version = "1.8.0" @@ -2221,6 +2354,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "socks" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b" +dependencies = [ + "byteorder", + "libc", + "winapi", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.3" @@ -2577,6 +2727,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "1.7.2" @@ -2733,6 +2889,25 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" +dependencies = [ + "webpki", +] + [[package]] name = "weezl" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 600e1fe0db..08c359e9d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ autotests = false anyhow = { version = "1.0.56", features = ["backtrace"] } axum = "0.5.6" axum-server = "0.4.0" +bdk = "0.19.0" bech32 = "0.9.0" bitcoin = "0.28.1" bitcoin_hashes = "0.10.0" diff --git a/src/subcommand.rs b/src/subcommand.rs index 9f94990263..99d62b5873 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -14,13 +14,14 @@ mod server; mod supply; mod traits; mod verify; +mod wallet; #[derive(Parser)] pub(crate) enum Subcommand { Epochs, Find(find::Find), - GeneratePrivateKey, GeneratePaperWallets, + GeneratePrivateKey, Index, Info, List(list::List), @@ -31,25 +32,27 @@ pub(crate) enum Subcommand { Supply, Traits(traits::Traits), Verify(verify::Verify), + Wallet(wallet::Wallet), } impl Subcommand { pub(crate) fn run(self, options: Options) -> Result<()> { match self { Self::Epochs => epochs::run(), - Self::GeneratePrivateKey => generate_private_key::run(), - Self::GeneratePaperWallets => generate_paper_wallets::run(), Self::Find(find) => find.run(options), + Self::GeneratePaperWallets => generate_paper_wallets::run(), + Self::GeneratePrivateKey => generate_private_key::run(), Self::Index => index::run(options), + Self::Info => info::run(options), Self::List(list) => list.run(options), - Self::Name(name) => name.run(), Self::Mint(mint) => mint.run(), + Self::Name(name) => name.run(), Self::Range(range) => range.run(), - Self::Supply => supply::run(), Self::Server(server) => server.run(options), - Self::Info => info::run(options), + Self::Supply => supply::run(), Self::Traits(traits) => traits.run(), Self::Verify(verify) => verify.run(), + Self::Wallet(wallet) => wallet.run(), } } } diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs new file mode 100644 index 0000000000..03a1b8a393 --- /dev/null +++ b/src/subcommand/wallet.rs @@ -0,0 +1,17 @@ +use super::*; + +#[derive(Parser)] +pub(crate) struct Wallet { + #[clap(long)] + init: bool +} + +impl Wallet { + pub(crate) fn run(self) -> Result { + if self.init { + println!("wallet initialized!"); + } + + Ok(()) + } +} From f4373506c1669e706ee7da69aaa6bbc0c8e59da8 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 13 Jul 2022 13:18:25 -0400 Subject: [PATCH 02/24] Setup subcommand structure --- src/subcommand.rs | 1 + src/subcommand/wallet.rs | 13 ++++++------- src/subcommand/wallet/init.rs | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/subcommand/wallet/init.rs diff --git a/src/subcommand.rs b/src/subcommand.rs index 99d62b5873..940c7eda42 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -32,6 +32,7 @@ pub(crate) enum Subcommand { Supply, Traits(traits::Traits), Verify(verify::Verify), + #[clap(subcommand)] Wallet(wallet::Wallet), } diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 03a1b8a393..cc16ffa89c 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -1,17 +1,16 @@ use super::*; +mod init; + #[derive(Parser)] -pub(crate) struct Wallet { - #[clap(long)] - init: bool +pub(crate) enum Wallet { + Init, } impl Wallet { pub(crate) fn run(self) -> Result { - if self.init { - println!("wallet initialized!"); + match self { + Init => init::run(), } - - Ok(()) } } diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs new file mode 100644 index 0000000000..3c6abbf6e0 --- /dev/null +++ b/src/subcommand/wallet/init.rs @@ -0,0 +1,6 @@ +use super::*; + +pub(crate) fn run() -> Result { + println!("Wallet initialized!"); + Ok(()) +} From fc4a296bd89890204855834b2c4ff0520b3b33f4 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 14 Jul 2022 19:43:09 -0400 Subject: [PATCH 03/24] Start work on init --- Cargo.lock | 740 ++++++++++++++++++++++++++-------- Cargo.toml | 3 +- src/subcommand.rs | 2 +- src/subcommand/wallet.rs | 6 +- src/subcommand/wallet/init.rs | 59 ++- 5 files changed, 630 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8012323a0a..6e34522dde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" dependencies = [ "backtrace", ] @@ -80,9 +80,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.5.6" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab2504b827a8bef941ba3dd64bdffe9cf56ca182908a147edd6189c95fbcae7d" +checksum = "d16705af05732b7d3258ec0f7b73c03a658a28925e050d8852d5b568ee8bcf4e" dependencies = [ "async-trait", "axum-core", @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da31c0ed7b4690e2c78fe4b880d21cd7db04a346ebc658b4270251b695437f17" +checksum = "e4f44a0e6200e9d11a1cdc989e4b358f6e3d354fbf48478f345a17f4e43f8635" dependencies = [ "async-trait", "bytes", @@ -140,19 +140,25 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", - "miniz_oxide", + "miniz_oxide 0.5.3", "object", "rustc-demangle", ] +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + [[package]] name = "base64" version = "0.13.0" @@ -176,7 +182,9 @@ checksum = "ec2c4c49915b82a2576bc7dee83d2f274387904b79305e6ae8b622daa0b282c1" dependencies = [ "async-trait", "bdk-macros", + "bip39", "bitcoin", + "bitcoincore-rpc", "electrum-client", "js-sys", "log", @@ -211,6 +219,18 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5738be7561b0eeb501ef1d5c5db3f24e01ceb55fededd9b00039aada34966ad" +[[package]] +name = "bip39" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e89470017230c38e52b82b3ee3f530db1856ba1d434e3a67a3456a8a8dec5f" +dependencies = [ + "bitcoin_hashes 0.9.7", + "rand_core 0.4.2", + "serde", + "unicode-normalization", +] + [[package]] name = "bit_field" version = "0.10.1" @@ -225,11 +245,17 @@ checksum = "05bba324e6baf655b882df672453dbbc527bc938cadd27750ae510aaccc3a66a" dependencies = [ "base64-compat", "bech32 0.8.1", - "bitcoin_hashes", + "bitcoin_hashes 0.10.0", "secp256k1", "serde", ] +[[package]] +name = "bitcoin_hashes" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce18265ec2324ad075345d5814fbeed4f41f0a660055dc78840b74d19b874b1" + [[package]] name = "bitcoin_hashes" version = "0.10.0" @@ -263,6 +289,24 @@ dependencies = [ "serde_json", ] +[[package]] +name = "bitcoind" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0831b9721892ce845a6acadd111311bee84f9e1cc0c5017b8213ec4437ccdfe2" +dependencies = [ + "bitcoin_hashes 0.10.0", + "bitcoincore-rpc", + "filetime", + "flate2", + "home", + "log", + "tar", + "tempfile", + "ureq", + "which", +] + [[package]] name = "bitflags" version = "0.9.1" @@ -295,9 +339,9 @@ checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" [[package]] name = "bytemuck" -version = "1.9.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdead85bdec19c194affaeeb670c0e41fe23de31459efd1c174d049269cf02cc" +checksum = "c53dfa917ec274df8ed3c572698f381a24eef2efba9492d797301b72b6db408a" [[package]] name = "byteorder" @@ -317,9 +361,15 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" dependencies = [ - "rustc_version", + "rustc_version 0.4.0", ] +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.0.73" @@ -347,10 +397,16 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time", + "time 0.1.44", "winapi", ] +[[package]] +name = "chunked_transfer" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" + [[package]] name = "clap" version = "2.34.0" @@ -364,16 +420,16 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.18" +version = "3.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" +checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d" dependencies = [ "atty", "bitflags 1.3.2", "clap_derive", "clap_lex", "indexmap", - "lazy_static", + "once_cell", "strsim", "termcolor", "textwrap 0.15.0", @@ -381,9 +437,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.1.18" +version = "3.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" dependencies = [ "heck", "proc-macro-error", @@ -394,9 +450,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ "os_str_bytes", ] @@ -416,12 +472,45 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "const_fn" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" + [[package]] name = "convert_case" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cookie" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" +dependencies = [ + "percent-encoding 2.1.0", + "time 0.2.27", + "version_check", +] + +[[package]] +name = "cookie_store" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3" +dependencies = [ + "cookie", + "idna 0.2.1", + "log", + "publicsuffix", + "serde", + "serde_json", + "time 0.2.27", + "url 2.2.2", +] + [[package]] name = "core-foundation" version = "0.9.3" @@ -449,12 +538,12 @@ dependencies = [ [[package]] name = "criterion" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" +checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", - "cast", + "cast 0.3.0", "clap 2.34.0", "criterion-plot", "csv", @@ -479,15 +568,15 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" dependencies = [ - "cast", + "cast 0.2.7", "itertools", ] [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -506,26 +595,26 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" dependencies = [ "autocfg 1.1.0", "cfg-if 1.0.0", "crossbeam-utils", - "lazy_static", "memoffset", + "once_cell", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" dependencies = [ "cfg-if 1.0.0", - "lazy_static", + "once_cell", ] [[package]] @@ -578,7 +667,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version", + "rustc_version 0.4.0", "syn", ] @@ -602,11 +691,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + [[package]] name = "either" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" [[package]] name = "electrum-client" @@ -616,12 +711,12 @@ checksum = "8ef9b40020912229e947b45d91f9ff96b10d543e0eddd75ff41b9eda24d9c051" dependencies = [ "bitcoin", "log", - "rustls", + "rustls 0.20.6", "serde", "serde_json", "socks", - "webpki", - "webpki-roots", + "webpki 0.22.0", + "webpki-roots 0.22.4", ] [[package]] @@ -646,6 +741,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "version_check", +] + [[package]] name = "executable-path" version = "1.0.0" @@ -664,7 +768,7 @@ dependencies = [ "half", "inflate", "lebe", - "smallvec", + "smallvec 1.9.0", "threadpool", ] @@ -677,27 +781,41 @@ dependencies = [ "instant", ] +[[package]] +name = "filetime" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "975ccf83d8d9d0d84682850a38c8169027be83368805971cc4f238c2b245bc98" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "flate2" -version = "1.0.24" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" dependencies = [ + "cfg-if 1.0.0", "crc32fast", - "miniz_oxide", + "libc", + "miniz_oxide 0.4.4", ] [[package]] name = "flume" -version = "0.10.12" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a" +checksum = "1ceeb589a3157cac0ab8cc585feb749bd2cea5cb55a6ee802ad72d9fd38303da" dependencies = [ "futures-core", "futures-sink", "nanorand", "pin-project", - "spin 0.9.3", + "spin 0.9.4", ] [[package]] @@ -874,22 +992,22 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if 1.0.0", "js-sys", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] [[package]] name = "gif" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b" +checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" dependencies = [ "color_quant", "weezl", @@ -903,9 +1021,9 @@ checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" [[package]] name = "globset" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" +checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" dependencies = [ "aho-corasick", "bstr", @@ -941,9 +1059,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" [[package]] name = "heck" @@ -966,6 +1084,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" +dependencies = [ + "winapi", +] + [[package]] name = "html-escape" version = "0.2.11" @@ -977,9 +1104,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes", "fnv", @@ -1023,9 +1150,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.19" +version = "0.14.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42dc3c131584288d375f2d07f822b0cb012d8c6fb899a5b9fdb3cb7eb9b6004f" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" dependencies = [ "bytes", "futures-channel", @@ -1071,9 +1198,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.3" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "de910d521f7cc3135c4de8db1cb910e0b5ed1dc6f57c381cd07e8e661ce10094" dependencies = [ "matches", "unicode-bidi", @@ -1102,9 +1229,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.2" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg 1.1.0", "hashbrown", @@ -1184,9 +1311,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.57" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" dependencies = [ "wasm-bindgen", ] @@ -1354,6 +1481,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + [[package]] name = "memchr" version = "2.5.0" @@ -1362,9 +1495,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5172b50c23043ff43dd53e51392f36519d9b35a8f3a410d30ece5d1aedd58ae" +checksum = "3a79b39c93a7a5a27eeaf9a23b5ff43f1b9e0ad6b1cdd441140ae53c35613fc7" dependencies = [ "libc", ] @@ -1394,6 +1527,16 @@ dependencies = [ "serde", ] +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg 1.1.0", +] + [[package]] name = "miniz_oxide" version = "0.5.3" @@ -1405,9 +1548,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", "log", @@ -1421,7 +1564,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.7", ] [[package]] @@ -1488,9 +1631,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg 1.1.0", "num-integer", @@ -1518,18 +1661,18 @@ dependencies = [ [[package]] name = "object" -version = "0.28.4" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "oorandom" @@ -1539,9 +1682,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "openssl" -version = "0.10.40" +version = "0.10.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" +checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", @@ -1571,9 +1714,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.74" +version = "0.9.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1" +checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" dependencies = [ "autocfg 1.1.0", "cc", @@ -1592,10 +1735,11 @@ dependencies = [ "bdk", "bech32 0.9.0", "bitcoin", - "bitcoin_hashes", + "bitcoin_hashes 0.10.0", "bitcoincore-rpc", + "bitcoind", "chrono", - "clap 3.1.18", + "clap 3.2.12", "criterion", "ctrlc", "derive_more", @@ -1679,7 +1823,7 @@ dependencies = [ "instant", "libc", "redox_syscall", - "smallvec", + "smallvec 1.9.0", "winapi", ] @@ -1697,18 +1841,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" +checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" +checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" dependencies = [ "proc-macro2", "quote", @@ -1735,9 +1879,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "plotters" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +checksum = "9428003b84df1496fb9d6eeee9c5f8145cb41ca375eb0dad204328888832811f" dependencies = [ "num-traits", "plotters-backend", @@ -1748,15 +1892,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "e0918736323d1baff32ee0eade54984f6f201ad7e97d5cfb5d6ab4a358529615" dependencies = [ "plotters-backend", ] @@ -1770,7 +1914,7 @@ dependencies = [ "bitflags 1.3.2", "crc32fast", "deflate", - "miniz_oxide", + "miniz_oxide 0.5.3", ] [[package]] @@ -1812,15 +1956,34 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ "unicode-ident", ] +[[package]] +name = "publicsuffix" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" +dependencies = [ + "error-chain", + "idna 0.2.1", + "lazy_static", + "regex", + "url 2.2.2", +] + [[package]] name = "qrcode-generator" version = "4.1.6" @@ -1838,11 +2001,20 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4339fc7a1021c9c1621d87f5e3505f2805c8c105420ba2f2a4df86814590c142" +[[package]] +name = "qstring" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" +dependencies = [ + "percent-encoding 2.1.0", +] + [[package]] name = "quote" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] @@ -2052,16 +2224,16 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.7", "redox_syscall", "thiserror", ] [[package]] name = "regex" -version = "1.5.6" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -2076,9 +2248,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" @@ -2091,9 +2263,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.10" +version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" +checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" dependencies = [ "base64", "bytes", @@ -2118,6 +2290,7 @@ dependencies = [ "serde_urlencoded", "tokio", "tokio-native-tls", + "tower-service", "url 2.2.2", "wasm-bindgen", "wasm-bindgen-futures", @@ -2146,13 +2319,35 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver", + "semver 1.0.12", +] + +[[package]] +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64", + "log", + "ring", + "sct 0.6.1", + "webpki 0.21.4", ] [[package]] @@ -2163,8 +2358,8 @@ checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" dependencies = [ "log", "ring", - "sct", - "webpki", + "sct 0.7.0", + "webpki 0.22.0", ] [[package]] @@ -2204,6 +2399,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "sct" version = "0.7.0" @@ -2259,15 +2464,30 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.9" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" + +[[package]] +name = "semver-parser" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.137" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" dependencies = [ "serde_derive", ] @@ -2284,9 +2504,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", @@ -2295,9 +2515,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ "itoa 1.0.2", "ryu", @@ -2316,6 +2536,21 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + [[package]] name = "slab" version = "0.4.6" @@ -2340,9 +2575,18 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.8.0" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" +dependencies = [ + "maybe-uninit", +] + +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "socket2" @@ -2373,13 +2617,71 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" dependencies = [ "lock_api", ] +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check", +] + +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version 0.2.3", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + [[package]] name = "strsim" version = "0.10.0" @@ -2394,9 +2696,9 @@ checksum = "171758edb47aa306a78dfa4ab9aeb5167405bd4e3dc2b64e88f6a84bbe98bd63" [[package]] name = "syn" -version = "1.0.96" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", @@ -2409,6 +2711,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" +[[package]] +name = "tar" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.3.0" @@ -2499,36 +2812,60 @@ dependencies = [ ] [[package]] -name = "tinytemplate" -version = "1.2.1" +name = "time" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" dependencies = [ - "serde", - "serde_json", + "const_fn", + "libc", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi", ] [[package]] -name = "tinyvec" -version = "1.6.0" +name = "time-macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" dependencies = [ - "tinyvec_macros", + "proc-macro-hack", + "time-macros-impl", ] [[package]] -name = "tinyvec_macros" -version = "0.1.0" +name = "time-macros-impl" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] [[package]] name = "tokio" -version = "1.19.1" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95eec79ea28c00a365f539f1961e9278fbcaf81c0ff6aaf0e93c181352446948" +checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e" dependencies = [ + "autocfg 1.1.0", "bytes", "libc", "memchr", @@ -2612,16 +2949,15 @@ dependencies = [ [[package]] name = "tower" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", "pin-project", "pin-project-lite", "tokio", - "tokio-util 0.7.3", "tower-layer", "tower-service", "tracing", @@ -2629,9 +2965,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d342c6d58709c0a6d48d48dabbb62d4ef955cf5f0f3bbfd845838e7ae88dbae" +checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" dependencies = [ "bitflags 1.3.2", "bytes", @@ -2654,15 +2990,15 @@ checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" [[package]] name = "tower-service" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.34" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ "cfg-if 1.0.0", "log", @@ -2672,11 +3008,11 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.26" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" +checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] @@ -2702,17 +3038,17 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +checksum = "09c8070a9942f5e7cfccd93f490fdebd230ee3c3c9f107cb25bad5351ef671cf" dependencies = [ - "tinyvec", + "smallvec 0.6.14", ] [[package]] @@ -2733,6 +3069,25 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "ureq" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b8b063c2d59218ae09f22b53c42eaad0d53516457905f5235ca4bc9e99daa71" +dependencies = [ + "base64", + "chunked_transfer", + "cookie", + "cookie_store", + "log", + "once_cell", + "qstring", + "rustls 0.19.1", + "url 2.2.2", + "webpki 0.21.4", + "webpki-roots 0.21.1", +] + [[package]] name = "url" version = "1.7.2" @@ -2751,7 +3106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", - "idna 0.2.3", + "idna 0.2.1", "matches", "percent-encoding 2.1.0", ] @@ -2815,9 +3170,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2825,9 +3180,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" dependencies = [ "bumpalo", "lazy_static", @@ -2840,9 +3195,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.30" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2852,9 +3207,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2862,9 +3217,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ "proc-macro2", "quote", @@ -2875,20 +3230,30 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" dependencies = [ "js-sys", "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "webpki" version = "0.22.0" @@ -2901,18 +3266,38 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.3" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +dependencies = [ + "webpki 0.21.4", +] + +[[package]] +name = "webpki-roots" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" +checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" dependencies = [ - "webpki", + "webpki 0.22.0", ] [[package]] name = "weezl" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c97e489d8f836838d497091de568cf16b117486d529ec5579233521065bd5e4" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + +[[package]] +name = "which" +version = "4.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +dependencies = [ + "either", + "lazy_static", + "libc", +] [[package]] name = "winapi" @@ -2996,3 +3381,12 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "xattr" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +dependencies = [ + "libc", +] diff --git a/Cargo.toml b/Cargo.toml index 08c359e9d0..a6aed13d56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,12 @@ autotests = false anyhow = { version = "1.0.56", features = ["backtrace"] } axum = "0.5.6" axum-server = "0.4.0" -bdk = "0.19.0" +bdk = { version = "0.19.0", features = ["rpc", "keys-bip39"] } bech32 = "0.9.0" bitcoin = "0.28.1" bitcoin_hashes = "0.10.0" bitcoincore-rpc = "0.15.0" +bitcoind = "0.26.1" chrono = "0.4.19" clap = { version = "3.1.0", features = ["derive"] } ctrlc = "3.2.1" diff --git a/src/subcommand.rs b/src/subcommand.rs index 940c7eda42..a12e353659 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -53,7 +53,7 @@ impl Subcommand { Self::Supply => supply::run(), Self::Traits(traits) => traits.run(), Self::Verify(verify) => verify.run(), - Self::Wallet(wallet) => wallet.run(), + Self::Wallet(wallet) => wallet.run(options), } } } diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index cc16ffa89c..737ee250f2 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -1,4 +1,4 @@ -use super::*; +use {super::*, Wallet::*}; mod init; @@ -8,9 +8,9 @@ pub(crate) enum Wallet { } impl Wallet { - pub(crate) fn run(self) -> Result { + pub(crate) fn run(self, options: Options) -> Result { match self { - Init => init::run(), + Init => init::run(options), } } } diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index 3c6abbf6e0..e5dfc29bf2 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -1,6 +1,61 @@ use super::*; -pub(crate) fn run() -> Result { - println!("Wallet initialized!"); +use bdk::{ + blockchain::{ + rpc::{Auth, RpcBlockchain, RpcConfig}, + ConfigurableBlockchain, + }, + database::memory::MemoryDatabase, + keys::{ + bip39::{Language, Mnemonic, WordCount}, + DerivableKey, GeneratableKey, GeneratedKey, + }, + miniscript::miniscript::Segwitv0, + template::Bip84, + wallet::{wallet_name_from_descriptor, SyncOptions}, + KeychainKind, Wallet, +}; + +fn generate_key() -> Result + Clone> { + let password = Some("password".to_string()); + + let mnemonic: GeneratedKey<_, _> = Mnemonic::generate((WordCount::Words12, Language::English)) + .map_err(|e| e.expect("Unknown Error"))?; + + Ok((mnemonic, password)) +} + +pub(crate) fn run(options: Options) -> Result { + println!("[~] Setting up ordinal wallet..."); + + let key = generate_key()?; + + let wallet = Wallet::new( + Bip84(key.clone(), KeychainKind::External), + Some(Bip84(key.clone(), KeychainKind::Internal)), + Network::Signet, + MemoryDatabase::new(), + )?; + + wallet.sync( + &RpcBlockchain::from_config(&RpcConfig { + url: options.rpc_url.unwrap(), + auth: Auth::Cookie { + file: options.cookie_file.unwrap(), + }, + network: Network::Signet, + wallet_name: wallet_name_from_descriptor( + Bip84(key.clone(), KeychainKind::External), + Some(Bip84(key.clone(), KeychainKind::Internal)), + Network::Signet, + &Secp256k1::new(), + )?, + skip_blocks: None, + })?, + SyncOptions::default(), + )?; + + println!("Setup complete."); + Ok(()) } From b657013e3140ff4327913f6328fd9f594fdefb76 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 14 Jul 2022 19:44:02 -0400 Subject: [PATCH 04/24] Get rid of bitcoind --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a6aed13d56..0bdba9b624 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ bech32 = "0.9.0" bitcoin = "0.28.1" bitcoin_hashes = "0.10.0" bitcoincore-rpc = "0.15.0" -bitcoind = "0.26.1" chrono = "0.4.19" clap = { version = "3.1.0", features = ["derive"] } ctrlc = "3.2.1" From 2d96974e65744111d2b1fed0eaae1b2abb8607c8 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 15 Jul 2022 10:29:06 -0400 Subject: [PATCH 05/24] Clippy --- Cargo.lock | 375 +--------------------------------- src/subcommand/wallet/init.rs | 15 +- 2 files changed, 19 insertions(+), 371 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e34522dde..9d13d477a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,12 +153,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.13.0" @@ -289,24 +283,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "bitcoind" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0831b9721892ce845a6acadd111311bee84f9e1cc0c5017b8213ec4437ccdfe2" -dependencies = [ - "bitcoin_hashes 0.10.0", - "bitcoincore-rpc", - "filetime", - "flate2", - "home", - "log", - "tar", - "tempfile", - "ureq", - "which", -] - [[package]] name = "bitflags" version = "0.9.1" @@ -361,7 +337,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" dependencies = [ - "rustc_version 0.4.0", + "rustc_version", ] [[package]] @@ -397,16 +373,10 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time 0.1.44", + "time", "winapi", ] -[[package]] -name = "chunked_transfer" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" - [[package]] name = "clap" version = "2.34.0" @@ -472,45 +442,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "convert_case" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "cookie" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" -dependencies = [ - "percent-encoding 2.1.0", - "time 0.2.27", - "version_check", -] - -[[package]] -name = "cookie_store" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3" -dependencies = [ - "cookie", - "idna 0.2.1", - "log", - "publicsuffix", - "serde", - "serde_json", - "time 0.2.27", - "url 2.2.2", -] - [[package]] name = "core-foundation" version = "0.9.3" @@ -667,7 +604,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn", ] @@ -691,12 +628,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "either" version = "1.7.0" @@ -711,12 +642,12 @@ checksum = "8ef9b40020912229e947b45d91f9ff96b10d543e0eddd75ff41b9eda24d9c051" dependencies = [ "bitcoin", "log", - "rustls 0.20.6", + "rustls", "serde", "serde_json", "socks", - "webpki 0.22.0", - "webpki-roots 0.22.4", + "webpki", + "webpki-roots", ] [[package]] @@ -741,15 +672,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check", -] - [[package]] name = "executable-path" version = "1.0.0" @@ -781,18 +703,6 @@ dependencies = [ "instant", ] -[[package]] -name = "filetime" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "975ccf83d8d9d0d84682850a38c8169027be83368805971cc4f238c2b245bc98" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall", - "winapi", -] - [[package]] name = "flate2" version = "1.0.22" @@ -1084,15 +994,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "home" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" -dependencies = [ - "winapi", -] - [[package]] name = "html-escape" version = "0.2.11" @@ -1737,7 +1638,6 @@ dependencies = [ "bitcoin", "bitcoin_hashes 0.10.0", "bitcoincore-rpc", - "bitcoind", "chrono", "clap 3.2.12", "criterion", @@ -1956,12 +1856,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - [[package]] name = "proc-macro2" version = "1.0.40" @@ -1971,19 +1865,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "publicsuffix" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" -dependencies = [ - "error-chain", - "idna 0.2.1", - "lazy_static", - "regex", - "url 2.2.2", -] - [[package]] name = "qrcode-generator" version = "4.1.6" @@ -2001,15 +1882,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4339fc7a1021c9c1621d87f5e3505f2805c8c105420ba2f2a4df86814590c142" -[[package]] -name = "qstring" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" -dependencies = [ - "percent-encoding 2.1.0", -] - [[package]] name = "quote" version = "1.0.20" @@ -2319,35 +2191,13 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.12", -] - -[[package]] -name = "rustls" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" -dependencies = [ - "base64", - "log", - "ring", - "sct 0.6.1", - "webpki 0.21.4", + "semver", ] [[package]] @@ -2358,8 +2208,8 @@ checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" dependencies = [ "log", "ring", - "sct 0.7.0", - "webpki 0.22.0", + "sct", + "webpki", ] [[package]] @@ -2399,16 +2249,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "sct" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "sct" version = "0.7.0" @@ -2462,27 +2302,12 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.139" @@ -2536,21 +2361,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "slab" version = "0.4.6" @@ -2624,64 +2434,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "strsim" version = "0.10.0" @@ -2711,17 +2463,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" -[[package]] -name = "tar" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" -dependencies = [ - "filetime", - "libc", - "xattr", -] - [[package]] name = "tempfile" version = "3.3.0" @@ -2811,44 +2552,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "time" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check", - "winapi", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - -[[package]] -name = "time-macros-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -3069,25 +2772,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" -[[package]] -name = "ureq" -version = "1.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b8b063c2d59218ae09f22b53c42eaad0d53516457905f5235ca4bc9e99daa71" -dependencies = [ - "base64", - "chunked_transfer", - "cookie", - "cookie_store", - "log", - "once_cell", - "qstring", - "rustls 0.19.1", - "url 2.2.2", - "webpki 0.21.4", - "webpki-roots 0.21.1", -] - [[package]] name = "url" version = "1.7.2" @@ -3244,16 +2928,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "webpki" version = "0.22.0" @@ -3264,22 +2938,13 @@ dependencies = [ "untrusted", ] -[[package]] -name = "webpki-roots" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" -dependencies = [ - "webpki 0.21.4", -] - [[package]] name = "webpki-roots" version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" dependencies = [ - "webpki 0.22.0", + "webpki", ] [[package]] @@ -3288,17 +2953,6 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" -[[package]] -name = "which" -version = "4.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" -dependencies = [ - "either", - "lazy_static", - "libc", -] - [[package]] name = "winapi" version = "0.3.9" @@ -3381,12 +3035,3 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] - -[[package]] -name = "xattr" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" -dependencies = [ - "libc", -] diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index e5dfc29bf2..ceca2cd993 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -20,7 +20,7 @@ fn generate_key() -> Result + Clone> { let password = Some("password".to_string()); let mnemonic: GeneratedKey<_, _> = Mnemonic::generate((WordCount::Words12, Language::English)) - .map_err(|e| e.expect("Unknown Error"))?; + .map_err(|e| e.expect("Failed to generate key"))?; Ok((mnemonic, password)) } @@ -39,14 +39,17 @@ pub(crate) fn run(options: Options) -> Result { wallet.sync( &RpcBlockchain::from_config(&RpcConfig { - url: options.rpc_url.unwrap(), - auth: Auth::Cookie { - file: options.cookie_file.unwrap(), - }, + url: options + .rpc_url + .ok_or_else(|| anyhow!("This command requires `--rpc-url`"))?, + auth: options + .cookie_file + .map(|path| Auth::Cookie { file: path }) + .unwrap_or(Auth::None), network: Network::Signet, wallet_name: wallet_name_from_descriptor( Bip84(key.clone(), KeychainKind::External), - Some(Bip84(key.clone(), KeychainKind::Internal)), + Some(Bip84(key, KeychainKind::Internal)), Network::Signet, &Secp256k1::new(), )?, From 66fcf88bb0133d34f328eb25e1981067049ed6d1 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 15 Jul 2022 10:42:08 -0400 Subject: [PATCH 06/24] Setup on regtest for now --- src/subcommand/wallet/init.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index ceca2cd993..d092063ab8 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -33,7 +33,7 @@ pub(crate) fn run(options: Options) -> Result { let wallet = Wallet::new( Bip84(key.clone(), KeychainKind::External), Some(Bip84(key.clone(), KeychainKind::Internal)), - Network::Signet, + Network::Regtest, MemoryDatabase::new(), )?; @@ -46,11 +46,11 @@ pub(crate) fn run(options: Options) -> Result { .cookie_file .map(|path| Auth::Cookie { file: path }) .unwrap_or(Auth::None), - network: Network::Signet, + network: Network::Regtest, wallet_name: wallet_name_from_descriptor( Bip84(key.clone(), KeychainKind::External), Some(Bip84(key, KeychainKind::Internal)), - Network::Signet, + Network::Regtest, &Secp256k1::new(), )?, skip_blocks: None, From e0a6f2928629e64546a3daa8026f2bba523ee144 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 11:50:56 -0400 Subject: [PATCH 07/24] Save wallet data using sqlite --- Cargo.lock | 137 +++++++++++++++++++++++----------- Cargo.toml | 2 +- src/subcommand/wallet/init.rs | 10 +-- 3 files changed, 98 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95b4f0ccf3..8fad10b90c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.7", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -80,9 +91,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16705af05732b7d3258ec0f7b73c03a658a28925e050d8852d5b568ee8bcf4e" +checksum = "6b9496f0c1d1afb7a2af4338bbe1d969cddfead41d87a9fb3aaa6d0bbc7af648" dependencies = [ "async-trait", "axum-core", @@ -148,7 +159,7 @@ dependencies = [ "cc", "cfg-if 1.0.0", "libc", - "miniz_oxide 0.5.3", + "miniz_oxide", "object", "rustc-demangle", ] @@ -170,10 +181,11 @@ dependencies = [ [[package]] name = "bdk" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2c4c49915b82a2576bc7dee83d2f274387904b79305e6ae8b622daa0b282c1" +checksum = "5a0becbf5a97855daca6717ff920c52a779cebf655b23ae1427e5366d2661e82" dependencies = [ + "ahash", "async-trait", "bdk-macros", "bip39", @@ -184,6 +196,7 @@ dependencies = [ "log", "miniscript", "rand 0.7.3", + "rusqlite", "serde", "serde_json", "sled", @@ -331,15 +344,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" -[[package]] -name = "cast" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" -dependencies = [ - "rustc_version", -] - [[package]] name = "cast" version = "0.3.0" @@ -480,7 +484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", - "cast 0.3.0", + "cast", "clap 2.34.0", "criterion-plot", "csv", @@ -501,11 +505,11 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" +checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" dependencies = [ - "cast 0.2.7", + "cast", "itertools", ] @@ -694,6 +698,18 @@ dependencies = [ "threadpool", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fastrand" version = "1.7.0" @@ -705,14 +721,12 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ - "cfg-if 1.0.0", "crc32fast", - "libc", - "miniz_oxide 0.4.4", + "miniz_oxide", ] [[package]] @@ -925,9 +939,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" [[package]] name = "globset" @@ -969,9 +983,27 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "hashbrown" -version = "0.12.2" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashlink" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +dependencies = [ + "hashbrown 0.11.2", +] [[package]] name = "heck" @@ -1135,7 +1167,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg 1.1.0", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -1351,6 +1383,16 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "libsqlite3-sys" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" +dependencies = [ + "pkg-config", + "vcpkg", +] + [[package]] name = "lock_api" version = "0.4.7" @@ -1428,16 +1470,6 @@ dependencies = [ "serde", ] -[[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg 1.1.0", -] - [[package]] name = "miniz_oxide" version = "0.5.3" @@ -1499,9 +1531,9 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", @@ -1698,9 +1730,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.1.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] name = "parking_lot" @@ -1814,7 +1846,7 @@ dependencies = [ "bitflags 1.3.2", "crc32fast", "deflate", - "miniz_oxide 0.5.3", + "miniz_oxide", ] [[package]] @@ -2185,6 +2217,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "rusqlite" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85127183a999f7db96d1a976a309eebbfb6ea3b0b400ddd8340190129de6eb7a" +dependencies = [ + "bitflags 1.3.2", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "memchr", + "smallvec 1.9.0", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -2741,9 +2788,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" +checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" [[package]] name = "unicode-normalization" diff --git a/Cargo.toml b/Cargo.toml index c4522edd83..093ac98646 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ autotests = false anyhow = { version = "1.0.56", features = ["backtrace"] } axum = "0.5.6" axum-server = "0.4.0" -bdk = { version = "0.19.0", features = ["rpc", "keys-bip39"] } +bdk = { version = "0.20.0", features = ["rpc", "keys-bip39", "sqlite"] } bech32 = "0.9.0" bitcoin = "0.28.1" bitcoin_hashes = "0.10.0" diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index d092063ab8..194d2aeb01 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -5,10 +5,10 @@ use bdk::{ rpc::{Auth, RpcBlockchain, RpcConfig}, ConfigurableBlockchain, }, - database::memory::MemoryDatabase, + database::SqliteDatabase, keys::{ bip39::{Language, Mnemonic, WordCount}, - DerivableKey, GeneratableKey, GeneratedKey, + DerivableKey, GeneratableKey, }, miniscript::miniscript::Segwitv0, template::Bip84, @@ -19,8 +19,8 @@ use bdk::{ fn generate_key() -> Result + Clone> { let password = Some("password".to_string()); - let mnemonic: GeneratedKey<_, _> = Mnemonic::generate((WordCount::Words12, Language::English)) - .map_err(|e| e.expect("Failed to generate key"))?; + let mnemonic = Mnemonic::generate((WordCount::Words12, Language::English)) + .map_err(|err| err.expect("Failed to generate mnemonic"))?; Ok((mnemonic, password)) } @@ -34,7 +34,7 @@ pub(crate) fn run(options: Options) -> Result { Bip84(key.clone(), KeychainKind::External), Some(Bip84(key.clone(), KeychainKind::Internal)), Network::Regtest, - MemoryDatabase::new(), + SqliteDatabase::new("foo".into()), )?; wallet.sync( From 8f79f641df4d4b9fefd4a5e62345f6b55f6f3239 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 15:27:54 -0400 Subject: [PATCH 08/24] Add fund and write test --- src/main.rs | 15 +++++++++++++++ src/subcommand/wallet.rs | 14 ++++++++++++-- src/subcommand/wallet/fund.rs | 16 ++++++++++++++++ src/subcommand/wallet/init.rs | 31 +++---------------------------- tests/lib.rs | 1 + tests/wallet.rs | 9 +++++++++ 6 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 src/subcommand/wallet/fund.rs create mode 100644 tests/wallet.rs diff --git a/src/main.rs b/src/main.rs index 2f037082de..5df75339f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,21 @@ use { anyhow::{anyhow, Context, Error}, axum::{extract, http::StatusCode, response::IntoResponse, routing::get, Json, Router}, axum_server::Handle, + bdk::{ + blockchain::{ + rpc::{Auth, RpcBlockchain, RpcConfig}, + ConfigurableBlockchain, + }, + database::SqliteDatabase, + keys::{ + bip39::{Language, Mnemonic, WordCount}, + DerivableKey, GeneratableKey, + }, + miniscript::miniscript::Segwitv0, + template::Bip84, + wallet::{wallet_name_from_descriptor, AddressIndex::LastUnused, SyncOptions}, + KeychainKind, Wallet, + }, bech32::{FromBase32, ToBase32}, bitcoin::{ blockdata::constants::COIN_VALUE, consensus::Decodable, consensus::Encodable, diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 737ee250f2..491677e176 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -1,16 +1,26 @@ -use {super::*, Wallet::*}; +use super::*; +mod fund; mod init; +pub(crate) fn get_key() -> Result + Clone> { + Ok(( + Mnemonic::parse("book fit fly ketchup also elevator scout mind edit fatal where rookie")?, + None, + )) +} + #[derive(Parser)] pub(crate) enum Wallet { Init, + Fund, } impl Wallet { pub(crate) fn run(self, options: Options) -> Result { match self { - Init => init::run(options), + Self::Init => init::run(options), + Self::Fund => fund::run(), } } } diff --git a/src/subcommand/wallet/fund.rs b/src/subcommand/wallet/fund.rs new file mode 100644 index 0000000000..70e063c8df --- /dev/null +++ b/src/subcommand/wallet/fund.rs @@ -0,0 +1,16 @@ +use super::*; + +pub(crate) fn run() -> Result { + let key = get_key()?; + + let wallet = Wallet::new( + Bip84(key.clone(), KeychainKind::External), + Some(Bip84(key.clone(), KeychainKind::Internal)), + Network::Regtest, + SqliteDatabase::new("foo".into()), + )?; + + println!("{}", wallet.get_address(LastUnused)?); + + Ok(()) +} diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index 194d2aeb01..0e339088f8 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -1,38 +1,13 @@ use super::*; -use bdk::{ - blockchain::{ - rpc::{Auth, RpcBlockchain, RpcConfig}, - ConfigurableBlockchain, - }, - database::SqliteDatabase, - keys::{ - bip39::{Language, Mnemonic, WordCount}, - DerivableKey, GeneratableKey, - }, - miniscript::miniscript::Segwitv0, - template::Bip84, - wallet::{wallet_name_from_descriptor, SyncOptions}, - KeychainKind, Wallet, -}; - -fn generate_key() -> Result + Clone> { - let password = Some("password".to_string()); - - let mnemonic = Mnemonic::generate((WordCount::Words12, Language::English)) - .map_err(|err| err.expect("Failed to generate mnemonic"))?; - - Ok((mnemonic, password)) -} - pub(crate) fn run(options: Options) -> Result { println!("[~] Setting up ordinal wallet..."); - let key = generate_key()?; + let key = get_key()?; let wallet = Wallet::new( Bip84(key.clone(), KeychainKind::External), - Some(Bip84(key.clone(), KeychainKind::Internal)), + None, Network::Regtest, SqliteDatabase::new("foo".into()), )?; @@ -49,7 +24,7 @@ pub(crate) fn run(options: Options) -> Result { network: Network::Regtest, wallet_name: wallet_name_from_descriptor( Bip84(key.clone(), KeychainKind::External), - Some(Bip84(key, KeychainKind::Internal)), + None, Network::Regtest, &Secp256k1::new(), )?, diff --git a/tests/lib.rs b/tests/lib.rs index 73f182d929..1fbd33f53e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -40,6 +40,7 @@ mod server; mod supply; mod traits; mod version; +mod wallet; type Result = std::result::Result>; diff --git a/tests/wallet.rs b/tests/wallet.rs new file mode 100644 index 0000000000..075cc0e156 --- /dev/null +++ b/tests/wallet.rs @@ -0,0 +1,9 @@ +use super::*; + +#[test] +fn fund() -> Result { + Test::new()? + .command("wallet fund") + .expected_stdout("bcrt1qtprrd8eadw3kd4h44yplkh85mj3hv0qw76tgj7\n") + .run() +} From 74649309ace33047bbef1f8cc4cd300e76f5fee2 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 17:36:12 -0400 Subject: [PATCH 09/24] Make tests work --- src/main.rs | 3 ++- src/subcommand/wallet.rs | 17 ++++++++++++++- src/subcommand/wallet/fund.rs | 9 +------- src/subcommand/wallet/init.rs | 36 +++--------------------------- tests/lib.rs | 41 +++++++++++++++++++++++++++++++++-- tests/wallet.rs | 20 +++++++++++++++-- 6 files changed, 79 insertions(+), 47 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5df75339f5..316061933c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use { miniscript::miniscript::Segwitv0, template::Bip84, wallet::{wallet_name_from_descriptor, AddressIndex::LastUnused, SyncOptions}, - KeychainKind, Wallet, + KeychainKind, }, bech32::{FromBase32, ToBase32}, bitcoin::{ @@ -59,6 +59,7 @@ use { }, tokio::runtime::Runtime, tower_http::cors::{Any, CorsLayer}, + dirs::data_dir }; #[cfg(feature = "redb")] diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 491677e176..fc92dee15b 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -3,13 +3,28 @@ use super::*; mod fund; mod init; -pub(crate) fn get_key() -> Result + Clone> { +fn get_key() -> Result + Clone> { Ok(( Mnemonic::parse("book fit fly ketchup also elevator scout mind edit fatal where rookie")?, None, )) } +fn get_wallet() -> Result> { + let db_path = PathBuf::from(format!("{}/ord", data_dir().unwrap().display())); + + if !db_path.exists() { + fs::create_dir_all(&db_path)?; + } + + Ok(bdk::wallet::Wallet::new( + Bip84(get_key()?, KeychainKind::External), + None, + Network::Signet, + SqliteDatabase::new(format!("{}/wallet.sqlite", db_path.display())), + )?) +} + #[derive(Parser)] pub(crate) enum Wallet { Init, diff --git a/src/subcommand/wallet/fund.rs b/src/subcommand/wallet/fund.rs index 70e063c8df..b5e28b846a 100644 --- a/src/subcommand/wallet/fund.rs +++ b/src/subcommand/wallet/fund.rs @@ -1,14 +1,7 @@ use super::*; pub(crate) fn run() -> Result { - let key = get_key()?; - - let wallet = Wallet::new( - Bip84(key.clone(), KeychainKind::External), - Some(Bip84(key.clone(), KeychainKind::Internal)), - Network::Regtest, - SqliteDatabase::new("foo".into()), - )?; + let wallet = get_wallet()?; println!("{}", wallet.get_address(LastUnused)?); diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index 0e339088f8..3b167b085d 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -1,39 +1,9 @@ use super::*; -pub(crate) fn run(options: Options) -> Result { - println!("[~] Setting up ordinal wallet..."); +pub(crate) fn run(_options: Options) -> Result { + get_wallet()?; - let key = get_key()?; - - let wallet = Wallet::new( - Bip84(key.clone(), KeychainKind::External), - None, - Network::Regtest, - SqliteDatabase::new("foo".into()), - )?; - - wallet.sync( - &RpcBlockchain::from_config(&RpcConfig { - url: options - .rpc_url - .ok_or_else(|| anyhow!("This command requires `--rpc-url`"))?, - auth: options - .cookie_file - .map(|path| Auth::Cookie { file: path }) - .unwrap_or(Auth::None), - network: Network::Regtest, - wallet_name: wallet_name_from_descriptor( - Bip84(key.clone(), KeychainKind::External), - None, - Network::Regtest, - &Secp256k1::new(), - )?, - skip_blocks: None, - })?, - SyncOptions::default(), - )?; - - println!("Setup complete."); + eprintln!("Wallet initialized."); Ok(()) } diff --git a/tests/lib.rs b/tests/lib.rs index 1fbd33f53e..c9076b8763 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -6,6 +6,7 @@ use { blockdata::constants::COIN_VALUE, blockdata::script, consensus::Encodable, Block, BlockHash, BlockHeader, OutPoint, Transaction, TxIn, TxOut, Witness, }, + dirs::data_dir, executable_path::executable_path, nix::{ sys::signal::{self, Signal}, @@ -14,9 +15,11 @@ use { regex::Regex, std::{ collections::BTreeSet, + env, error::Error, fs, net::TcpListener, + path::PathBuf, process::{Command, Stdio}, str, sync::{Arc, Mutex}, @@ -85,10 +88,12 @@ struct TransactionOptions<'a> { struct Test { args: Vec, + env: Vec<(String, String)>, + events: Vec, + expected_path: Option, expected_status: i32, expected_stderr: Option, expected_stdout: Expected, - events: Vec, tempdir: TempDir, } @@ -100,10 +105,12 @@ impl Test { fn with_tempdir(tempdir: TempDir) -> Self { Self { args: Vec::new(), + env: Vec::new(), + events: Vec::new(), + expected_path: None, expected_status: 0, expected_stderr: None, expected_stdout: Expected::String(String::new()), - events: Vec::new(), tempdir, } } @@ -142,6 +149,19 @@ impl Test { } } + fn env(mut self, key: &str, value: &str) -> Self { + self.env.push((key.to_owned(), value.to_owned())); + self + } + + fn set_home_to_tempdir(mut self) -> Self { + self.env.push(( + "HOME".to_string(), + self.tempdir.path().to_str().unwrap().to_string(), + )); + self + } + fn expected_stderr(self, expected_stderr: &str) -> Self { Self { expected_stderr: Some(expected_stderr.to_owned()), @@ -156,6 +176,13 @@ impl Test { } } + fn expected_path(self, expected_path: &str) -> Self { + Self { + expected_path: Some(expected_path.to_owned()), + ..self + } + } + fn ignore_stdout(self) -> Self { Self { expected_stdout: Expected::Ignore, @@ -205,6 +232,7 @@ impl Test { }; let child = Command::new(executable_path("ord")) + .envs(self.env) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(if self.expected_stderr.is_some() { @@ -299,6 +327,15 @@ impl Test { Expected::Ignore => {} } + if let Some(expected_path) = self.expected_path { + assert!(PathBuf::from(format!( + "{}/{}", + self.tempdir.path().display(), + expected_path + )) + .exists()); + } + assert_eq!( successful_requests, self diff --git a/tests/wallet.rs b/tests/wallet.rs index 075cc0e156..030f1ae68b 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -1,9 +1,25 @@ use super::*; +#[test] +fn init() -> Result { + let test = Test::new()?; + + test + .command("wallet init") + .set_home_to_tempdir() + .expected_status(0) + .expected_stderr("Wallet initialized.\n") + .expected_path("Library/Application Support/ord/wallet.sqlite") + .run() +} + #[test] fn fund() -> Result { - Test::new()? + let test = Test::new()?; + + test .command("wallet fund") - .expected_stdout("bcrt1qtprrd8eadw3kd4h44yplkh85mj3hv0qw76tgj7\n") + .set_home_to_tempdir() + .expected_stdout("tb1qtprrd8eadw3kd4h44yplkh85mj3hv0qwunj99h\n") .run() } From 1baaad1ed41aacddb88fa0188ef94f6d95e392cb Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 17:42:03 -0400 Subject: [PATCH 10/24] Remove unwraps --- src/subcommand/wallet.rs | 12 ++++++++++-- tests/lib.rs | 5 ----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index fc92dee15b..80eb7c652c 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -11,7 +11,9 @@ fn get_key() -> Result + Clone> { } fn get_wallet() -> Result> { - let db_path = PathBuf::from(format!("{}/ord", data_dir().unwrap().display())); + let db_path = data_dir() + .ok_or(anyhow!("Failed to retrieve data dir"))? + .join("ord"); if !db_path.exists() { fs::create_dir_all(&db_path)?; @@ -21,7 +23,13 @@ fn get_wallet() -> Result> { Bip84(get_key()?, KeychainKind::External), None, Network::Signet, - SqliteDatabase::new(format!("{}/wallet.sqlite", db_path.display())), + SqliteDatabase::new( + db_path + .join("wallet.sqlite") + .to_str() + .ok_or(anyhow!("Failed to convert path to str"))? + .to_string(), + ), )?) } diff --git a/tests/lib.rs b/tests/lib.rs index c9076b8763..0e867d53a5 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -149,11 +149,6 @@ impl Test { } } - fn env(mut self, key: &str, value: &str) -> Self { - self.env.push((key.to_owned(), value.to_owned())); - self - } - fn set_home_to_tempdir(mut self) -> Self { self.env.push(( "HOME".to_string(), From 12e66ab43f124459e952af9a31463ae5d6a40b0c Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 17:46:27 -0400 Subject: [PATCH 11/24] Clippy --- src/main.rs | 13 +++---------- src/subcommand/wallet.rs | 4 ++-- tests/lib.rs | 10 +--------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 316061933c..4c6a08d689 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,18 +9,11 @@ use { axum::{extract, http::StatusCode, response::IntoResponse, routing::get, Json, Router}, axum_server::Handle, bdk::{ - blockchain::{ - rpc::{Auth, RpcBlockchain, RpcConfig}, - ConfigurableBlockchain, - }, database::SqliteDatabase, - keys::{ - bip39::{Language, Mnemonic, WordCount}, - DerivableKey, GeneratableKey, - }, + keys::{bip39::Mnemonic, DerivableKey}, miniscript::miniscript::Segwitv0, template::Bip84, - wallet::{wallet_name_from_descriptor, AddressIndex::LastUnused, SyncOptions}, + wallet::AddressIndex::LastUnused, KeychainKind, }, bech32::{FromBase32, ToBase32}, @@ -32,6 +25,7 @@ use { chrono::{DateTime, NaiveDateTime, Utc}, clap::Parser, derive_more::{Display, FromStr}, + dirs::data_dir, integer_cbrt::IntegerCubeRoot, integer_sqrt::IntegerSquareRoot, lazy_static::lazy_static, @@ -59,7 +53,6 @@ use { }, tokio::runtime::Runtime, tower_http::cors::{Any, CorsLayer}, - dirs::data_dir }; #[cfg(feature = "redb")] diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 80eb7c652c..0f703ce265 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -12,7 +12,7 @@ fn get_key() -> Result + Clone> { fn get_wallet() -> Result> { let db_path = data_dir() - .ok_or(anyhow!("Failed to retrieve data dir"))? + .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? .join("ord"); if !db_path.exists() { @@ -27,7 +27,7 @@ fn get_wallet() -> Result> { db_path .join("wallet.sqlite") .to_str() - .ok_or(anyhow!("Failed to convert path to str"))? + .ok_or_else(|| anyhow!("Failed to convert path to str"))? .to_string(), ), )?) diff --git a/tests/lib.rs b/tests/lib.rs index 0e867d53a5..276320ff95 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -6,7 +6,6 @@ use { blockdata::constants::COIN_VALUE, blockdata::script, consensus::Encodable, Block, BlockHash, BlockHeader, OutPoint, Transaction, TxIn, TxOut, Witness, }, - dirs::data_dir, executable_path::executable_path, nix::{ sys::signal::{self, Signal}, @@ -15,11 +14,9 @@ use { regex::Regex, std::{ collections::BTreeSet, - env, error::Error, fs, net::TcpListener, - path::PathBuf, process::{Command, Stdio}, str, sync::{Arc, Mutex}, @@ -323,12 +320,7 @@ impl Test { } if let Some(expected_path) = self.expected_path { - assert!(PathBuf::from(format!( - "{}/{}", - self.tempdir.path().display(), - expected_path - )) - .exists()); + assert!(self.tempdir.path().join(expected_path).exists()); } assert_eq!( From e92e8866b403be994f0922f47ec3d6baf779f867 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 17:55:55 -0400 Subject: [PATCH 12/24] Cleaner --- tests/wallet.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/wallet.rs b/tests/wallet.rs index 030f1ae68b..fbeecece9a 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -2,9 +2,7 @@ use super::*; #[test] fn init() -> Result { - let test = Test::new()?; - - test + Test::new()? .command("wallet init") .set_home_to_tempdir() .expected_status(0) @@ -15,9 +13,7 @@ fn init() -> Result { #[test] fn fund() -> Result { - let test = Test::new()?; - - test + Test::new()? .command("wallet fund") .set_home_to_tempdir() .expected_stdout("tb1qtprrd8eadw3kd4h44yplkh85mj3hv0qwunj99h\n") From b97e4bd2a937a864462d72b8bd274075ccdad2c1 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 17:56:40 -0400 Subject: [PATCH 13/24] Also set linux variable --- tests/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/lib.rs b/tests/lib.rs index 276320ff95..12719a0555 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -151,6 +151,12 @@ impl Test { "HOME".to_string(), self.tempdir.path().to_str().unwrap().to_string(), )); + + self.env.push(( + "XDG_DATA_HOME".to_string(), + self.tempdir.path().to_str().unwrap().to_string(), + )); + self } From 1c895955c056ccc4c11481f22c442dc50c67fe3b Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 18:01:40 -0400 Subject: [PATCH 14/24] Check different path for linux --- tests/wallet.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/wallet.rs b/tests/wallet.rs index fbeecece9a..ffc968444f 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -1,6 +1,7 @@ use super::*; #[test] +#[cfg(target_os = "macos")] fn init() -> Result { Test::new()? .command("wallet init") @@ -11,6 +12,18 @@ fn init() -> Result { .run() } +#[test] +#[cfg(target_os = "linux")] +fn init() -> Result { + Test::new()? + .command("wallet init") + .set_home_to_tempdir() + .expected_status(0) + .expected_stderr("Wallet initialized.\n") + .expected_path(".local/share/ord/wallet.sqlite") + .run() +} + #[test] fn fund() -> Result { Test::new()? From 948187318360b4466ad066e7c309a86128ed6f69 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 18:06:41 -0400 Subject: [PATCH 15/24] Don't create another test --- tests/wallet.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/wallet.rs b/tests/wallet.rs index ffc968444f..2780eb938c 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -1,26 +1,17 @@ use super::*; #[test] -#[cfg(target_os = "macos")] fn init() -> Result { Test::new()? .command("wallet init") .set_home_to_tempdir() .expected_status(0) .expected_stderr("Wallet initialized.\n") - .expected_path("Library/Application Support/ord/wallet.sqlite") - .run() -} - -#[test] -#[cfg(target_os = "linux")] -fn init() -> Result { - Test::new()? - .command("wallet init") - .set_home_to_tempdir() - .expected_status(0) - .expected_stderr("Wallet initialized.\n") - .expected_path(".local/share/ord/wallet.sqlite") + .expected_path(if cfg!(target_os = "macos") { + "Library/Application Support/ord/wallet.sqlite" + } else { + ".local/share/ord/wallet.sqlite" + }) .run() } From 5b8bda910ef336fd88946f26288fca93317689d0 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 18:35:02 -0400 Subject: [PATCH 16/24] Remove expected_path --- tests/lib.rs | 13 ------------- tests/wallet.rs | 13 ++++++++++--- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index 12719a0555..34ffb0f588 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -87,7 +87,6 @@ struct Test { args: Vec, env: Vec<(String, String)>, events: Vec, - expected_path: Option, expected_status: i32, expected_stderr: Option, expected_stdout: Expected, @@ -104,7 +103,6 @@ impl Test { args: Vec::new(), env: Vec::new(), events: Vec::new(), - expected_path: None, expected_status: 0, expected_stderr: None, expected_stdout: Expected::String(String::new()), @@ -174,13 +172,6 @@ impl Test { } } - fn expected_path(self, expected_path: &str) -> Self { - Self { - expected_path: Some(expected_path.to_owned()), - ..self - } - } - fn ignore_stdout(self) -> Self { Self { expected_stdout: Expected::Ignore, @@ -325,10 +316,6 @@ impl Test { Expected::Ignore => {} } - if let Some(expected_path) = self.expected_path { - assert!(self.tempdir.path().join(expected_path).exists()); - } - assert_eq!( successful_requests, self diff --git a/tests/wallet.rs b/tests/wallet.rs index 2780eb938c..468ab09efe 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -2,17 +2,24 @@ use super::*; #[test] fn init() -> Result { - Test::new()? + let tempdir = Test::new()? .command("wallet init") .set_home_to_tempdir() .expected_status(0) .expected_stderr("Wallet initialized.\n") - .expected_path(if cfg!(target_os = "macos") { + .output()? + .tempdir; + + assert!(tempdir + .path() + .join(if cfg!(target_os = "macos") { "Library/Application Support/ord/wallet.sqlite" } else { ".local/share/ord/wallet.sqlite" }) - .run() + .exists()); + + Ok(()) } #[test] From 2f007cd95092189c90bd359e6ede5c7d8d440326 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 19:05:47 -0400 Subject: [PATCH 17/24] Add more comprehensive tests --- src/subcommand/wallet.rs | 29 ++++++++++++++++++++- src/subcommand/wallet/init.rs | 2 +- tests/wallet.rs | 48 ++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 0f703ce265..557f6a6249 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -10,13 +10,40 @@ fn get_key() -> Result + Clone> { )) } +fn init_wallet() -> Result { + let db_path = data_dir() + .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? + .join("ord"); + + if db_path.exists() { + return Err(anyhow!("Wallet already exists.")); + } + + fs::create_dir_all(&db_path)?; + + bdk::wallet::Wallet::new( + Bip84(get_key()?, KeychainKind::External), + None, + Network::Signet, + SqliteDatabase::new( + db_path + .join("wallet.sqlite") + .to_str() + .ok_or_else(|| anyhow!("Failed to convert path to str"))? + .to_string(), + ), + )?; + + Ok(()) +} + fn get_wallet() -> Result> { let db_path = data_dir() .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? .join("ord"); if !db_path.exists() { - fs::create_dir_all(&db_path)?; + return Err(anyhow!("Wallet doesn't exist.")); } Ok(bdk::wallet::Wallet::new( diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index 3b167b085d..c936f1ccf8 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -1,7 +1,7 @@ use super::*; pub(crate) fn run(_options: Options) -> Result { - get_wallet()?; + init_wallet()?; eprintln!("Wallet initialized."); diff --git a/tests/wallet.rs b/tests/wallet.rs index 468ab09efe..77c6c9d968 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -19,14 +19,60 @@ fn init() -> Result { }) .exists()); + Test::with_tempdir(tempdir) + .command("wallet init") + .set_home_to_tempdir() + .expected_status(1) + .expected_stderr("error: Wallet already exists.\n") + .run() +} + +#[test] +fn init_nonexistent_wallet() -> Result { + let tempdir = Test::new()? + .command("wallet init") + .set_home_to_tempdir() + .expected_status(0) + .expected_stderr("Wallet initialized.\n") + .output()? + .tempdir; + + assert!(tempdir + .path() + .join(if cfg!(target_os = "macos") { + "Library/Application Support/ord/wallet.sqlite" + } else { + ".local/share/ord/wallet.sqlite" + }) + .exists()); + Ok(()) } #[test] fn fund() -> Result { - Test::new()? + let tempdir = Test::new()? + .command("wallet init") + .set_home_to_tempdir() + .expected_status(0) + .expected_stderr("Wallet initialized.\n") + .set_home_to_tempdir() + .output()? + .tempdir; + + Test::with_tempdir(tempdir) .command("wallet fund") .set_home_to_tempdir() .expected_stdout("tb1qtprrd8eadw3kd4h44yplkh85mj3hv0qwunj99h\n") .run() } + +#[test] +fn fund_nonexistent_wallet() -> Result { + Test::new()? + .command("wallet fund") + .set_home_to_tempdir() + .expected_status(1) + .expected_stderr("error: Wallet doesn't exist.\n") + .run() +} From 12d84b1533a98d900f1f83e92972a6de89235b90 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 19:09:33 -0400 Subject: [PATCH 18/24] env -> envs --- tests/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index 34ffb0f588..c406eb4757 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -85,7 +85,7 @@ struct TransactionOptions<'a> { struct Test { args: Vec, - env: Vec<(String, String)>, + envs: Vec<(String, String)>, events: Vec, expected_status: i32, expected_stderr: Option, @@ -101,7 +101,7 @@ impl Test { fn with_tempdir(tempdir: TempDir) -> Self { Self { args: Vec::new(), - env: Vec::new(), + envs: Vec::new(), events: Vec::new(), expected_status: 0, expected_stderr: None, @@ -145,12 +145,12 @@ impl Test { } fn set_home_to_tempdir(mut self) -> Self { - self.env.push(( + self.envs.push(( "HOME".to_string(), self.tempdir.path().to_str().unwrap().to_string(), )); - self.env.push(( + self.envs.push(( "XDG_DATA_HOME".to_string(), self.tempdir.path().to_str().unwrap().to_string(), )); @@ -221,7 +221,7 @@ impl Test { }; let child = Command::new(executable_path("ord")) - .envs(self.env) + .envs(self.envs) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(if self.expected_stderr.is_some() { From 765fa0773f8fb685fc808287e7f1dfe6ec4ce718 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 18 Jul 2022 19:14:06 -0400 Subject: [PATCH 19/24] Use OsString --- tests/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index c406eb4757..58fa8c1963 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -15,6 +15,7 @@ use { std::{ collections::BTreeSet, error::Error, + ffi::OsString, fs, net::TcpListener, process::{Command, Stdio}, @@ -85,7 +86,7 @@ struct TransactionOptions<'a> { struct Test { args: Vec, - envs: Vec<(String, String)>, + envs: Vec<(OsString, OsString)>, events: Vec, expected_status: i32, expected_stderr: Option, @@ -146,13 +147,13 @@ impl Test { fn set_home_to_tempdir(mut self) -> Self { self.envs.push(( - "HOME".to_string(), - self.tempdir.path().to_str().unwrap().to_string(), + OsString::from("HOME"), + OsString::from(self.tempdir.path().to_str().unwrap()), )); self.envs.push(( - "XDG_DATA_HOME".to_string(), - self.tempdir.path().to_str().unwrap().to_string(), + OsString::from("XDG_DATA_HOME".to_string()), + OsString::from(self.tempdir.path().to_str().unwrap()), )); self From b9658040f45b8ed3b1ff532305d83ac090d7a143 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 19 Jul 2022 10:09:07 -0400 Subject: [PATCH 20/24] Rebuild --- Cargo.lock | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8fad10b90c..20e1f15867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,9 +340,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" [[package]] name = "cast" @@ -1142,9 +1142,9 @@ dependencies = [ [[package]] name = "image" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28edd9d7bc256be2502e325ac0628bde30b7001b9b52e0abe31a1a9dc2701212" +checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964" dependencies = [ "bytemuck", "byteorder", @@ -1152,7 +1152,6 @@ dependencies = [ "exr", "gif", "jpeg-decoder", - "num-iter", "num-rational", "num-traits", "png", @@ -1551,17 +1550,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg 1.1.0", - "num-integer", - "num-traits", -] - [[package]] name = "num-rational" version = "0.4.1" @@ -2410,9 +2398,12 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg 1.1.0", +] [[package]] name = "sled" From c0fb6cb8ca4974248f975dc35ac31a8d2a8eaf23 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 19 Jul 2022 16:22:58 -0400 Subject: [PATCH 21/24] Don't hardcode seed --- src/main.rs | 3 +-- src/subcommand/wallet.rs | 47 +++++++---------------------------- src/subcommand/wallet/init.rs | 27 +++++++++++++++++++- tests/wallet.rs | 36 +++++++++++++-------------- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4c6a08d689..0aabbe9ecb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,7 @@ use { axum_server::Handle, bdk::{ database::SqliteDatabase, - keys::{bip39::Mnemonic, DerivableKey}, - miniscript::miniscript::Segwitv0, + keys::bip39::{Language, Mnemonic}, template::Bip84, wallet::AddressIndex::LastUnused, KeychainKind, diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 557f6a6249..281d6084fd 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -3,55 +3,26 @@ use super::*; mod fund; mod init; -fn get_key() -> Result + Clone> { - Ok(( - Mnemonic::parse("book fit fly ketchup also elevator scout mind edit fatal where rookie")?, - None, - )) -} - -fn init_wallet() -> Result { - let db_path = data_dir() - .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? - .join("ord"); - - if db_path.exists() { - return Err(anyhow!("Wallet already exists.")); - } - - fs::create_dir_all(&db_path)?; - - bdk::wallet::Wallet::new( - Bip84(get_key()?, KeychainKind::External), - None, - Network::Signet, - SqliteDatabase::new( - db_path - .join("wallet.sqlite") - .to_str() - .ok_or_else(|| anyhow!("Failed to convert path to str"))? - .to_string(), - ), - )?; - - Ok(()) -} - fn get_wallet() -> Result> { - let db_path = data_dir() + let path = data_dir() .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? .join("ord"); - if !db_path.exists() { + if !path.exists() { return Err(anyhow!("Wallet doesn't exist.")); } + let entropy = fs::read(path.join("seed.txt"))?; + Ok(bdk::wallet::Wallet::new( - Bip84(get_key()?, KeychainKind::External), + Bip84( + (Mnemonic::from_entropy(&entropy)?, None), + KeychainKind::External, + ), None, Network::Signet, SqliteDatabase::new( - db_path + path .join("wallet.sqlite") .to_str() .ok_or_else(|| anyhow!("Failed to convert path to str"))? diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index c936f1ccf8..3264276e02 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -1,7 +1,32 @@ use super::*; pub(crate) fn run(_options: Options) -> Result { - init_wallet()?; + let path = data_dir() + .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? + .join("ord"); + + if path.exists() { + return Err(anyhow!("Wallet already exists.")); + } + + fs::create_dir_all(&path)?; + + let seed = Mnemonic::generate_in_with(&mut rand::thread_rng(), Language::English, 12)?; + + fs::write(path.join("seed.txt"), seed.to_entropy())?; + + bdk::wallet::Wallet::new( + Bip84((seed, None), KeychainKind::External), + None, + Network::Signet, + SqliteDatabase::new( + path + .join("wallet.sqlite") + .to_str() + .ok_or_else(|| anyhow!("Failed to convert path to str"))? + .to_string(), + ), + )?; eprintln!("Wallet initialized."); diff --git a/tests/wallet.rs b/tests/wallet.rs index 77c6c9d968..4d94e6dbbc 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -1,7 +1,15 @@ use super::*; +fn path(path: &str) -> String { + if cfg!(target_os = "macos") { + format!("Library/Application Support/{}", path) + } else { + format!(".local/share/{}", path) + } +} + #[test] -fn init() -> Result { +fn init_existing_wallet() -> Result { let tempdir = Test::new()? .command("wallet init") .set_home_to_tempdir() @@ -10,14 +18,9 @@ fn init() -> Result { .output()? .tempdir; - assert!(tempdir - .path() - .join(if cfg!(target_os = "macos") { - "Library/Application Support/ord/wallet.sqlite" - } else { - ".local/share/ord/wallet.sqlite" - }) - .exists()); + assert!(tempdir.path().join(path("ord/wallet.sqlite")).exists()); + + assert!(tempdir.path().join(path("ord/seed.txt")).exists()); Test::with_tempdir(tempdir) .command("wallet init") @@ -37,20 +40,15 @@ fn init_nonexistent_wallet() -> Result { .output()? .tempdir; - assert!(tempdir - .path() - .join(if cfg!(target_os = "macos") { - "Library/Application Support/ord/wallet.sqlite" - } else { - ".local/share/ord/wallet.sqlite" - }) - .exists()); + assert!(tempdir.path().join(path("ord/wallet.sqlite")).exists()); + + assert!(tempdir.path().join(path("ord/seed.txt")).exists()); Ok(()) } #[test] -fn fund() -> Result { +fn fund_existing_wallet() -> Result { let tempdir = Test::new()? .command("wallet init") .set_home_to_tempdir() @@ -63,7 +61,7 @@ fn fund() -> Result { Test::with_tempdir(tempdir) .command("wallet fund") .set_home_to_tempdir() - .expected_stdout("tb1qtprrd8eadw3kd4h44yplkh85mj3hv0qwunj99h\n") + .stdout_regex("*\n") .run() } From 4fe52765288d35ee308478e26df1fc12198617a9 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 19 Jul 2022 16:39:33 -0400 Subject: [PATCH 22/24] Address some of the review comments --- Cargo.lock | 1 - Cargo.toml | 2 +- src/subcommand.rs | 2 +- src/subcommand/wallet.rs | 32 ++------------------------------ src/subcommand/wallet/fund.rs | 26 +++++++++++++++++++++++++- src/subcommand/wallet/init.rs | 4 ++-- tests/lib.rs | 9 ++++----- tests/wallet.rs | 9 +++++++-- 8 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20e1f15867..c56495e48f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,6 @@ dependencies = [ "bdk-macros", "bip39", "bitcoin", - "bitcoincore-rpc", "electrum-client", "js-sys", "log", diff --git a/Cargo.toml b/Cargo.toml index 093ac98646..aff0d9e6bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ autotests = false anyhow = { version = "1.0.56", features = ["backtrace"] } axum = "0.5.6" axum-server = "0.4.0" -bdk = { version = "0.20.0", features = ["rpc", "keys-bip39", "sqlite"] } +bdk = { version = "0.20.0", features = ["keys-bip39", "sqlite"] } bech32 = "0.9.0" bitcoin = "0.28.1" bitcoin_hashes = "0.10.0" diff --git a/src/subcommand.rs b/src/subcommand.rs index a12e353659..940c7eda42 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -53,7 +53,7 @@ impl Subcommand { Self::Supply => supply::run(), Self::Traits(traits) => traits.run(), Self::Verify(verify) => verify.run(), - Self::Wallet(wallet) => wallet.run(options), + Self::Wallet(wallet) => wallet.run(), } } } diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index 281d6084fd..da16cc4762 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -3,34 +3,6 @@ use super::*; mod fund; mod init; -fn get_wallet() -> Result> { - let path = data_dir() - .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? - .join("ord"); - - if !path.exists() { - return Err(anyhow!("Wallet doesn't exist.")); - } - - let entropy = fs::read(path.join("seed.txt"))?; - - Ok(bdk::wallet::Wallet::new( - Bip84( - (Mnemonic::from_entropy(&entropy)?, None), - KeychainKind::External, - ), - None, - Network::Signet, - SqliteDatabase::new( - path - .join("wallet.sqlite") - .to_str() - .ok_or_else(|| anyhow!("Failed to convert path to str"))? - .to_string(), - ), - )?) -} - #[derive(Parser)] pub(crate) enum Wallet { Init, @@ -38,9 +10,9 @@ pub(crate) enum Wallet { } impl Wallet { - pub(crate) fn run(self, options: Options) -> Result { + pub(crate) fn run(self) -> Result { match self { - Self::Init => init::run(options), + Self::Init => init::run(), Self::Fund => fund::run(), } } diff --git a/src/subcommand/wallet/fund.rs b/src/subcommand/wallet/fund.rs index b5e28b846a..1ac414f9e3 100644 --- a/src/subcommand/wallet/fund.rs +++ b/src/subcommand/wallet/fund.rs @@ -1,7 +1,31 @@ use super::*; pub(crate) fn run() -> Result { - let wallet = get_wallet()?; + let path = data_dir() + .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? + .join("ord"); + + if !path.exists() { + return Err(anyhow!("Wallet doesn't exist.")); + } + + let entropy = fs::read(path.join("entropy"))?; + + let wallet = bdk::wallet::Wallet::new( + Bip84( + (Mnemonic::from_entropy(&entropy)?, None), + KeychainKind::External, + ), + None, + Network::Signet, + SqliteDatabase::new( + path + .join("wallet.sqlite") + .to_str() + .ok_or_else(|| anyhow!("Failed to convert path to str"))? + .to_string(), + ), + )?; println!("{}", wallet.get_address(LastUnused)?); diff --git a/src/subcommand/wallet/init.rs b/src/subcommand/wallet/init.rs index 3264276e02..986cc62813 100644 --- a/src/subcommand/wallet/init.rs +++ b/src/subcommand/wallet/init.rs @@ -1,6 +1,6 @@ use super::*; -pub(crate) fn run(_options: Options) -> Result { +pub(crate) fn run() -> Result { let path = data_dir() .ok_or_else(|| anyhow!("Failed to retrieve data dir"))? .join("ord"); @@ -13,7 +13,7 @@ pub(crate) fn run(_options: Options) -> Result { let seed = Mnemonic::generate_in_with(&mut rand::thread_rng(), Language::English, 12)?; - fs::write(path.join("seed.txt"), seed.to_entropy())?; + fs::write(path.join("entropy"), seed.to_entropy())?; bdk::wallet::Wallet::new( Bip84((seed, None), KeychainKind::External), diff --git a/tests/lib.rs b/tests/lib.rs index 58fa8c1963..a12b191eff 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -146,14 +146,13 @@ impl Test { } fn set_home_to_tempdir(mut self) -> Self { - self.envs.push(( - OsString::from("HOME"), - OsString::from(self.tempdir.path().to_str().unwrap()), - )); + self + .envs + .push((OsString::from("HOME"), OsString::from(self.tempdir.path()))); self.envs.push(( OsString::from("XDG_DATA_HOME".to_string()), - OsString::from(self.tempdir.path().to_str().unwrap()), + OsString::from(self.tempdir.path()), )); self diff --git a/tests/wallet.rs b/tests/wallet.rs index 4d94e6dbbc..82e86f18b5 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -20,7 +20,7 @@ fn init_existing_wallet() -> Result { assert!(tempdir.path().join(path("ord/wallet.sqlite")).exists()); - assert!(tempdir.path().join(path("ord/seed.txt")).exists()); + assert!(tempdir.path().join(path("ord/entropy")).exists()); Test::with_tempdir(tempdir) .command("wallet init") @@ -42,11 +42,16 @@ fn init_nonexistent_wallet() -> Result { assert!(tempdir.path().join(path("ord/wallet.sqlite")).exists()); - assert!(tempdir.path().join(path("ord/seed.txt")).exists()); + assert!(tempdir.path().join(path("ord/entropy")).exists()); Ok(()) } +#[test] +fn load_corrupted_entropy() -> Result { + Ok(()) +} + #[test] fn fund_existing_wallet() -> Result { let tempdir = Test::new()? From e44f205a6dd706592b4e2ba0e4eb4b4299bf8c3c Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 19 Jul 2022 17:02:42 -0400 Subject: [PATCH 23/24] Add corrupted entropy test --- tests/wallet.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/wallet.rs b/tests/wallet.rs index 82e86f18b5..bf8e23dfa7 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -49,6 +49,30 @@ fn init_nonexistent_wallet() -> Result { #[test] fn load_corrupted_entropy() -> Result { + let tempdir = Test::new()? + .command("wallet init") + .set_home_to_tempdir() + .expected_status(0) + .expected_stderr("Wallet initialized.\n") + .output()? + .tempdir; + + let entropy_path = tempdir.path().join(path("ord/entropy")); + + assert!(entropy_path.exists()); + + let mut entropy = fs::read(&entropy_path)?; + entropy[0] ^= 0b0000_1000; + + fs::write(&entropy_path, entropy)?; + + Test::with_tempdir(tempdir) + .command("wallet fund") + .set_home_to_tempdir() + .expected_status(1) + .expected_stderr("error: ChecksumMismatch\n") + .run()?; + Ok(()) } @@ -66,7 +90,7 @@ fn fund_existing_wallet() -> Result { Test::with_tempdir(tempdir) .command("wallet fund") .set_home_to_tempdir() - .stdout_regex("*\n") + .stdout_regex("^tb1.*\n") .run() } From f4610723507fa95dd44ae65807ea185c7854782e Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 19 Jul 2022 18:08:15 -0400 Subject: [PATCH 24/24] Don't set xdg data dir --- tests/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index 07bf2b6411..bdac4e089a 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -150,11 +150,6 @@ impl Test { .envs .push((OsString::from("HOME"), OsString::from(self.tempdir.path()))); - self.envs.push(( - OsString::from("XDG_DATA_HOME".to_string()), - OsString::from(self.tempdir.path()), - )); - self }