Skip to content

Instantly share code, notes, and snippets.

@RCasatta
Created December 12, 2022 15:22
Show Gist options
  • Save RCasatta/a04500a4b28f3840912a54bd3b5bb938 to your computer and use it in GitHub Desktop.
Save RCasatta/a04500a4b28f3840912a54bd3b5bb938 to your computer and use it in GitHub Desktop.
test subscribe
use bitcoin::secp256k1::Secp256k1;
use electrum_client::ElectrumApi;
use electrum_client::Client;
use bitcoin::util::bip32;
use bitcoin::util::bip32::DerivationPath;
use bitcoin::Address;
use bitcoin::Network;
use std::str::FromStr;
fn main() {
let client = Client::new("tcp://electrum.blockstream.info:50001").unwrap();
let secp = Secp256k1::verification_only();
let xpub = bip32::ExtendedPubKey::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap();
let mut i = 0;
loop {
let p = DerivationPath::from_str(&format!("m/{i}")).unwrap();
i += 1;
let derived = xpub.derive_pub(&secp, &p).unwrap().to_pub();
let a = Address::p2pkh(&derived, Network::Bitcoin);
client.script_subscribe(&a.script_pubkey()).unwrap();
println!("{i}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment