Merge bitcoindevkit/bdk#563: update AddressInfo struct
2698fc0219eb360e84a89ceabba4793777bf550b update AddressInfo struct (eunoia_1729) Pull request description: ### Description Resolves #541. - Updates `AddressInfo` struct to include `keychainKind` - Updates the related `get_address` functions to pass in this field - Updates corresponding tests ### 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 Top commit has no ACKs. Tree-SHA512: b1d22e5f322e1a35390fb06a5185457bd53af7c4a9c4e6e2fd5e93b967fa3f56af5848ac314e63e2b0becd60dbc8a4eeb761a2bdebfe8ba43ce49b13da4190b2
This commit is contained in:
commit
9c0141b5e3
@ -140,6 +140,8 @@ pub struct AddressInfo {
|
||||
pub index: u32,
|
||||
/// Address
|
||||
pub address: Address,
|
||||
/// Type of keychain
|
||||
pub keychain: KeychainKind,
|
||||
}
|
||||
|
||||
impl Deref for AddressInfo {
|
||||
@ -246,6 +248,7 @@ where
|
||||
.map(|address| AddressInfo {
|
||||
address,
|
||||
index: incremented_index,
|
||||
keychain,
|
||||
})
|
||||
.map_err(|_| Error::ScriptDoesntHaveAddressForm)
|
||||
}
|
||||
@ -276,6 +279,7 @@ where
|
||||
.map(|address| AddressInfo {
|
||||
address,
|
||||
index: current_index,
|
||||
keychain,
|
||||
})
|
||||
.map_err(|_| Error::ScriptDoesntHaveAddressForm)
|
||||
}
|
||||
@ -286,7 +290,11 @@ where
|
||||
self.get_descriptor_for_keychain(keychain)
|
||||
.as_derived(index, &self.secp)
|
||||
.address(self.network)
|
||||
.map(|address| AddressInfo { index, address })
|
||||
.map(|address| AddressInfo {
|
||||
index,
|
||||
address,
|
||||
keychain,
|
||||
})
|
||||
.map_err(|_| Error::ScriptDoesntHaveAddressForm)
|
||||
}
|
||||
|
||||
@ -298,7 +306,11 @@ where
|
||||
self.get_descriptor_for_keychain(keychain)
|
||||
.as_derived(index, &self.secp)
|
||||
.address(self.network)
|
||||
.map(|address| AddressInfo { index, address })
|
||||
.map(|address| AddressInfo {
|
||||
index,
|
||||
address,
|
||||
keychain,
|
||||
})
|
||||
.map_err(|_| Error::ScriptDoesntHaveAddressForm)
|
||||
}
|
||||
|
||||
@ -3924,6 +3936,7 @@ pub(crate) mod test {
|
||||
AddressInfo {
|
||||
index: 0,
|
||||
address: Address::from_str("tb1q6yn66vajcctph75pvylgkksgpp6nq04ppwct9a").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
|
||||
@ -3932,7 +3945,8 @@ pub(crate) mod test {
|
||||
wallet.get_address(New).unwrap(),
|
||||
AddressInfo {
|
||||
index: 1,
|
||||
address: Address::from_str("tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7").unwrap()
|
||||
address: Address::from_str("tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
|
||||
@ -3941,7 +3955,8 @@ pub(crate) mod test {
|
||||
wallet.get_address(Peek(25)).unwrap(),
|
||||
AddressInfo {
|
||||
index: 25,
|
||||
address: Address::from_str("tb1qsp7qu0knx3sl6536dzs0703u2w2ag6ppl9d0c2").unwrap()
|
||||
address: Address::from_str("tb1qsp7qu0knx3sl6536dzs0703u2w2ag6ppl9d0c2").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
|
||||
@ -3950,7 +3965,8 @@ pub(crate) mod test {
|
||||
wallet.get_address(New).unwrap(),
|
||||
AddressInfo {
|
||||
index: 2,
|
||||
address: Address::from_str("tb1qzntf2mqex4ehwkjlfdyy3ewdlk08qkvkvrz7x2").unwrap()
|
||||
address: Address::from_str("tb1qzntf2mqex4ehwkjlfdyy3ewdlk08qkvkvrz7x2").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
|
||||
@ -3959,7 +3975,8 @@ pub(crate) mod test {
|
||||
wallet.get_address(Reset(1)).unwrap(),
|
||||
AddressInfo {
|
||||
index: 1,
|
||||
address: Address::from_str("tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7").unwrap()
|
||||
address: Address::from_str("tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
|
||||
@ -3968,7 +3985,8 @@ pub(crate) mod test {
|
||||
wallet.get_address(New).unwrap(),
|
||||
AddressInfo {
|
||||
index: 2,
|
||||
address: Address::from_str("tb1qzntf2mqex4ehwkjlfdyy3ewdlk08qkvkvrz7x2").unwrap()
|
||||
address: Address::from_str("tb1qzntf2mqex4ehwkjlfdyy3ewdlk08qkvkvrz7x2").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -3997,15 +4015,21 @@ pub(crate) mod test {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
wallet.get_address(AddressIndex::New).unwrap().address,
|
||||
Address::from_str("bcrt1qkmvk2nadgplmd57ztld8nf8v2yxkzmdvwtjf8s").unwrap()
|
||||
wallet.get_address(AddressIndex::New).unwrap(),
|
||||
AddressInfo {
|
||||
index: 0,
|
||||
address: Address::from_str("bcrt1qkmvk2nadgplmd57ztld8nf8v2yxkzmdvwtjf8s").unwrap(),
|
||||
keychain: KeychainKind::External,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
wallet
|
||||
.get_internal_address(AddressIndex::New)
|
||||
.unwrap()
|
||||
.address,
|
||||
Address::from_str("bcrt1qtrwtz00wxl69e5xex7amy4xzlxkaefg3gfdkxa").unwrap()
|
||||
wallet.get_internal_address(AddressIndex::New).unwrap(),
|
||||
AddressInfo {
|
||||
index: 0,
|
||||
address: Address::from_str("bcrt1qtrwtz00wxl69e5xex7amy4xzlxkaefg3gfdkxa").unwrap(),
|
||||
keychain: KeychainKind::Internal,
|
||||
}
|
||||
);
|
||||
|
||||
let wallet = Wallet::new(
|
||||
@ -4017,11 +4041,12 @@ pub(crate) mod test {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
wallet
|
||||
.get_internal_address(AddressIndex::New)
|
||||
.unwrap()
|
||||
.address,
|
||||
Address::from_str("bcrt1qkmvk2nadgplmd57ztld8nf8v2yxkzmdvwtjf8s").unwrap(),
|
||||
wallet.get_internal_address(AddressIndex::New).unwrap(),
|
||||
AddressInfo {
|
||||
index: 0,
|
||||
address: Address::from_str("bcrt1qkmvk2nadgplmd57ztld8nf8v2yxkzmdvwtjf8s").unwrap(),
|
||||
keychain: KeychainKind::Internal,
|
||||
},
|
||||
"when there's no internal descriptor it should just use external"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user