Skip to content

Commit 3a07614

Browse files
committed
Merge #471: moving the function wallet_name_from_descriptor from blockchain/rpc.rs to wallet/mod.rs as it can be useful not only for rpc
2fc8114 moving the function wallet_name_from_descriptor from blockchain/rpc.rs to wallet/mod.rs as it can be useful not only for rpc (Richard Ulrich) Pull request description: ### Description Moving the function wallet_name_from_descriptor from rpc.rs to mod.rs Since the local cache for compact filters should be separate per wallet, this function can be useful not only for rpc. ### Notes to the reviewers I thought about renaming it, but waited for opinions on that. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: re-ACK 2fc8114 Tree-SHA512: d5732e74f7a54f54dde39fff77f94f12c611a419bed9683025ecf7be95cde330209f676dfc9346ebcd29194325589710eafdd1d533e8073d0662cb397577119f
2 parents b2ac4a0 + 2fc8114 commit 3a07614

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

src/blockchain/compact_filters/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub struct CompactFiltersBlockchainConfig {
472472
pub peers: Vec<BitcoinPeerConfig>,
473473
/// Network used
474474
pub network: Network,
475-
/// Storage dir to save partially downloaded headers and full blocks
475+
/// Storage dir to save partially downloaded headers and full blocks. Should be a separate directory per descriptor. Consider using [crate::wallet::wallet_name_from_descriptor] for this.
476476
pub storage_dir: String,
477477
/// Optionally skip initial `skip_blocks` blocks (default: 0)
478478
pub skip_blocks: Option<usize>,

src/blockchain/rpc.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ use crate::bitcoin::consensus::deserialize;
3535
use crate::bitcoin::{Address, Network, OutPoint, Transaction, TxOut, Txid};
3636
use crate::blockchain::{Blockchain, Capability, ConfigurableBlockchain, Progress};
3737
use crate::database::{BatchDatabase, DatabaseUtils};
38-
use crate::descriptor::{get_checksum, IntoWalletDescriptor};
39-
use crate::wallet::utils::SecpCtx;
4038
use crate::{BlockTime, Error, FeeRate, KeychainKind, LocalUtxo, TransactionDetails};
4139
use bitcoincore_rpc::json::{
4240
GetAddressInfoResultLabel, ImportMultiOptions, ImportMultiRequest,
@@ -76,7 +74,7 @@ pub struct RpcConfig {
7674
pub auth: Auth,
7775
/// The network we are using (it will be checked the bitcoin node network matches this)
7876
pub network: Network,
79-
/// The wallet name in the bitcoin node, consider using [wallet_name_from_descriptor] for this
77+
/// The wallet name in the bitcoin node, consider using [crate::wallet::wallet_name_from_descriptor] for this
8078
pub wallet_name: String,
8179
/// Skip this many blocks of the blockchain at the first rescan, if None the rescan is done from the genesis block
8280
pub skip_blocks: Option<u32>,
@@ -415,35 +413,6 @@ impl ConfigurableBlockchain for RpcBlockchain {
415413
}
416414
}
417415

418-
/// Deterministically generate a unique name given the descriptors defining the wallet
419-
pub fn wallet_name_from_descriptor<T>(
420-
descriptor: T,
421-
change_descriptor: Option<T>,
422-
network: Network,
423-
secp: &SecpCtx,
424-
) -> Result<String, Error>
425-
where
426-
T: IntoWalletDescriptor,
427-
{
428-
//TODO check descriptors contains only public keys
429-
let descriptor = descriptor
430-
.into_wallet_descriptor(secp, network)?
431-
.0
432-
.to_string();
433-
let mut wallet_name = get_checksum(&descriptor[..descriptor.find('#').unwrap()])?;
434-
if let Some(change_descriptor) = change_descriptor {
435-
let change_descriptor = change_descriptor
436-
.into_wallet_descriptor(secp, network)?
437-
.0
438-
.to_string();
439-
wallet_name.push_str(
440-
get_checksum(&change_descriptor[..change_descriptor.find('#').unwrap()])?.as_str(),
441-
);
442-
}
443-
444-
Ok(wallet_name)
445-
}
446-
447416
/// return the wallets available in default wallet directory
448417
//TODO use bitcoincore_rpc method when PR #179 lands
449418
fn list_wallet_dir(client: &Client) -> Result<Vec<String>, Error> {

src/wallet/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,3 +4006,32 @@ pub(crate) mod test {
40064006
builder.finish().unwrap();
40074007
}
40084008
}
4009+
4010+
/// Deterministically generate a unique name given the descriptors defining the wallet
4011+
pub fn wallet_name_from_descriptor<T>(
4012+
descriptor: T,
4013+
change_descriptor: Option<T>,
4014+
network: Network,
4015+
secp: &SecpCtx,
4016+
) -> Result<String, Error>
4017+
where
4018+
T: IntoWalletDescriptor,
4019+
{
4020+
//TODO check descriptors contains only public keys
4021+
let descriptor = descriptor
4022+
.into_wallet_descriptor(secp, network)?
4023+
.0
4024+
.to_string();
4025+
let mut wallet_name = get_checksum(&descriptor[..descriptor.find('#').unwrap()])?;
4026+
if let Some(change_descriptor) = change_descriptor {
4027+
let change_descriptor = change_descriptor
4028+
.into_wallet_descriptor(secp, network)?
4029+
.0
4030+
.to_string();
4031+
wallet_name.push_str(
4032+
get_checksum(&change_descriptor[..change_descriptor.find('#').unwrap()])?.as_str(),
4033+
);
4034+
}
4035+
4036+
Ok(wallet_name)
4037+
}

0 commit comments

Comments
 (0)