Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error mismatch #254

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
42 changes: 28 additions & 14 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
use std::path::PathBuf;

use bpstd::{Wpkh, XpubDerivable};
use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts};
use bpwallet::Wallet;
use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts};
use nonasync::persistence::PersistenceError;
use rgb::persistence::Stock;
use rgb::resolvers::AnyResolver;
use rgb::{RgbDescr, RgbWallet, TapretKey, WalletError};
Expand Down Expand Up @@ -104,20 +105,33 @@
}

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 ... ");
let mut stock = Stock::load(provider, true)
.or_else(|err| {
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
}
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)
})?;
eprintln!("stock file is damaged, failing");
Err(err)
This conversation was marked as resolved.
Show resolved Hide resolved
})
.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::cli::{BpCommand, Config, Exec};
use bpwallet::Wallet;
use bpwallet::cli::{BpCommand, Config, Exec};
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::encoding::{FieldName, TypeName};
use strict_types::StrictVal;
use strict_types::encoding::{FieldName, TypeName};

use crate::RgbArgs;

Expand Down
6 changes: 3 additions & 3 deletions psbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ use bp::dbc::opret::OpretProof;
use bp::dbc::tapret::TapretProof;
pub use psbt::*;
pub use rgb::*;
use rgbstd::containers::{AnchorSet, Batch, CloseMethodSet, Fascia, PubWitness, XPubWitness};
use rgbstd::XChain;
use rgbstd::containers::{AnchorSet, Batch, CloseMethodSet, Fascia, PubWitness, XPubWitness};

pub use self::rgb::{
ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError, PSBT_GLOBAL_RGB_TRANSITION,
PSBT_IN_RGB_CONSUMED_BY, PSBT_OUT_RGB_VELOCITY_HINT, PSBT_RGB_PREFIX,
PSBT_GLOBAL_RGB_TRANSITION, PSBT_IN_RGB_CONSUMED_BY, PSBT_OUT_RGB_VELOCITY_HINT,
PSBT_RGB_PREFIX, ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError,
};

#[derive(Clone, Eq, PartialEq, Debug, Display, Error)]
Expand Down
2 changes: 1 addition & 1 deletion psbt/src/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};

use amplify::confinement::{Confined, SmallOrdMap, U24};
use amplify::{confinement, FromSliceError};
use amplify::{FromSliceError, confinement};
use bp::dbc::Method;
use bp::seals::txout::CloseMethod;
use commit_verify::mpc;
Expand Down
2 changes: 1 addition & 1 deletion src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use std::iter;
use std::str::FromStr;

use amplify::Wrapper;
use bp::dbc::tapret::TapretCommitment;
use bp::dbc::Method;
use bp::dbc::tapret::TapretCommitment;
use bp::seals::txout::CloseMethod;
use bp::{LegacyPk, SigScript, Witness};
use bpstd::{
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rgbstd::persistence::{
};
use strict_types::encoding::{DeserializeError, Ident, SerializeError};

use crate::{validation, TapTweakAlreadyAssigned};
use crate::{TapTweakAlreadyAssigned, validation};

#[derive(Debug, Display, Error, From)]
#[display(inner)]
Expand Down
2 changes: 1 addition & 1 deletion src/indexers/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use std::collections::HashMap;

use bp::Tx;
use bpstd::Network;
use rgbstd::XWitnessId;
use rgbstd::containers::Consignment;
use rgbstd::validation::{ResolveWitness, WitnessResolverError};
use rgbstd::XWitnessId;

use crate::vm::{WitnessOrd, XWitnessTx};
use crate::{Txid, XChain};
Expand Down
8 changes: 4 additions & 4 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::marker::PhantomData;
use bp::dbc::tapret::TapretProof;
use bp::seals::txout::ExplicitSeal;
use bp::{Outpoint, Sats, ScriptPubkey, Vout};
use bpstd::{psbt, Address};
use bpstd::{Address, psbt};
use bpwallet::{Wallet, WalletDescr};
use psrgbt::{
Beneficiary as BpBeneficiary, Psbt, PsbtConstructor, PsbtMeta, RgbPsbt, TapretKeyError,
Expand Down Expand Up @@ -351,9 +351,9 @@ where Self::Descr: DescriptorRgb<K>
}

impl<K, D: DescriptorRgb<K>> WalletProvider<K> for Wallet<K, D> {
type Filter<'a> = WalletWrapper<'a, K, D>
where
Self: 'a;
type Filter<'a>
= WalletWrapper<'a, K, D>
where Self: 'a;
fn filter(&self) -> Self::Filter<'_> { WalletWrapper(self) }
fn with_descriptor_mut<R>(&mut self, f: impl FnOnce(&mut WalletDescr<K, D>) -> R) -> R {
self.descriptor_mut(f)
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use std::path::PathBuf;

use bpstd::XpubDerivable;
#[cfg(feature = "fs")]
use bpwallet::fs::FsTextStore;
#[cfg(feature = "fs")]
use bpwallet::Wallet;
#[cfg(feature = "fs")]
use bpwallet::fs::FsTextStore;
#[cfg(not(target_arch = "wasm32"))]
use nonasync::persistence::PersistenceProvider;
use psrgbt::{Psbt, PsbtMeta};
Expand Down
Loading