From d591d70db882b2f2db4da3a080b8471b9420c55f Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Thu, 27 Jun 2024 22:11:53 +0200 Subject: [PATCH 1/7] chore: update bp dependency to use StoredWallet --- Cargo.lock | 3 +-- Cargo.toml | 3 +++ cli/src/args.rs | 2 +- src/errors.rs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 503e7a6..f7fe07e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,8 +519,7 @@ dependencies = [ [[package]] name = "bp-wallet" version = "0.11.0-beta.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08b287e3c8fc890c9b9d8b41e822314d6209b96fcb319ee951b1fb66db7f1a3d" +source = "git+https://github.com/BP-WG/bp-wallet?branch=runtime#9f319d0684a7e2b54c4c7cf6a0143007dae8ec55" dependencies = [ "amplify", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 35909d7..1d117f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,3 +91,6 @@ serde = ["serde_crate", "serde_yaml", "bp-std/serde", "descriptors/serde", "rgb- [package.metadata.docs.rs] features = ["all"] + +[patch.crates-io] +bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "runtime" } diff --git a/cli/src/args.rs b/cli/src/args.rs index 63124b6..246528d 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -121,7 +121,7 @@ impl RgbArgs { stock: Stock, ) -> Result>, WalletError> { let stock_path = self.general.base_dir(); - let wallet = self.inner.bp_runtime::(config)?; + let wallet = self.inner.bp_wallet::(config)?; let wallet_path = wallet.path().clone(); let wallet = StoredWallet::attach(stock_path, wallet_path, stock, wallet.detach()); diff --git a/src/errors.rs b/src/errors.rs index 0632e29..3411bab 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -85,7 +85,7 @@ pub enum WalletError { #[cfg(feature = "fs")] #[from] #[from(bpwallet::LoadError)] - Bp(bpwallet::RuntimeError), + Bp(bpwallet::WalletError), /// resolver error: {0} #[display(doc_comments)] From 08ec7a61fad575aec53c3a97e8df84b494b40349 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 30 Jun 2024 17:39:38 +0200 Subject: [PATCH 2/7] fix module name conflict --- cli/src/args.rs | 7 ++++--- src/{resolvers => indexers}/any.rs | 0 src/{resolvers => indexers}/electrum_blocking.rs | 0 src/{resolvers => indexers}/esplora_blocking.rs | 0 src/{resolvers => indexers}/mod.rs | 0 src/lib.rs | 12 ++++++++---- 6 files changed, 12 insertions(+), 7 deletions(-) rename src/{resolvers => indexers}/any.rs (100%) rename src/{resolvers => indexers}/electrum_blocking.rs (100%) rename src/{resolvers => indexers}/esplora_blocking.rs (100%) rename src/{resolvers => indexers}/mod.rs (100%) diff --git a/cli/src/args.rs b/cli/src/args.rs index 246528d..95a82ab 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -28,9 +28,10 @@ use std::path::Path; use bpstd::{Wpkh, XpubDerivable}; use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts}; use bpwallet::Wallet; -use rgb::{AnyResolver, RgbDescr, StoredStock, StoredWallet, TapretKey, WalletError}; -use rgbstd::persistence::fs::{LoadFs, StoreFs}; -use rgbstd::persistence::Stock; +use rgb::persistence::fs::{LoadFs, StoreFs}; +use rgb::persistence::Stock; +use rgb::resolvers::AnyResolver; +use rgb::{RgbDescr, StoredStock, StoredWallet, TapretKey, WalletError}; use strict_types::encoding::{DecodeError, DeserializeError}; use crate::Command; diff --git a/src/resolvers/any.rs b/src/indexers/any.rs similarity index 100% rename from src/resolvers/any.rs rename to src/indexers/any.rs diff --git a/src/resolvers/electrum_blocking.rs b/src/indexers/electrum_blocking.rs similarity index 100% rename from src/resolvers/electrum_blocking.rs rename to src/indexers/electrum_blocking.rs diff --git a/src/resolvers/esplora_blocking.rs b/src/indexers/esplora_blocking.rs similarity index 100% rename from src/resolvers/esplora_blocking.rs rename to src/indexers/esplora_blocking.rs diff --git a/src/resolvers/mod.rs b/src/indexers/mod.rs similarity index 100% rename from src/resolvers/mod.rs rename to src/indexers/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 0602dd4..fa2d1a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,8 +26,7 @@ extern crate amplify; extern crate serde_crate as serde; mod descriptor; -#[allow(hidden_glob_reexports)] -mod resolvers; +mod indexers; mod wallet; pub mod pay; mod errors; @@ -37,9 +36,14 @@ mod store; pub use descriptor::{DescriptorRgb, RgbDescr, RgbKeychain, TapTweakAlreadyAssigned, TapretKey}; pub use errors::{CompletionError, CompositionError, HistoryError, PayError, WalletError}; pub use pay::{TransferParams, WalletProvider}; -#[cfg(any(feature = "electrum_blocking", feature = "esplora_blocking"))] -pub use resolvers::*; pub use rgbstd::*; +pub mod resolvers { + pub use rgbstd::resolvers::*; + + #[cfg(any(feature = "electrum_blocking", feature = "esplora_blocking"))] + pub use super::indexers::*; + pub use super::indexers::{AnyResolver, RgbResolver}; +} #[cfg(feature = "fs")] pub use store::{StoredStock, StoredWallet}; pub use wallet::{WalletStock, WalletWrapper}; From 5f1d047c193e93db37efb3b23fbfe6444b084f27 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 6 Jul 2024 08:28:56 +0200 Subject: [PATCH 3/7] refactor fs workflows --- Cargo.lock | 650 +-------------------------------------------- Cargo.toml | 2 + cli/src/args.rs | 30 +-- cli/src/command.rs | 4 +- src/errors.rs | 4 +- src/lib.rs | 4 +- src/pay.rs | 16 +- src/store.rs | 200 +++----------- src/wallet.rs | 19 +- 9 files changed, 94 insertions(+), 835 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7fe07e..df76ae9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - [[package]] name = "adler" version = "1.0.2" @@ -239,21 +230,6 @@ dependencies = [ "paste", ] -[[package]] -name = "backtrace" -version = "0.3.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "baid64" version = "0.2.2" @@ -261,17 +237,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95dabc2759e01e2c382968639868a701f384a18890934f9e75d4feb4d6623794" dependencies = [ "amplify", - "base64 0.22.1", + "base64", "mnemonic", "sha2", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -464,7 +434,6 @@ dependencies = [ "amplify", "bp-std", "log", - "reqwest", "serde", "serde_with", "sha2", @@ -519,16 +488,16 @@ dependencies = [ [[package]] name = "bp-wallet" version = "0.11.0-beta.6.1" -source = "git+https://github.com/BP-WG/bp-wallet?branch=runtime#9f319d0684a7e2b54c4c7cf6a0143007dae8ec55" +source = "git+https://github.com/BP-WG/bp-wallet?branch=runtime#b3cdda624394f6ade6f83076a43bc66078895c2a" dependencies = [ "amplify", - "base64 0.21.7", + "base64", "bp-electrum", "bp-esplora", "bp-std", "clap", "descriptors", - "env_logger 0.10.2", + "env_logger", "log", "psbt", "serde", @@ -551,12 +520,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.99" @@ -710,16 +673,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -870,19 +823,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.11.3" @@ -918,12 +858,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27ea9bdb2356e5a92403cf23ac493f9b43bd71e4ffd0f800862b841dd723994c" -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - [[package]] name = "flate2" version = "1.0.30" @@ -949,21 +883,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -979,39 +898,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-core", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1035,12 +921,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - [[package]] name = "glob" version = "0.3.1" @@ -1081,12 +961,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "hex" version = "0.4.3" @@ -1111,107 +985,12 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" -dependencies = [ - "bytes", - "futures-core", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower", - "tower-service", - "tracing", -] - [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1273,23 +1052,6 @@ dependencies = [ "serde", ] -[[package]] -name = "ipnet" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -1354,7 +1116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.5", + "windows-targets 0.48.5", ] [[package]] @@ -1406,17 +1168,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "mirai-annotations" version = "1.12.0" @@ -1429,23 +1180,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b8f3a258db515d5e91a904ce4ae3f73e091149b90cadbdb93d210bee07f63b" -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nom" version = "7.1.3" @@ -1471,65 +1205,12 @@ dependencies = [ "autocfg", ] -[[package]] -name = "object" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" -dependencies = [ - "bitflags 2.5.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -1548,44 +1229,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "powerfmt" version = "0.2.0" @@ -1624,7 +1267,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "500d928c69d44b90fa22f3209fb8d349b436ef8973754ccfa085a8db8392e422" dependencies = [ "amplify", - "base64 0.22.1", + "base64", "bp-core", "bp-derive", "chrono", @@ -1714,51 +1357,10 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" -[[package]] -name = "reqwest" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" -dependencies = [ - "base64 0.22.1", - "bytes", - "futures-core", - "futures-util", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-tls", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tokio-native-tls", - "tokio-socks", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "rgb-core" version = "0.11.0-beta.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd852c74f2b91711ef730a4aa5149442e2488425b3db811c6a55b72eb6db41d4" +source = "git+https://github.com/RGB-WG/rgb-core?branch=master#84892fd826f6f7805b076e70cba467b85c1eb8f7" dependencies = [ "aluvm", "amplify", @@ -1796,8 +1398,7 @@ dependencies = [ [[package]] name = "rgb-invoice" version = "0.11.0-beta.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0d31923f200cc460bf2b5afb3216e22f0851316538fa0ab69577b07a1212dc" +source = "git+https://github.com/RGB-WG/rgb-std?branch=runtime#f00e86085e13a342fbd2300e49f3e7f7242cdd9c" dependencies = [ "amplify", "baid64", @@ -1859,8 +1460,7 @@ dependencies = [ [[package]] name = "rgb-std" version = "0.11.0-beta.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6398107b0b11300118d7655b35b9d3bb02e5df77b06c94cd0827d84839b952fd" +source = "git+https://github.com/RGB-WG/rgb-std?branch=runtime#f00e86085e13a342fbd2300e49f3e7f7242cdd9c" dependencies = [ "aluvm", "amplify", @@ -1892,7 +1492,7 @@ dependencies = [ "bp-wallet", "clap", "commit_verify", - "env_logger 0.11.3", + "env_logger", "log", "psbt", "rgb-interfaces", @@ -1930,12 +1530,6 @@ dependencies = [ "digest", ] -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - [[package]] name = "rustc-hash" version = "1.1.0" @@ -1984,16 +1578,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-pemfile" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" -dependencies = [ - "base64 0.22.1", - "rustls-pki-types", -] - [[package]] name = "rustls-pki-types" version = "1.7.0" @@ -2018,15 +1602,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -2096,29 +1671,6 @@ dependencies = [ "secp256k1-sys 0.9.2", ] -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags 2.5.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.203" @@ -2169,25 +1721,13 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "serde_with" version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" dependencies = [ - "base64 0.22.1", + "base64", "chrono", "hex", "indexmap 1.9.3", @@ -2259,22 +1799,6 @@ dependencies = [ "amplify_derive", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "socks" version = "0.3.4" @@ -2381,33 +1905,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.61" @@ -2474,43 +1971,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "pin-project-lite", - "socket2", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-socks" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" -dependencies = [ - "either", - "futures-util", - "thiserror", - "tokio", -] - [[package]] name = "toml" version = "0.8.14" @@ -2545,58 +2005,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - [[package]] name = "typenum" version = "1.17.0" @@ -2642,7 +2050,7 @@ version = "2.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d11a831e3c0b56e438a28308e7c810799e3c118417f342d30ecec080105395cd" dependencies = [ - "base64 0.22.1", + "base64", "flate2", "log", "once_cell", @@ -2673,12 +2081,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -2695,15 +2097,6 @@ dependencies = [ "strict_encoding", ] -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2854,15 +2247,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3026,16 +2410,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "zeroize" version = "1.8.1" diff --git a/Cargo.toml b/Cargo.toml index 1d117f8..df99716 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,3 +94,5 @@ features = ["all"] [patch.crates-io] bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "runtime" } +rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "master" } +rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "runtime" } diff --git a/cli/src/args.rs b/cli/src/args.rs index 95a82ab..036a3a3 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -23,15 +23,14 @@ use std::fs; use std::io::ErrorKind; -use std::path::Path; +use std::path::PathBuf; use bpstd::{Wpkh, XpubDerivable}; use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts}; use bpwallet::Wallet; -use rgb::persistence::fs::{LoadFs, StoreFs}; use rgb::persistence::Stock; use rgb::resolvers::AnyResolver; -use rgb::{RgbDescr, StoredStock, StoredWallet, TapretKey, WalletError}; +use rgb::{RgbDescr, StoredWallet, TapretKey, WalletError}; use strict_types::encoding::{DecodeError, DeserializeError}; use crate::Command; @@ -78,19 +77,22 @@ impl Default for RgbArgs { } impl RgbArgs { - pub(crate) fn load_stock(&self, stock_path: &Path) -> Result { + pub(crate) fn load_stock( + &self, + stock_path: impl ToOwned, + ) -> Result { if self.verbose > 1 { eprint!("Loading stock ... "); } - Stock::load(stock_path).map_err(WalletError::from).or_else(|err| { + Stock::load(stock_path.to_owned()).map_err(WalletError::from).or_else(|err| { if matches!(err, WalletError::Deserialize(DeserializeError::Decode(DecodeError::Io(ref err))) if err.kind() == ErrorKind::NotFound) { if self.verbose > 1 { eprint!("stock file is absent, creating a new one ... "); } - let stock = Stock::default(); - fs::create_dir_all(stock_path)?; - stock.store(stock_path)?; + fs::create_dir_all(stock_path.to_owned())?; + let stock = Stock::new(stock_path.to_owned()); + stock.store()?; if self.verbose > 1 { eprintln!("success"); } @@ -101,10 +103,10 @@ impl RgbArgs { }) } - pub fn rgb_stock(&self) -> Result { + pub fn rgb_stock(&self) -> Result { let stock_path = self.general.base_dir(); - let stock = self.load_stock(&stock_path)?; - Ok(StoredStock::attach(stock_path, stock)) + let stock = self.load_stock(stock_path)?; + Ok(stock) } pub fn rgb_wallet( @@ -112,7 +114,7 @@ impl RgbArgs { config: &Config, ) -> Result>, WalletError> { let stock_path = self.general.base_dir(); - let stock = self.load_stock(&stock_path)?; + let stock = self.load_stock(stock_path)?; self.rgb_wallet_from_stock(config, stock) } @@ -121,10 +123,8 @@ impl RgbArgs { config: &Config, stock: Stock, ) -> Result>, WalletError> { - let stock_path = self.general.base_dir(); let wallet = self.inner.bp_wallet::(config)?; - let wallet_path = wallet.path().clone(); - let wallet = StoredWallet::attach(stock_path, wallet_path, stock, wallet.detach()); + let wallet = StoredWallet::new(stock, wallet); Ok(wallet) } diff --git a/cli/src/command.rs b/cli/src/command.rs index d92a05f..af1729c 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -37,7 +37,6 @@ use rgb::containers::{ }; use rgb::interface::{AmountChange, IfaceId}; use rgb::invoice::{Beneficiary, Pay2Vout, RgbInvoice, RgbInvoiceBuilder, XChainNet}; -use rgb::persistence::StashReadProvider; use rgb::schema::SchemaId; use rgb::validation::Validity; use rgb::vm::RgbIsa; @@ -47,6 +46,7 @@ use rgb::{ XOutpoint, XOutputSeal, }; use rgbstd::interface::OutpointFilter; +use rgbstd::persistence::StashReadProvider; use serde_crate::{Deserialize, Serialize}; use strict_types::encoding::{FieldName, TypeName}; use strict_types::StrictVal; @@ -485,7 +485,7 @@ impl Exec for RgbArgs { all, } => { let stock_path = self.general.base_dir(); - let stock = self.load_stock(&stock_path)?; + let stock = self.load_stock(stock_path)?; let contract = stock.contract_iface(*contract_id, tn!(iface.to_owned()))?; diff --git a/src/errors.rs b/src/errors.rs index 3411bab..0e17177 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -84,8 +84,8 @@ pub enum WalletError { #[cfg(feature = "fs")] #[from] - #[from(bpwallet::LoadError)] - Bp(bpwallet::WalletError), + #[from(bpwallet::fs::LoadError)] + Bp(bpwallet::cli::ExecError), /// resolver error: {0} #[display(doc_comments)] diff --git a/src/lib.rs b/src/lib.rs index fa2d1a2..ce82202 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,6 @@ mod indexers; mod wallet; pub mod pay; mod errors; -#[cfg(feature = "fs")] mod store; pub use descriptor::{DescriptorRgb, RgbDescr, RgbKeychain, TapTweakAlreadyAssigned, TapretKey}; @@ -44,6 +43,5 @@ pub mod resolvers { pub use super::indexers::*; pub use super::indexers::{AnyResolver, RgbResolver}; } -#[cfg(feature = "fs")] -pub use store::{StoredStock, StoredWallet}; +pub use store::StoredWallet; pub use wallet::{WalletStock, WalletWrapper}; diff --git a/src/pay.rs b/src/pay.rs index 98a8a50..1155f1a 100644 --- a/src/pay.rs +++ b/src/pay.rs @@ -21,13 +21,12 @@ use std::collections::{BTreeMap, BTreeSet}; use std::marker::PhantomData; -use std::ops::DerefMut; use bp::dbc::tapret::TapretProof; use bp::seals::txout::ExplicitSeal; use bp::{Outpoint, Sats, ScriptPubkey, Vout}; use bpstd::{psbt, Address}; -use bpwallet::Wallet; +use bpwallet::{Save, Wallet, WalletDescr}; use psrgbt::{ Beneficiary as BpBeneficiary, Psbt, PsbtConstructor, PsbtMeta, RgbPsbt, TapretKeyError, TxParams, @@ -99,7 +98,7 @@ where Self::Descr: DescriptorRgb type Filter<'a>: Copy + WitnessFilter + OutpointFilter where Self: 'a; fn filter(&self) -> Self::Filter<'_>; - fn descriptor_mut(&mut self) -> &mut Self::Descr; + fn descriptor_mut(&mut self, f: impl FnOnce(&mut WalletDescr) -> R) -> R; fn outpoints(&self) -> impl Iterator; fn txids(&self) -> impl Iterator; @@ -291,8 +290,7 @@ where Self::Descr: DescriptorRgb .terminal_derivation() .ok_or(CompletionError::InconclusiveDerivation)?; let tapret_commitment = output.tapret_commitment()?; - self.descriptor_mut() - .add_tapret_tweak(terminal, tapret_commitment)?; + self.descriptor_mut(|descr| descr.add_tapret_tweak(terminal, tapret_commitment))?; } let witness_txid = psbt.txid(); @@ -322,10 +320,14 @@ where Self::Descr: DescriptorRgb } } -impl> WalletProvider for Wallet { +impl> WalletProvider for Wallet +where Wallet: Save +{ type Filter<'a> = WalletWrapper<'a, K, D> where Self: 'a; fn filter(&self) -> Self::Filter<'_> { WalletWrapper(self) } - fn descriptor_mut(&mut self) -> &mut Self::Descr { self.deref_mut() } + fn descriptor_mut(&mut self, f: impl FnOnce(&mut WalletDescr) -> R) -> R { + self.descriptor_mut(f) + } fn outpoints(&self) -> impl Iterator { self.coins().map(|coin| coin.outpoint) } fn txids(&self) -> impl Iterator { self.transactions().keys().copied() } } diff --git a/src/store.rs b/src/store.rs index 2285255..d7e7aa4 100644 --- a/src/store.rs +++ b/src/store.rs @@ -20,17 +20,19 @@ // limitations under the License. use std::collections::HashMap; -use std::error::Error; use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; +#[cfg(feature = "fs")] use std::path::{Path, PathBuf}; use bpstd::XpubDerivable; -use bpwallet::{StoreError, Wallet, WalletDescr}; +#[cfg(feature = "fs")] +use bpwallet::fs::Warning; +use bpwallet::{Wallet, WalletDescr}; use psrgbt::{Psbt, PsbtMeta}; use rgbstd::containers::Transfer; use rgbstd::interface::{AmountChange, IfaceOp, IfaceRef}; -use rgbstd::persistence::fs::StoreFs; +#[cfg(feature = "fs")] +use rgbstd::persistence::fs::FsStored; use rgbstd::persistence::{ IndexProvider, MemIndex, MemStash, MemState, StashProvider, StateProvider, Stock, }; @@ -41,91 +43,6 @@ use super::{ }; use crate::invoice::RgbInvoice; -pub trait Store { - type Err: Error; - fn store(&self, path: impl AsRef) -> Result<(), Self::Err>; -} - -impl> Store for Wallet -where - for<'de> WalletDescr: serde::Serialize + serde::Deserialize<'de>, - for<'de> D: serde::Serialize + serde::Deserialize<'de>, -{ - type Err = StoreError; - fn store(&self, path: impl AsRef) -> Result<(), Self::Err> { self.store(path.as_ref()) } -} - -#[derive(Getters)] -pub struct StoredStock< - S: StashProvider = MemStash, - H: StateProvider = MemState, - P: IndexProvider = MemIndex, -> where - S: StoreFs, - H: StoreFs, - P: StoreFs, -{ - stock_path: PathBuf, - stock: Stock, - #[getter(prefix = "is_")] - dirty: bool, -} - -impl Deref for StoredStock -where - S: StoreFs, - H: StoreFs, - P: StoreFs, -{ - type Target = Stock; - - fn deref(&self) -> &Self::Target { &self.stock } -} - -impl DerefMut for StoredStock -where - S: StoreFs, - H: StoreFs, - P: StoreFs, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - self.dirty = true; - &mut self.stock - } -} - -impl StoredStock -where - S: StoreFs, - H: StoreFs, - P: StoreFs, -{ - pub fn attach(path: PathBuf, stock: Stock) -> Self { - Self { - stock_path: path, - stock, - dirty: false, - } - } - - pub fn store(&self) { - if self.dirty { - self.stock - .store(&self.stock_path) - .expect("error saving data"); - } - } -} - -impl Drop for StoredStock -where - S: StoreFs, - H: StoreFs, - P: StoreFs, -{ - fn drop(&mut self) { self.store() } -} - #[derive(Getters)] pub struct StoredWallet< W: WalletProvider, @@ -133,60 +50,56 @@ pub struct StoredWallet< S: StashProvider = MemStash, H: StateProvider = MemState, P: IndexProvider = MemIndex, -> where - W::Descr: DescriptorRgb, - W: Store, - S: StoreFs, - H: StoreFs, - P: StoreFs, +> where W::Descr: DescriptorRgb { - stock_path: PathBuf, - wallet_path: Option, stock: Stock, wallet: W, - #[getter(prefix = "is_")] - stock_dirty: bool, - #[getter(prefix = "is_")] - wallet_dirty: bool, + warnings: Vec, #[getter(skip)] _phantom: PhantomData, } +#[cfg(feature = "fs")] +impl, S: StashProvider, H: StateProvider, P: IndexProvider> + StoredWallet, K, S, H, P> +where + S: FsStored, + H: FsStored, + P: FsStored, + for<'de> WalletDescr: serde::Serialize + serde::Deserialize<'de>, + for<'de> D: serde::Serialize + serde::Deserialize<'de>, +{ + pub fn load( + stock_path: impl ToOwned, + wallet_path: impl AsRef, + ) -> Result { + let stock = Stock::load(stock_path)?; + let (wallet, warnings) = Wallet::load(wallet_path.as_ref(), true)?; + Ok(Self { + wallet, + stock, + warnings, + _phantom: PhantomData, + }) + } +} + impl, S: StashProvider, H: StateProvider, P: IndexProvider> StoredWallet -where - W::Descr: DescriptorRgb, - W: Store, - S: StoreFs, - H: StoreFs, - P: StoreFs, +where W::Descr: DescriptorRgb { - pub fn attach( - stock_path: PathBuf, - wallet_path: Option, - stock: Stock, - wallet: W, - ) -> Self { + pub fn new(stock: Stock, wallet: W) -> Self { Self { - stock_path, - wallet_path, stock, wallet, - stock_dirty: false, - wallet_dirty: false, + warnings: none!(), _phantom: PhantomData, } } - pub fn stock_mut(&mut self) -> &mut Stock { - self.stock_dirty = true; - &mut self.stock - } + pub fn stock_mut(&mut self) -> &mut Stock { &mut self.stock } - pub fn wallet_mut(&mut self) -> &mut W { - self.wallet_dirty = true; - &mut self.wallet - } + pub fn wallet_mut(&mut self) -> &mut W { &mut self.wallet } #[allow(clippy::result_large_err)] pub fn fungible_history( @@ -204,8 +117,6 @@ where invoice: &RgbInvoice, params: TransferParams, ) -> Result<(Psbt, PsbtMeta, Transfer), PayError> { - self.stock_dirty = true; - self.wallet_dirty = true; self.wallet.pay(&mut self.stock, invoice, params) } @@ -215,7 +126,6 @@ where invoice: &RgbInvoice, params: TransferParams, ) -> Result<(Psbt, PsbtMeta), CompositionError> { - self.wallet_dirty = true; self.wallet.construct_psbt_rgb(&self.stock, invoice, params) } @@ -225,40 +135,6 @@ where invoice: &RgbInvoice, psbt: &mut Psbt, ) -> Result { - self.stock_dirty = true; - self.wallet_dirty = true; self.wallet.transfer(&mut self.stock, invoice, psbt) } - - pub fn store(&self) { - let r1 = if self.stock_dirty { - self.stock - .store(&self.stock_path) - .map_err(|e| e.to_string()) - } else { - Ok(()) - }; - let r2 = if self.wallet_dirty { - if let Some(path) = self.wallet_path.as_ref() { - self.wallet.store(path).map_err(|e| e.to_string()) - } else { - Ok(()) - } - } else { - Ok(()) - }; - r1.and(r2).expect("error saving data"); - } -} - -impl, S: StashProvider, H: StateProvider, P: IndexProvider> Drop - for StoredWallet -where - W::Descr: DescriptorRgb, - W: Store, - S: StoreFs, - H: StoreFs, - P: StoreFs, -{ - fn drop(&mut self) { self.store() } } diff --git a/src/wallet.rs b/src/wallet.rs index bba7f3f..f0b5821 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -21,7 +21,7 @@ use std::collections::HashMap; -use bpwallet::Wallet; +use bpwallet::{Save, Wallet}; use rgbstd::interface::{AmountChange, IfaceOp, IfaceRef, OutpointFilter, WitnessFilter}; use rgbstd::persistence::{IndexProvider, StashProvider, StateProvider, Stock}; @@ -30,14 +30,19 @@ use crate::{ XChain, XOutpoint, XWitnessId, }; -pub struct WalletWrapper<'a, K, D: DescriptorRgb>(pub &'a Wallet); +pub struct WalletWrapper<'a, K, D: DescriptorRgb>(pub &'a Wallet) +where Wallet: Save; -impl<'a, K, D: DescriptorRgb> Copy for WalletWrapper<'a, K, D> {} -impl<'a, K, D: DescriptorRgb> Clone for WalletWrapper<'a, K, D> { +impl<'a, K, D: DescriptorRgb> Copy for WalletWrapper<'a, K, D> where Wallet: Save {} +impl<'a, K, D: DescriptorRgb> Clone for WalletWrapper<'a, K, D> +where Wallet: Save +{ fn clone(&self) -> Self { *self } } -impl<'a, K, D: DescriptorRgb> OutpointFilter for WalletWrapper<'a, K, D> { +impl<'a, K, D: DescriptorRgb> OutpointFilter for WalletWrapper<'a, K, D> +where Wallet: Save +{ fn include_outpoint(&self, output: impl Into) -> bool { let output = output.into(); self.0 @@ -46,7 +51,9 @@ impl<'a, K, D: DescriptorRgb> OutpointFilter for WalletWrapper<'a, K, D> { } } -impl<'a, K, D: DescriptorRgb> WitnessFilter for WalletWrapper<'a, K, D> { +impl<'a, K, D: DescriptorRgb> WitnessFilter for WalletWrapper<'a, K, D> +where Wallet: Save +{ fn include_witness(&self, witness: impl Into) -> bool { let witness = witness.into(); self.0 From 879ba6e8ef1d19be7c833cfb4b273d0336e70b9f Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 6 Jul 2024 10:57:15 +0200 Subject: [PATCH 4/7] wallet: improve naming, remove redundant WalletStock --- cli/src/args.rs | 8 +-- cli/src/command.rs | 6 +- src/lib.rs | 8 +-- src/pay.rs | 2 +- src/store.rs | 140 ------------------------------------------- src/wallet.rs | 145 ++++++++++++++++++++++++++++++--------------- src/wrapper.rs | 57 ++++++++++++++++++ 7 files changed, 167 insertions(+), 199 deletions(-) delete mode 100644 src/store.rs create mode 100644 src/wrapper.rs diff --git a/cli/src/args.rs b/cli/src/args.rs index 036a3a3..0ff321c 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -30,7 +30,7 @@ use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts}; use bpwallet::Wallet; use rgb::persistence::Stock; use rgb::resolvers::AnyResolver; -use rgb::{RgbDescr, StoredWallet, TapretKey, WalletError}; +use rgb::{RgbDescr, RgbWallet, TapretKey, WalletError}; use strict_types::encoding::{DecodeError, DeserializeError}; use crate::Command; @@ -112,7 +112,7 @@ impl RgbArgs { pub fn rgb_wallet( &self, config: &Config, - ) -> Result>, WalletError> { + ) -> Result>, WalletError> { let stock_path = self.general.base_dir(); let stock = self.load_stock(stock_path)?; self.rgb_wallet_from_stock(config, stock) @@ -122,9 +122,9 @@ impl RgbArgs { &self, config: &Config, stock: Stock, - ) -> Result>, WalletError> { + ) -> Result>, WalletError> { let wallet = self.inner.bp_wallet::(config)?; - let wallet = StoredWallet::new(stock, wallet); + let wallet = RgbWallet::new(stock, wallet); Ok(wallet) } diff --git a/cli/src/command.rs b/cli/src/command.rs index af1729c..ee56197 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -42,7 +42,7 @@ use rgb::validation::Validity; use rgb::vm::RgbIsa; use rgb::{ BundleId, ContractId, DescriptorRgb, GenesisSeal, GraphSeal, Identity, OutputSeal, RgbDescr, - RgbKeychain, StateType, StoredWallet, TransferParams, WalletError, WalletProvider, XChain, + RgbKeychain, RgbWallet, StateType, TransferParams, WalletError, WalletProvider, XChain, XOutpoint, XOutputSeal, }; use rgbstd::interface::OutpointFilter; @@ -508,8 +508,8 @@ impl Exec for RgbArgs { } enum Filter { - Wallet(StoredWallet>), - WalletAll(StoredWallet>), + Wallet(RgbWallet>), + WalletAll(RgbWallet>), NoWallet, } impl OutpointFilter for Filter { diff --git a/src/lib.rs b/src/lib.rs index ce82202..44d3fe1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,10 +27,10 @@ extern crate serde_crate as serde; mod descriptor; mod indexers; -mod wallet; +mod wrapper; pub mod pay; mod errors; -mod store; +mod wallet; pub use descriptor::{DescriptorRgb, RgbDescr, RgbKeychain, TapTweakAlreadyAssigned, TapretKey}; pub use errors::{CompletionError, CompositionError, HistoryError, PayError, WalletError}; @@ -43,5 +43,5 @@ pub mod resolvers { pub use super::indexers::*; pub use super::indexers::{AnyResolver, RgbResolver}; } -pub use store::StoredWallet; -pub use wallet::{WalletStock, WalletWrapper}; +pub use wallet::RgbWallet; +pub use wrapper::WalletWrapper; diff --git a/src/pay.rs b/src/pay.rs index 1155f1a..c6d2af2 100644 --- a/src/pay.rs +++ b/src/pay.rs @@ -38,7 +38,7 @@ use rgbstd::persistence::{IndexProvider, StashProvider, StateProvider, Stock}; use rgbstd::{ContractId, DataState, XChain, XOutpoint}; use crate::invoice::NonFungible; -use crate::wallet::WalletWrapper; +use crate::wrapper::WalletWrapper; use crate::{CompletionError, CompositionError, DescriptorRgb, PayError, RgbKeychain, Txid}; #[derive(Clone, PartialEq, Debug)] diff --git a/src/store.rs b/src/store.rs deleted file mode 100644 index d7e7aa4..0000000 --- a/src/store.rs +++ /dev/null @@ -1,140 +0,0 @@ -// RGB wallet library for smart contracts on Bitcoin & Lightning network -// -// SPDX-License-Identifier: Apache-2.0 -// -// Written in 2019-2023 by -// Dr Maxim Orlovsky -// -// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::collections::HashMap; -use std::marker::PhantomData; -#[cfg(feature = "fs")] -use std::path::{Path, PathBuf}; - -use bpstd::XpubDerivable; -#[cfg(feature = "fs")] -use bpwallet::fs::Warning; -use bpwallet::{Wallet, WalletDescr}; -use psrgbt::{Psbt, PsbtMeta}; -use rgbstd::containers::Transfer; -use rgbstd::interface::{AmountChange, IfaceOp, IfaceRef}; -#[cfg(feature = "fs")] -use rgbstd::persistence::fs::FsStored; -use rgbstd::persistence::{ - IndexProvider, MemIndex, MemStash, MemState, StashProvider, StateProvider, Stock, -}; - -use super::{ - CompletionError, CompositionError, ContractId, DescriptorRgb, PayError, TransferParams, - WalletError, WalletProvider, WalletStock, XWitnessId, -}; -use crate::invoice::RgbInvoice; - -#[derive(Getters)] -pub struct StoredWallet< - W: WalletProvider, - K = XpubDerivable, - S: StashProvider = MemStash, - H: StateProvider = MemState, - P: IndexProvider = MemIndex, -> where W::Descr: DescriptorRgb -{ - stock: Stock, - wallet: W, - warnings: Vec, - #[getter(skip)] - _phantom: PhantomData, -} - -#[cfg(feature = "fs")] -impl, S: StashProvider, H: StateProvider, P: IndexProvider> - StoredWallet, K, S, H, P> -where - S: FsStored, - H: FsStored, - P: FsStored, - for<'de> WalletDescr: serde::Serialize + serde::Deserialize<'de>, - for<'de> D: serde::Serialize + serde::Deserialize<'de>, -{ - pub fn load( - stock_path: impl ToOwned, - wallet_path: impl AsRef, - ) -> Result { - let stock = Stock::load(stock_path)?; - let (wallet, warnings) = Wallet::load(wallet_path.as_ref(), true)?; - Ok(Self { - wallet, - stock, - warnings, - _phantom: PhantomData, - }) - } -} - -impl, S: StashProvider, H: StateProvider, P: IndexProvider> - StoredWallet -where W::Descr: DescriptorRgb -{ - pub fn new(stock: Stock, wallet: W) -> Self { - Self { - stock, - wallet, - warnings: none!(), - _phantom: PhantomData, - } - } - - pub fn stock_mut(&mut self) -> &mut Stock { &mut self.stock } - - pub fn wallet_mut(&mut self) -> &mut W { &mut self.wallet } - - #[allow(clippy::result_large_err)] - pub fn fungible_history( - &self, - contract_id: ContractId, - iface: impl Into, - ) -> Result>, WalletError> { - self.stock - .fungible_history(&self.wallet, contract_id, iface) - } - - #[allow(clippy::result_large_err)] - pub fn pay( - &mut self, - invoice: &RgbInvoice, - params: TransferParams, - ) -> Result<(Psbt, PsbtMeta, Transfer), PayError> { - self.wallet.pay(&mut self.stock, invoice, params) - } - - #[allow(clippy::result_large_err)] - pub fn construct_psbt( - &mut self, - invoice: &RgbInvoice, - params: TransferParams, - ) -> Result<(Psbt, PsbtMeta), CompositionError> { - self.wallet.construct_psbt_rgb(&self.stock, invoice, params) - } - - #[allow(clippy::result_large_err)] - pub fn transfer( - &mut self, - invoice: &RgbInvoice, - psbt: &mut Psbt, - ) -> Result { - self.wallet.transfer(&mut self.stock, invoice, psbt) - } -} diff --git a/src/wallet.rs b/src/wallet.rs index f0b5821..6dad3f8 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -20,73 +20,96 @@ // limitations under the License. use std::collections::HashMap; +use std::marker::PhantomData; +#[cfg(feature = "fs")] +use std::path::{Path, PathBuf}; -use bpwallet::{Save, Wallet}; -use rgbstd::interface::{AmountChange, IfaceOp, IfaceRef, OutpointFilter, WitnessFilter}; -use rgbstd::persistence::{IndexProvider, StashProvider, StateProvider, Stock}; - -use crate::{ - AssignmentWitness, ContractId, DescriptorRgb, HistoryError, WalletError, WalletProvider, - XChain, XOutpoint, XWitnessId, +use bpstd::XpubDerivable; +#[cfg(feature = "fs")] +use bpwallet::fs::Warning; +use bpwallet::{Wallet, WalletDescr}; +use psrgbt::{Psbt, PsbtMeta}; +use rgbstd::containers::Transfer; +use rgbstd::interface::{AmountChange, IfaceOp, IfaceRef}; +#[cfg(feature = "fs")] +use rgbstd::persistence::fs::FsStored; +use rgbstd::persistence::{ + IndexProvider, MemIndex, MemStash, MemState, StashProvider, StateProvider, Stock, }; -pub struct WalletWrapper<'a, K, D: DescriptorRgb>(pub &'a Wallet) -where Wallet: Save; +use super::{ + CompletionError, CompositionError, ContractId, DescriptorRgb, HistoryError, PayError, + TransferParams, WalletError, WalletProvider, XWitnessId, +}; +use crate::invoice::RgbInvoice; -impl<'a, K, D: DescriptorRgb> Copy for WalletWrapper<'a, K, D> where Wallet: Save {} -impl<'a, K, D: DescriptorRgb> Clone for WalletWrapper<'a, K, D> -where Wallet: Save +#[derive(Getters)] +pub struct RgbWallet< + W: WalletProvider, + K = XpubDerivable, + S: StashProvider = MemStash, + H: StateProvider = MemState, + P: IndexProvider = MemIndex, +> where W::Descr: DescriptorRgb { - fn clone(&self) -> Self { *self } + stock: Stock, + wallet: W, + warnings: Vec, + #[getter(skip)] + _phantom: PhantomData, } -impl<'a, K, D: DescriptorRgb> OutpointFilter for WalletWrapper<'a, K, D> -where Wallet: Save +#[cfg(feature = "fs")] +impl, S: StashProvider, H: StateProvider, P: IndexProvider> + RgbWallet, K, S, H, P> +where + S: FsStored, + H: FsStored, + P: FsStored, + for<'de> WalletDescr: serde::Serialize + serde::Deserialize<'de>, + for<'de> D: serde::Serialize + serde::Deserialize<'de>, { - fn include_outpoint(&self, output: impl Into) -> bool { - let output = output.into(); - self.0 - .outpoints() - .any(|outpoint| XChain::Bitcoin(outpoint) == *output) + pub fn load( + stock_path: impl ToOwned, + wallet_path: impl AsRef, + ) -> Result { + let stock = Stock::load(stock_path)?; + let (wallet, warnings) = Wallet::load(wallet_path.as_ref(), true)?; + Ok(Self { + wallet, + stock, + warnings, + _phantom: PhantomData, + }) } } -impl<'a, K, D: DescriptorRgb> WitnessFilter for WalletWrapper<'a, K, D> -where Wallet: Save +impl, S: StashProvider, H: StateProvider, P: IndexProvider> + RgbWallet +where W::Descr: DescriptorRgb { - fn include_witness(&self, witness: impl Into) -> bool { - let witness = witness.into(); - self.0 - .txids() - .any(|txid| AssignmentWitness::Present(XWitnessId::Bitcoin(txid)) == witness) + pub fn new(stock: Stock, wallet: W) -> Self { + Self { + stock, + wallet, + warnings: none!(), + _phantom: PhantomData, + } } -} -pub trait WalletStock, K> -where W::Descr: DescriptorRgb -{ - #[allow(clippy::result_large_err)] - fn fungible_history( - &self, - wallet: &W, - contract_id: ContractId, - iface: impl Into, - ) -> Result>, WalletError>; -} + pub fn stock_mut(&mut self) -> &mut Stock { &mut self.stock } -impl, K, S: StashProvider, H: StateProvider, P: IndexProvider> - WalletStock for Stock -where W::Descr: DescriptorRgb -{ - // TODO: Integrate into BP Wallet `TxRow` as L2 and provide transactional info - fn fungible_history( + pub fn wallet_mut(&mut self) -> &mut W { &mut self.wallet } + + #[allow(clippy::result_large_err)] + pub fn fungible_history( &self, - wallet: &W, contract_id: ContractId, iface: impl Into, ) -> Result>, WalletError> { + let wallet = &self.wallet; let iref = iface.into(); - let iface = self.iface(iref.clone()).map_err(|e| e.to_string())?; + let iface = self.stock.iface(iref.clone()).map_err(|e| e.to_string())?; let default_op = iface .default_operation .as_ref() @@ -100,10 +123,38 @@ where W::Descr: DescriptorRgb .ok_or(HistoryError::NoDefaultAssignment)? .clone(); let contract = self + .stock .contract_iface(contract_id, iref) .map_err(|e| e.to_string())?; Ok(contract .fungible_ops::(state_name, wallet.filter(), wallet.filter()) .map_err(|e| e.to_string())?) } + + #[allow(clippy::result_large_err)] + pub fn pay( + &mut self, + invoice: &RgbInvoice, + params: TransferParams, + ) -> Result<(Psbt, PsbtMeta, Transfer), PayError> { + self.wallet.pay(&mut self.stock, invoice, params) + } + + #[allow(clippy::result_large_err)] + pub fn construct_psbt( + &mut self, + invoice: &RgbInvoice, + params: TransferParams, + ) -> Result<(Psbt, PsbtMeta), CompositionError> { + self.wallet.construct_psbt_rgb(&self.stock, invoice, params) + } + + #[allow(clippy::result_large_err)] + pub fn transfer( + &mut self, + invoice: &RgbInvoice, + psbt: &mut Psbt, + ) -> Result { + self.wallet.transfer(&mut self.stock, invoice, psbt) + } } diff --git a/src/wrapper.rs b/src/wrapper.rs new file mode 100644 index 0000000..5ce4a07 --- /dev/null +++ b/src/wrapper.rs @@ -0,0 +1,57 @@ +// RGB wallet library for smart contracts on Bitcoin & Lightning network +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use bpwallet::{Save, Wallet}; +use rgbstd::interface::{OutpointFilter, WitnessFilter}; + +use crate::{AssignmentWitness, DescriptorRgb, WalletProvider, XChain, XOutpoint, XWitnessId}; + +pub struct WalletWrapper<'a, K, D: DescriptorRgb>(pub &'a Wallet) +where Wallet: Save; + +impl<'a, K, D: DescriptorRgb> Copy for WalletWrapper<'a, K, D> where Wallet: Save {} +impl<'a, K, D: DescriptorRgb> Clone for WalletWrapper<'a, K, D> +where Wallet: Save +{ + fn clone(&self) -> Self { *self } +} + +impl<'a, K, D: DescriptorRgb> OutpointFilter for WalletWrapper<'a, K, D> +where Wallet: Save +{ + fn include_outpoint(&self, output: impl Into) -> bool { + let output = output.into(); + self.0 + .outpoints() + .any(|outpoint| XChain::Bitcoin(outpoint) == *output) + } +} + +impl<'a, K, D: DescriptorRgb> WitnessFilter for WalletWrapper<'a, K, D> +where Wallet: Save +{ + fn include_witness(&self, witness: impl Into) -> bool { + let witness = witness.into(); + self.0 + .txids() + .any(|txid| AssignmentWitness::Present(XWitnessId::Bitcoin(txid)) == witness) + } +} From 6a3e941bc579e8b10097cdb6927cb0adead78293 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 8 Jul 2024 23:10:11 +0200 Subject: [PATCH 5/7] cli: improve logging --- Cargo.lock | 4 ++-- cli/src/args.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df76ae9..a3a4375 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -488,7 +488,7 @@ dependencies = [ [[package]] name = "bp-wallet" version = "0.11.0-beta.6.1" -source = "git+https://github.com/BP-WG/bp-wallet?branch=runtime#b3cdda624394f6ade6f83076a43bc66078895c2a" +source = "git+https://github.com/BP-WG/bp-wallet?branch=runtime#24e947a90539abbe85b127e7bf9871cdfe3a90a9" dependencies = [ "amplify", "base64", @@ -1116,7 +1116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] diff --git a/cli/src/args.rs b/cli/src/args.rs index 0ff321c..cc60ddd 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -81,11 +81,13 @@ impl RgbArgs { &self, stock_path: impl ToOwned, ) -> Result { + let stock_path = stock_path.to_owned(); + if self.verbose > 1 { - eprint!("Loading stock ... "); + eprint!("Loading stock from `{}` ... ", stock_path.display()); } - Stock::load(stock_path.to_owned()).map_err(WalletError::from).or_else(|err| { + let stock = Stock::load(stock_path.clone()).map_err(WalletError::from).or_else(|err| { if matches!(err, WalletError::Deserialize(DeserializeError::Decode(DecodeError::Io(ref err))) if err.kind() == ErrorKind::NotFound) { if self.verbose > 1 { eprint!("stock file is absent, creating a new one ... "); @@ -93,14 +95,17 @@ impl RgbArgs { fs::create_dir_all(stock_path.to_owned())?; let stock = Stock::new(stock_path.to_owned()); stock.store()?; - if self.verbose > 1 { - eprintln!("success"); - } return Ok(stock) } eprintln!("stock file is damaged, failing"); Err(err) - }) + })?; + + if self.verbose > 1 { + eprintln!("success"); + } + + Ok(stock) } pub fn rgb_stock(&self) -> Result { From 66ebbc6b4ebf78d3e513e728f89cdedab53f53b9 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 9 Jul 2024 14:09:35 +0200 Subject: [PATCH 6/7] chore: update rgb-std tip --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3a4375..538a337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,7 +1116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.5", + "windows-targets 0.48.5", ] [[package]] @@ -1398,7 +1398,7 @@ dependencies = [ [[package]] name = "rgb-invoice" version = "0.11.0-beta.6" -source = "git+https://github.com/RGB-WG/rgb-std?branch=runtime#f00e86085e13a342fbd2300e49f3e7f7242cdd9c" +source = "git+https://github.com/RGB-WG/rgb-std?branch=runtime#c2f83473eb612638b9b67c0fb5150c574c35171e" dependencies = [ "amplify", "baid64", @@ -1460,7 +1460,7 @@ dependencies = [ [[package]] name = "rgb-std" version = "0.11.0-beta.6" -source = "git+https://github.com/RGB-WG/rgb-std?branch=runtime#f00e86085e13a342fbd2300e49f3e7f7242cdd9c" +source = "git+https://github.com/RGB-WG/rgb-std?branch=runtime#c2f83473eb612638b9b67c0fb5150c574c35171e" dependencies = [ "aluvm", "amplify", From 0b98e6e3a006a6e6ad82114051d19bb316c7c622 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Wed, 10 Jul 2024 13:12:43 +0200 Subject: [PATCH 7/7] cli: fix feature gates on WalletError --- Cargo.toml | 3 ++- cli/Cargo.toml | 2 +- cli/src/command.rs | 5 ++--- src/errors.rs | 15 +++++++++------ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index df99716..dcbc004 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,8 +83,9 @@ log = { workspace = true, optional = true } [features] default = ["esplora_blocking"] -all = ["esplora_blocking", "electrum_blocking", "serde", "log", "fs"] +all = ["esplora_blocking", "electrum_blocking", "serde", "log", "fs", "cli"] fs = ["serde", "bp-wallet/fs"] +cli = ["fs"] esplora_blocking = ["bp-esplora"] electrum_blocking = ["bp-electrum"] serde = ["serde_crate", "serde_yaml", "bp-std/serde", "descriptors/serde", "rgb-psbt/serde"] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 3bd7520..b1887ff 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -27,7 +27,7 @@ bp-wallet = { workspace = true, features = ["cli"] } psbt = { workspace = true } rgb-std = { workspace = true, features = ["serde"] } rgb-interfaces = { workspace = true } -rgb-runtime = { version = "0.11.0-beta.6", path = "..", features = ["electrum_blocking", "esplora_blocking", "log", "serde", "fs"] } +rgb-runtime = { version = "0.11.0-beta.6", path = "..", features = ["electrum_blocking", "esplora_blocking", "log", "serde", "fs", "cli"] } log = { workspace = true } env_logger = "0.11.3" clap = { version = "4.4.8", features = ["derive", "env"] } diff --git a/cli/src/command.rs b/cli/src/command.rs index ee56197..25dc518 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -35,8 +35,9 @@ use rgb::containers::{ BuilderSeal, ContainerVer, ContentId, ContentSigs, Contract, FileContent, Supplement, Terminal, Transfer, UniversalFile, }; -use rgb::interface::{AmountChange, IfaceId}; +use rgb::interface::{AmountChange, IfaceId, OutpointFilter}; use rgb::invoice::{Beneficiary, Pay2Vout, RgbInvoice, RgbInvoiceBuilder, XChainNet}; +use rgb::persistence::StashReadProvider; use rgb::schema::SchemaId; use rgb::validation::Validity; use rgb::vm::RgbIsa; @@ -45,8 +46,6 @@ use rgb::{ RgbKeychain, RgbWallet, StateType, TransferParams, WalletError, WalletProvider, XChain, XOutpoint, XOutputSeal, }; -use rgbstd::interface::OutpointFilter; -use rgbstd::persistence::StashReadProvider; use serde_crate::{Deserialize, Serialize}; use strict_types::encoding::{FieldName, TypeName}; use strict_types::StrictVal; diff --git a/src/errors.rs b/src/errors.rs index 0e17177..bd9aabc 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -50,7 +50,15 @@ pub enum WalletError { Deserialize(DeserializeError), #[from] - Load(LoadError), + StockLoad(LoadError), + + #[cfg(feature = "fs")] + #[from] + WalletLoad(bpwallet::fs::LoadError), + + #[cfg(feature = "cli")] + #[from] + WalletExect(bpwallet::cli::ExecError), #[from] Builder(BuilderError), @@ -82,11 +90,6 @@ pub enum WalletError { #[display(doc_comments)] IncompleteContract(validation::Status), - #[cfg(feature = "fs")] - #[from] - #[from(bpwallet::fs::LoadError)] - Bp(bpwallet::cli::ExecError), - /// resolver error: {0} #[display(doc_comments)] Resolver(String),