Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
};
use crate::fs::FsTextStore;
use crate::indexers::esplora;
use crate::{AnyIndexer, Wallet};
use crate::{AnyIndexer, Layer2Empty, Wallet, WalletCache};

/// Command-line arguments
#[derive(Parser)]
Expand Down Expand Up @@ -119,14 +119,14 @@
pub fn bp_wallet<D: Descriptor>(
&self,
conf: &Config,
) -> Result<Wallet<XpubDerivable, D>, ExecError>
) -> Result<Wallet<XpubDerivable, D, WalletCache<Layer2Empty>>, ExecError>

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

View check run for this annotation

Codecov / codecov/patch

src/cli/args.rs#L122

Added line #L122 was not covered by tests
where
for<'de> D: From<O::Descr> + serde::Serialize + serde::Deserialize<'de>,
{
eprint!("Loading descriptor");
let sync = self.sync || self.wallet.descriptor_opts.is_some();

let mut wallet: Wallet<XpubDerivable, D> =
let mut wallet: Wallet<XpubDerivable, D, WalletCache<Layer2Empty>> =

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

View check run for this annotation

Codecov / codecov/patch

src/cli/args.rs#L129

Added line #L129 was not covered by tests
if let Some(d) = self.wallet.descriptor_opts.descriptor() {
eprintln!(" from command-line argument");
eprint!("Syncing");
Expand Down
24 changes: 15 additions & 9 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@

use crate::cli::{Args, Config, DescriptorOpts, Exec};
use crate::fs::FsTextStore;
use crate::{coinselect, AnyIndexerError, Indexer, OpType, Wallet, WalletAddr, WalletUtxo};
use crate::{
coinselect, AnyIndexerError, Indexer, Layer2Empty, OpType, Wallet, WalletAddr, WalletCache,
WalletUtxo,
};

#[derive(Subcommand, Clone, PartialEq, Eq, Debug, Display)]
pub enum Command {
Expand Down Expand Up @@ -237,14 +240,17 @@
if config.default_wallet == name { "\t[default]\t" } else { "\t\t" }
);
let provider = FsTextStore::new(entry.path().clone())?;
let wallet = match Wallet::<XpubDerivable, O::Descr>::load(provider, true) {
Err(err) => {
error!("Error loading wallet descriptor: {err}");
println!("# broken wallet descriptor");
continue;
}
Ok(wallet) => wallet,
};
let wallet =
match Wallet::<XpubDerivable, O::Descr, WalletCache<Layer2Empty>>::load(
provider, true,
) {
Err(err) => {
error!("Error loading wallet descriptor: {err}");
println!("# broken wallet descriptor");
continue;

Check warning on line 250 in src/cli/command.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/command.rs#L243-L250

Added lines #L243 - L250 were not covered by tests
}
Ok(wallet) => wallet,

Check warning on line 252 in src/cli/command.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/command.rs#L252

Added line #L252 was not covered by tests
};
println!("\t{}", wallet.descriptor());
}
if count == 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ pub use layer2::{
};
pub use rows::{CoinRow, Counterparty, OpType, TxRow};
pub use util::MayError;
pub use wallet::{Wallet, WalletCache, WalletData, WalletDescr};
pub use wallet::{Wallet, WalletCache, WalletCacheProvider, WalletData, WalletDescr};
80 changes: 1 addition & 79 deletions src/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use std::str::FromStr;
use amplify::hex::FromHex;
use bpstd::{Address, DerivedAddr, Outpoint, Sats, ScriptPubkey, Txid};

use crate::{
BlockHeight, Layer2Cache, Layer2Coin, Layer2Empty, Layer2Tx, Party, TxStatus, WalletCache,
};
use crate::{BlockHeight, Layer2Coin, Layer2Empty, Layer2Tx, Party, TxStatus};

#[cfg_attr(
feature = "serde",
Expand Down Expand Up @@ -146,82 +144,6 @@ pub struct CoinRow<L2: Layer2Coin> {
pub layer2: Vec<L2>,
}

impl<L2: Layer2Cache> WalletCache<L2> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we delete these whole block? I use it in my projects, and there may be other users

@Crayon-Shin-chan-bitlightlabs Crayon-Shin-chan-bitlightlabs Jun 24, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not delete these codes, there were move to WalletProvider trait as default methods

https://github.com/Crayon-Shin-chan-bitlightlabs/bp-wallet/blob/master/src/wallet.rs#L316-L389

pub fn coins(&self) -> impl Iterator<Item = CoinRow<L2::Coin>> + '_ {
self.utxo.iter().map(|outpoint| {
let tx = self.tx.get(&outpoint.txid).expect("cache data inconsistency");
let out = tx.outputs.get(outpoint.vout_usize()).expect("cache data inconsistency");
CoinRow {
height: tx.status.map(|info| info.height),
outpoint: *outpoint,
address: out.derived_addr().expect("cache data inconsistency"),
amount: out.value,
layer2: none!(), // TODO: Add support to WalletTx
}
})
}

pub fn history(&self) -> impl Iterator<Item = TxRow<L2::Tx>> + '_ {
self.tx.values().map(|tx| {
let (credit, debit) = tx.credited_debited();
let mut row = TxRow {
height: tx.status.map(|info| info.height),
operation: OpType::Credit,
our_inputs: tx
.inputs
.iter()
.enumerate()
.filter_map(|(idx, inp)| inp.derived_addr().map(|_| idx as u32))
.collect(),
counterparties: none!(),
own: none!(),
txid: tx.txid,
fee: tx.fee,
weight: tx.weight,
size: tx.size,
total: tx.total_moved(),
amount: Sats::ZERO,
balance: Sats::ZERO,
layer2: none!(), // TODO: Add support to WalletTx
};
// TODO: Add balance calculation
row.own = tx
.inputs
.iter()
.filter_map(|i| i.derived_addr().map(|a| (a, -i.value.sats_i64())))
.chain(
tx.outputs
.iter()
.filter_map(|o| o.derived_addr().map(|a| (a, o.value.sats_i64()))),
)
.collect();
if credit.is_non_zero() {
row.counterparties = tx.credits().fold(Vec::new(), |mut cp, inp| {
let party = Counterparty::from(inp.payer.clone());
cp.push((party, inp.value.sats_i64()));
cp
});
row.counterparties.extend(tx.debits().fold(Vec::new(), |mut cp, out| {
let party = Counterparty::from(out.beneficiary.clone());
cp.push((party, -out.value.sats_i64()));
cp
}));
row.operation = OpType::Credit;
row.amount = credit - debit - tx.fee;
} else if debit.is_non_zero() {
row.counterparties = tx.debits().fold(Vec::new(), |mut cp, out| {
let party = Counterparty::from(out.beneficiary.clone());
cp.push((party, -out.value.sats_i64()));
cp
});
row.operation = OpType::Debit;
row.amount = debit;
}
row
})
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading
Loading