Skip to content

Commit

Permalink
wip: non-functional
Browse files Browse the repository at this point in the history
Nothing to see here.
  • Loading branch information
evanlinjin committed Oct 16, 2023
1 parent 6ebdd19 commit 01ee8c3
Show file tree
Hide file tree
Showing 30 changed files with 675 additions and 472 deletions.
2 changes: 1 addition & 1 deletion crates/bdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main() {
let db = ();

let descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/0'/0'/0/*)";
let mut wallet = Wallet::new(descriptor, None, db, Network::Testnet).expect("should create");
let mut wallet = Wallet::new(descriptor, None, db, Network::Testnet, None).expect("should create");

// get a new address (this increments revealed derivation index)
println!("revealed address: {}", wallet.get_address(AddressIndex::New));
Expand Down
3 changes: 2 additions & 1 deletion crates/bdk/examples/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ fn main() -> Result<(), Box<dyn Error>> {
info!("Compiled into following Descriptor: \n{}", descriptor);

// Create a new wallet from this descriptor
let mut wallet = Wallet::new_no_persist(&format!("{}", descriptor), None, Network::Regtest)?;
let mut wallet =
Wallet::new_no_persist(&format!("{}", descriptor), None, Network::Regtest, None)?;

info!(
"First derived address from the descriptor: \n{}",
Expand Down
16 changes: 12 additions & 4 deletions crates/bdk/src/descriptor/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<T: DescriptorTemplate> IntoWalletDescriptor for T {
///
/// let key =
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
/// let mut wallet = Wallet::new_no_persist(P2Pkh(key), None, Network::Testnet)?;
/// let mut wallet = Wallet::new_no_persist(P2Pkh(key), None, Network::Testnet, None)?;
///
/// assert_eq!(
/// wallet.get_address(New).to_string(),
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<K: IntoDescriptorKey<Legacy>> DescriptorTemplate for P2Pkh<K> {
///
/// let key =
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
/// let mut wallet = Wallet::new_no_persist(P2Wpkh_P2Sh(key), None, Network::Testnet)?;
/// let mut wallet = Wallet::new_no_persist(P2Wpkh_P2Sh(key), None, Network::Testnet, None)?;
///
/// assert_eq!(
/// wallet.get_address(AddressIndex::New).to_string(),
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<K: IntoDescriptorKey<Segwitv0>> DescriptorTemplate for P2Wpkh_P2Sh<K> {
///
/// let key =
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
/// let mut wallet = Wallet::new_no_persist(P2Wpkh(key), None, Network::Testnet)?;
/// let mut wallet = Wallet::new_no_persist(P2Wpkh(key), None, Network::Testnet, None)?;
///
/// assert_eq!(
/// wallet.get_address(New).to_string(),
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<K: IntoDescriptorKey<Segwitv0>> DescriptorTemplate for P2Wpkh<K> {
///
/// let key =
/// bitcoin::PrivateKey::from_wif("cTc4vURSzdx6QE6KVynWGomDbLaA75dNALMNyfjh3p8DRRar84Um")?;
/// let mut wallet = Wallet::new_no_persist(P2TR(key), None, Network::Testnet)?;
/// let mut wallet = Wallet::new_no_persist(P2TR(key), None, Network::Testnet, None)?;
///
/// assert_eq!(
/// wallet.get_address(New).to_string(),
Expand Down Expand Up @@ -200,6 +200,7 @@ impl<K: IntoDescriptorKey<Tap>> DescriptorTemplate for P2TR<K> {
/// Bip44(key.clone(), KeychainKind::External),
/// Some(Bip44(key, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "mmogjc7HJEZkrLqyQYqJmxUqFaC7i4uf89");
Expand Down Expand Up @@ -238,6 +239,7 @@ impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44<K> {
/// Bip44Public(key.clone(), fingerprint, KeychainKind::External),
/// Some(Bip44Public(key, fingerprint, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "miNG7dJTzJqNbFS19svRdTCisC65dsubtR");
Expand Down Expand Up @@ -275,6 +277,7 @@ impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44Public<K> {
/// Bip49(key.clone(), KeychainKind::External),
/// Some(Bip49(key, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "2N4zkWAoGdUv4NXhSsU8DvS5MB36T8nKHEB");
Expand Down Expand Up @@ -313,6 +316,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip49<K> {
/// Bip49Public(key.clone(), fingerprint, KeychainKind::External),
/// Some(Bip49Public(key, fingerprint, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "2N3K4xbVAHoiTQSwxkZjWDfKoNC27pLkYnt");
Expand Down Expand Up @@ -350,6 +354,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip49Public<K> {
/// Bip84(key.clone(), KeychainKind::External),
/// Some(Bip84(key, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "tb1qhl85z42h7r4su5u37rvvw0gk8j2t3n9y7zsg4n");
Expand Down Expand Up @@ -388,6 +393,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip84<K> {
/// Bip84Public(key.clone(), fingerprint, KeychainKind::External),
/// Some(Bip84Public(key, fingerprint, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "tb1qedg9fdlf8cnnqfd5mks6uz5w4kgpk2pr6y4qc7");
Expand Down Expand Up @@ -425,6 +431,7 @@ impl<K: DerivableKey<Segwitv0>> DescriptorTemplate for Bip84Public<K> {
/// Bip86(key.clone(), KeychainKind::External),
/// Some(Bip86(key, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "tb1p5unlj09djx8xsjwe97269kqtxqpwpu2epeskgqjfk4lnf69v4tnqpp35qu");
Expand Down Expand Up @@ -463,6 +470,7 @@ impl<K: DerivableKey<Tap>> DescriptorTemplate for Bip86<K> {
/// Bip86Public(key.clone(), fingerprint, KeychainKind::External),
/// Some(Bip86Public(key, fingerprint, KeychainKind::Internal)),
/// Network::Testnet,
/// None,
/// )?;
///
/// assert_eq!(wallet.get_address(New).to_string(), "tb1pwjp9f2k5n0xq73ecuu0c5njvgqr3vkh7yaylmpqvsuuaafymh0msvcmh37");
Expand Down
9 changes: 9 additions & 0 deletions crates/bdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,12 @@ impl_error!(miniscript::Error, Miniscript);
impl_error!(MiniscriptPsbtError, MiniscriptPsbt);
impl_error!(bitcoin::bip32::Error, Bip32);
impl_error!(bitcoin::psbt::Error, Psbt);

impl From<crate::wallet::NewNoPersistError> for Error {
fn from(e: crate::wallet::NewNoPersistError) -> Self {
match e {
wallet::NewNoPersistError::Descriptor(e) => Error::Descriptor(e),
unknown_network_err => Error::Generic(format!("{}", unknown_network_err)),
}
}
}
5 changes: 4 additions & 1 deletion crates/bdk/src/wallet/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! &import.descriptor(),
//! import.change_descriptor().as_ref(),
//! Network::Testnet,
//! None,
//! )?;
//! # Ok::<_, Box<dyn std::error::Error>>(())
//! ```
Expand All @@ -46,6 +47,7 @@
//! "wpkh([c258d2e4/84h/1h/0h]tpubDD3ynpHgJQW8VvWRzQ5WFDCrs4jqVFGHB3vLC3r49XHJSqP8bHKdK4AriuUKLccK68zfzowx7YhmDN8SiSkgCDENUFx9qVw65YyqM78vyVe/0/*)",
//! Some("wpkh([c258d2e4/84h/1h/0h]tpubDD3ynpHgJQW8VvWRzQ5WFDCrs4jqVFGHB3vLC3r49XHJSqP8bHKdK4AriuUKLccK68zfzowx7YhmDN8SiSkgCDENUFx9qVw65YyqM78vyVe/1/*)"),
//! Network::Testnet,
//! None,
//! )?;
//! let export = FullyNodedExport::export_wallet(&wallet, "exported wallet", true).unwrap();
//!
Expand Down Expand Up @@ -226,7 +228,8 @@ mod test {
change_descriptor: Option<&str>,
network: Network,
) -> Wallet<()> {
let mut wallet = Wallet::new_no_persist(descriptor, change_descriptor, network).unwrap();
let mut wallet =
Wallet::new_no_persist(descriptor, change_descriptor, network, None).unwrap();
let transaction = Transaction {
input: vec![],
output: vec![],
Expand Down
Loading

0 comments on commit 01ee8c3

Please sign in to comment.