Skip to content

Commit

Permalink
use new StoreProvider APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 30, 2024
1 parent 1fc1a24 commit 288bee2
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 93 deletions.
90 changes: 55 additions & 35 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ license = "Apache-2.0"

[workspace.dependencies]
amplify = "4.7.0"
nonasync = { version = "0.1.0", features = ["log"] }
baid64 = "0.2.2"
strict_encoding = "2.7.0-rc.1"
strict_types = "2.7.0-rc.1"
Expand Down Expand Up @@ -63,6 +64,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
amplify = { workspace = true }
nonasync = { workspace = true }
baid64 = { workspace = true }
bp-electrum = { workspace = true, optional = true }
commit_verify = { workspace = true }
Expand Down Expand Up @@ -100,3 +102,10 @@ serde = ["serde_crate", "serde_yaml", "bp-std/serde", "descriptors/serde", "rgb-

[package.metadata.docs.rs]
features = ["all"]

[patch.crates-io]
nonasync = { git = "https://github.com/rust-amplify/amplify-nonasync" }
bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "store" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "master" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "store" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "store" }
17 changes: 12 additions & 5 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use bpwallet::Wallet;
use rgb::persistence::Stock;
use rgb::resolvers::AnyResolver;
use rgb::{RgbDescr, RgbWallet, TapretKey, WalletError};
use rgbstd::persistence::fs::FsBinStore;
use strict_types::encoding::{DecodeError, DeserializeError};

use crate::Command;
Expand Down Expand Up @@ -102,14 +103,16 @@ impl RgbArgs {
eprint!("Loading stock from `{}` ... ", stock_path.display());
}

let mut stock = Stock::load(stock_path.clone()).map_err(WalletError::from).or_else(|err| {
let provider = FsBinStore::new(stock_path.clone());
let mut stock = Stock::load(provider, true).map_err(WalletError::WalletPersist).or_else(|err| {

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L106-L107

Added lines #L106 - L107 were not covered by tests
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 ... ");
}
fs::create_dir_all(&stock_path)?;
let stock = Stock::new(stock_path.to_owned());
stock.store()?;
let provider = FsBinStore::new(stock_path);
let mut stock = Stock::in_memory();
stock.make_persistent(provider, true).map_err(WalletError::StockPersist)?;

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L113-L115

Added lines #L113 - L115 were not covered by tests
return Ok(stock);
}
eprintln!("stock file is damaged, failing");
Expand Down Expand Up @@ -151,14 +154,18 @@ impl RgbArgs {
) -> Result<RgbWallet<Wallet<XpubDerivable, RgbDescr>>, WalletError> {
let stock = self.rgb_stock()?;
self.rgb_wallet_from_stock(config, stock)
.map_err(|(_, err)| err)

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L157

Added line #L157 was not covered by tests
}

pub fn rgb_wallet_from_stock(
&self,
config: &Config,
stock: Stock,
) -> Result<RgbWallet<Wallet<XpubDerivable, RgbDescr>>, WalletError> {
let wallet = self.inner.bp_wallet::<RgbDescr>(config)?;
) -> Result<RgbWallet<Wallet<XpubDerivable, RgbDescr>>, (Stock, WalletError)> {
let wallet = match self.inner.bp_wallet::<RgbDescr>(config) {
Ok(wallet) => wallet,
Err(e) => return Err((stock, e.into())),

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L164-L167

Added lines #L164 - L167 were not covered by tests
};
let wallet = RgbWallet::new(stock, wallet);

Ok(wallet)
Expand Down
Loading

0 comments on commit 288bee2

Please sign in to comment.