diff --git a/Cargo.lock b/Cargo.lock index 02edff3..d05348c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1538,6 +1538,7 @@ dependencies = [ "commit_verify", "env_logger", "log", + "nonasync", "psbt", "rgb-interfaces", "rgb-runtime", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2905353..64ab91f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -24,6 +24,7 @@ commit_verify = { workspace = true } bp-seals = { workspace = true } bp-std = { workspace = true, features = ["serde"] } bp-wallet = { workspace = true, features = ["cli"] } +nonasync = { workspace = true } psbt = { workspace = true } rgb-std = { workspace = true, features = ["serde"] } rgb-interfaces = { workspace = true } diff --git a/cli/src/args.rs b/cli/src/args.rs index 4f4697a..de7cda6 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -29,6 +29,7 @@ use std::path::PathBuf; use bpstd::{Wpkh, XpubDerivable}; use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts}; use bpwallet::Wallet; +use nonasync::persistence::PersistenceError; use rgb::persistence::Stock; use rgb::resolvers::AnyResolver; use rgb::{RgbDescr, RgbWallet, TapretKey, WalletError}; @@ -105,15 +106,19 @@ impl RgbArgs { let provider = FsBinStore::new(stock_path.clone())?; let mut stock = Stock::load(provider, true).map_err(WalletError::WalletPersist).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 ... "); + if let WalletError::WalletPersist(PersistenceError(ref err)) = err { + if let Some(DeserializeError::Decode(DecodeError::Io(io_err))) = err.downcast_ref::() { + if io_err.kind() == ErrorKind::NotFound { + if self.verbose > 1 { + eprint!("stock file is absent, creating a new one ... "); + } + fs::create_dir_all(&stock_path)?; + let provider = FsBinStore::new(stock_path)?; + let mut stock = Stock::in_memory(); + stock.make_persistent(provider, true).map_err(WalletError::StockPersist)?; + return Ok(stock); + } } - fs::create_dir_all(&stock_path)?; - let provider = FsBinStore::new(stock_path)?; - let mut stock = Stock::in_memory(); - stock.make_persistent(provider, true).map_err(WalletError::StockPersist)?; - return Ok(stock); } eprintln!("stock file is damaged, failing"); Err(err)