Skip to content

Commit

Permalink
Update cli/src/args.rs
Browse files Browse the repository at this point in the history
Co-authored-by: Dr. Maxim Orlovsky <[email protected]>
  • Loading branch information
2 people authored and Crayon Shin-chan committed Oct 7, 2024
1 parent 2481c5f commit b322876
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
41 changes: 22 additions & 19 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use std::ops::{Deref, DerefMut};
use std::path::PathBuf;

use bpstd::{Wpkh, XpubDerivable};
use bpwallet::Wallet;
use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts};
use bpwallet::Wallet;
use nonasync::persistence::PersistenceError;
use rgb::persistence::Stock;
use rgb::resolvers::AnyResolver;
Expand Down Expand Up @@ -106,29 +106,32 @@ impl RgbArgs {

let provider = FsBinStore::new(stock_path.clone())?;
let mut stock = Stock::load(provider, true)
.map_err(WalletError::WalletPersist)
.or_else(|err| {
if let WalletError::WalletPersist(PersistenceError(ref err)) = err {
if let Some(DeserializeError::Decode(DecodeError::Io(io_err))) =
err.downcast_ref::<DeserializeError>()
{
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);
}
let Some(DeserializeError::Decode(DecodeError::Io(io_err))) =
err.0.downcast_ref::<DeserializeError>()

Check warning on line 111 in cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L108-L111

Added lines #L108 - L111 were not covered by tests
else {
eprintln!("stock file is damaged, failing");
return Err(err);

Check warning on line 114 in cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L113-L114

Added lines #L113 - L114 were not covered by tests
};

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)
.map_err(|err| PersistenceError(Box::new(err)))?;
let provider = FsBinStore::new(stock_path)
.map_err(|err| PersistenceError(Box::new(err)))?;
let mut stock = Stock::in_memory();
stock
.make_persistent(provider, true)
.map_err(|err| PersistenceError(Box::new(err)))?;
return Ok(stock);

Check warning on line 129 in cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L117-L129

Added lines #L117 - L129 were not covered by tests
}
eprintln!("stock file is damaged, failing");
Err(err)
})?;
})
.map_err(WalletError::WalletPersist)?;

Check warning on line 134 in cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L131-L134

Added lines #L131 - L134 were not covered by tests

if self.sync {
let resolver = self.resolver()?;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use std::str::FromStr;
use amplify::confinement::{SmallOrdMap, TinyOrdMap, TinyOrdSet, U16 as MAX16};
use baid64::DisplayBaid64;
use bpstd::{Sats, XpubDerivable};
use bpwallet::Wallet;
use bpwallet::cli::{BpCommand, Config, Exec};
use bpwallet::Wallet;
use ifaces::{IfaceStandard, Rgb20, Rgb21, Rgb25};
use psbt::{Psbt, PsbtVer};
use rgb::containers::{
Expand All @@ -50,8 +50,8 @@ use rgbstd::containers::ConsignmentExt;
use rgbstd::persistence::{MemContract, Stock};
use seals::SecretSeal;
use serde_crate::{Deserialize, Serialize};
use strict_types::StrictVal;
use strict_types::encoding::{FieldName, TypeName};
use strict_types::StrictVal;

use crate::RgbArgs;

Expand Down

0 comments on commit b322876

Please sign in to comment.