descriptors: rename derive into derive_received
We'll be able to derive change addresses too
This commit is contained in:
parent
f985fd7879
commit
caaca1fd1a
@ -172,7 +172,9 @@ fn serializable_size<T: bitcoin::consensus::Encodable + ?Sized>(t: &T) -> u64 {
|
||||
impl DaemonControl {
|
||||
// Get the descriptor at this derivation index
|
||||
fn derived_desc(&self, index: bip32::ChildNumber) -> descriptors::DerivedInheritanceDescriptor {
|
||||
self.config.main_descriptor.derive(index, &self.secp)
|
||||
self.config
|
||||
.main_descriptor
|
||||
.derive_receive(index, &self.secp)
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,9 +203,7 @@ impl DaemonControl {
|
||||
// TODO: should we wrap around instead of failing?
|
||||
db_conn.increment_derivation_index(&self.secp);
|
||||
let address = self
|
||||
.config
|
||||
.main_descriptor
|
||||
.derive(index, &self.secp)
|
||||
.derived_desc(index)
|
||||
.address(self.config.bitcoin_config.network);
|
||||
GetAddressResult { address }
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ impl SqliteConn {
|
||||
let next_la_index = next_index + LOOK_AHEAD_LIMIT - 1;
|
||||
let next_la_address = db_wallet
|
||||
.main_descriptor
|
||||
.derive(next_la_index.into(), secp)
|
||||
.derive_receive(next_la_index.into(), secp)
|
||||
.address(network);
|
||||
db_tx
|
||||
.execute(
|
||||
@ -714,7 +714,7 @@ mod tests {
|
||||
// There is the index for the first index
|
||||
let addr = options
|
||||
.main_descriptor
|
||||
.derive(0.into(), &secp)
|
||||
.derive_receive(0.into(), &secp)
|
||||
.address(options.bitcoind_network);
|
||||
let db_addr = conn.db_address(&addr).unwrap();
|
||||
assert_eq!(db_addr.derivation_index, 0.into());
|
||||
@ -722,7 +722,7 @@ mod tests {
|
||||
// There is the index for the 199th index (look-ahead limit)
|
||||
let addr = options
|
||||
.main_descriptor
|
||||
.derive(199.into(), &secp)
|
||||
.derive_receive(199.into(), &secp)
|
||||
.address(options.bitcoind_network);
|
||||
let db_addr = conn.db_address(&addr).unwrap();
|
||||
assert_eq!(db_addr.derivation_index, 199.into());
|
||||
@ -730,7 +730,7 @@ mod tests {
|
||||
// And not for the 200th one.
|
||||
let addr = options
|
||||
.main_descriptor
|
||||
.derive(200.into(), &secp)
|
||||
.derive_receive(200.into(), &secp)
|
||||
.address(options.bitcoind_network);
|
||||
assert!(conn.db_address(&addr).is_none());
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ pub fn create_fresh_db(
|
||||
// TODO: have this as a helper in descriptors.rs
|
||||
let address = options
|
||||
.main_descriptor
|
||||
.derive(index.into(), secp)
|
||||
.derive_receive(index.into(), secp)
|
||||
.address(options.bitcoind_network);
|
||||
query += &format!(
|
||||
"INSERT INTO addresses (address, derivation_index) VALUES (\"{}\", {});\n",
|
||||
|
||||
@ -327,11 +327,11 @@ impl InheritanceDescriptor {
|
||||
})
|
||||
}
|
||||
|
||||
/// Derive this descriptor at a given index.
|
||||
/// Derive this descriptor at a given index for a receiving address.
|
||||
///
|
||||
/// # Panics
|
||||
/// - If the given index is hardened.
|
||||
pub fn derive(
|
||||
pub fn derive_receive(
|
||||
&self,
|
||||
index: bip32::ChildNumber,
|
||||
secp: &secp256k1::Secp256k1<impl secp256k1::Verification>,
|
||||
@ -504,7 +504,7 @@ mod tests {
|
||||
fn inheritance_descriptor_derivation() {
|
||||
let secp = secp256k1::Secp256k1::verification_only();
|
||||
let desc = InheritanceDescriptor::from_str("wsh(andor(pk(tpubDEN9WSToTyy9ZQfaYqSKfmVqmq1VVLNtYfj3Vkqh67et57eJ5sTKZQBkHqSwPUsoSskJeaYnPttHe2VrkCsKA27kUaN9SDc5zhqeLzKa1rr/*),older(10000),pk(tpubD8LYfn6njiA2inCoxwM7EuN3cuLVcaHAwLYeups13dpevd3nHLRdK9NdQksWXrhLQVxcUZRpnp5CkJ1FhE61WRAsHxDNAkvGkoQkAeWDYjV/*)))#y5wcna2d").unwrap();
|
||||
let der_desc = desc.derive(11.into(), &secp);
|
||||
let der_desc = desc.derive_receive(11.into(), &secp);
|
||||
assert_eq!(
|
||||
"bc1qvjzcg25nsxmfccct0txjvljxjwn68htkrw57jqmjhfzvhyd2z4msc74w65",
|
||||
der_desc.address(bitcoin::Network::Bitcoin).to_string()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user