Replace electrum with blindbit

This commit is contained in:
NicolasCantu 2025-06-03 18:40:47 +02:00 committed by Sosthene
parent fbabe71e76
commit 760a377a3e
2 changed files with 21 additions and 14 deletions

View File

@ -267,7 +267,7 @@ fn create_new_tx_message(transaction: Vec<u8>) -> Result<NewTxMessage> {
)) ))
} }
async fn handle_zmq(zmq_url: String, electrum_url: String) { async fn handle_zmq(zmq_url: String, blindbit_url: String) {
debug!("Starting listening on Core"); debug!("Starting listening on Core");
let mut socket = zeromq::SubSocket::new(); let mut socket = zeromq::SubSocket::new();
socket.connect(&zmq_url).await.unwrap(); socket.connect(&zmq_url).await.unwrap();
@ -297,7 +297,7 @@ async fn handle_zmq(zmq_url: String, electrum_url: String) {
continue; continue;
} }
}, },
Ok("hashblock") => match scan_blocks(0, &electrum_url) { Ok("hashblock") => match scan_blocks(0, &blindbit_url).await {
Ok(_) => continue, Ok(_) => continue,
Err(e) => { Err(e) => {
error!("{}", e); error!("{}", e);
@ -472,14 +472,14 @@ async fn main() -> Result<()> {
if last_scan < current_tip { if last_scan < current_tip {
log::info!("Scanning for our outputs"); log::info!("Scanning for our outputs");
scan_blocks(current_tip - last_scan, &config.electrum_url)?; scan_blocks(current_tip - last_scan, &config.blindbit_url)?;
} }
Set CHAIN_TIP // Set CHAIN_TIP
CHAIN_TIP.store(current_tip as u64, std::sync::atomic::Ordering::SeqCst); CHAIN_TIP.store(current_tip as u64, std::sync::atomic::Ordering::SeqCst);
// Subscribe to Bitcoin Core // Subscribe to Bitcoin Core
tokio::spawn(handle_zmq(config.zmq_url, config.electrum_url)); tokio::spawn(handle_zmq(config.zmq_url, config.blindbit_url));
// Create the event loop and TCP listener we'll accept connections on. // Create the event loop and TCP listener we'll accept connections on.
let try_socket = TcpListener::bind(config.ws_url).await; let try_socket = TcpListener::bind(config.ws_url).await;

View File

@ -3,10 +3,8 @@ use std::str::FromStr;
use std::sync::MutexGuard; use std::sync::MutexGuard;
use anyhow::{Error, Result}; use anyhow::{Error, Result};
use bitcoincore_rpc::bitcoin::absolute::Height; use bitcoincore_rpc::bitcoin::absolute::{Amount, Height};
use bitcoincore_rpc::bitcoin::hashes::Hash; use sdk_common::silentpayments::{SpWallet, StateUpdater};
use electrum_client::ElectrumApi;
use sdk_common::silentpayments::SpWallet;
use sdk_common::sp_client::bitcoin::bip158::BlockFilter; use sdk_common::sp_client::bitcoin::bip158::BlockFilter;
use sdk_common::sp_client::bitcoin::hex::DisplayHex; use sdk_common::sp_client::bitcoin::hex::DisplayHex;
use sdk_common::sp_client::bitcoin::secp256k1::{All, PublicKey, Scalar, Secp256k1, SecretKey}; use sdk_common::sp_client::bitcoin::secp256k1::{All, PublicKey, Scalar, Secp256k1, SecretKey};
@ -15,10 +13,10 @@ use sdk_common::sp_client::silentpayments::receiving::Receiver;
use sdk_common::sp_client::silentpayments::utils::receiving::{ use sdk_common::sp_client::silentpayments::utils::receiving::{
calculate_tweak_data, get_pubkey_from_input, calculate_tweak_data, get_pubkey_from_input,
}; };
use sdk_common::sp_client::{OutputSpendStatus, OwnedOutput}; use sdk_common::sp_client::{OutputSpendStatus, OwnedOutput, SpScanner};
use tokio::time::Instant; use tokio::time::Instant;
use crate::{electrumclient, MutexExt, DAEMON, STORAGE, WALLET}; use crate::{MutexExt, DAEMON, STORAGE, WALLET};
pub fn compute_partial_tweak_to_transaction(tx: &Transaction) -> Result<PublicKey> { pub fn compute_partial_tweak_to_transaction(tx: &Transaction) -> Result<PublicKey> {
let daemon = DAEMON.get().ok_or(Error::msg("DAEMON not initialized"))?; let daemon = DAEMON.get().ok_or(Error::msg("DAEMON not initialized"))?;
@ -236,9 +234,9 @@ fn scan_block_inputs(
Ok(found) Ok(found)
} }
pub fn scan_blocks(mut n_blocks_to_scan: u32, electrum_url: &str) -> anyhow::Result<()> { pub async fn scan_blocks(mut n_blocks_to_scan: u32, blindbit_url: &str) -> anyhow::Result<()> {
log::info!("Starting a rescan"); log::info!("Starting a rescan");
let electrum_client = electrumclient::create_electrum_client(electrum_url)?; let blindbit_client = sdk_common::sp_client::BlindbitClient::new(blindbit_url.to_owned())?;
let mut sp_wallet = WALLET let mut sp_wallet = WALLET
.get() .get()
@ -270,13 +268,22 @@ pub fn scan_blocks(mut n_blocks_to_scan: u32, electrum_url: &str) -> anyhow::Res
return Ok(()); return Ok(());
} }
let updater = StateUpdater::new();
log::info!("start: {} end: {}", start, end); log::info!("start: {} end: {}", start, end);
SpScanner::new(
sp_wallet.get_sp_client().clone(),
Box::new(updater),
backend,
owned_outpoints,
keep_scanning
);
let mut filters: Vec<(u32, BlockHash, BlockFilter)> = vec![]; let mut filters: Vec<(u32, BlockHash, BlockFilter)> = vec![];
for blkheight in start..=end { for blkheight in start..=end {
filters.push(core.get_filters(blkheight)?); filters.push(core.get_filters(blkheight)?);
} }
let mut tweak_data_map = electrum_client.sp_tweaks(start as usize)?; let mut tweak_data_map = blindbit_client.tweaks(Height::from_consensus(start)?, Amount::from_sat(550)).await?;
let scan_sk = sp_wallet.get_sp_client().get_scan_key(); let scan_sk = sp_wallet.get_sp_client().get_scan_key();