Skip to content

Commit

Permalink
chain: send block over dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Jun 13, 2024
1 parent 8be8411 commit 3249894
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,13 @@ impl Chain {
// Scan an incoming block for transactions with our scripts
pub(crate) async fn scan_block(&mut self, block: &Block) -> Result<(), BlockScanError> {
self.block_queue.receive_one();
let mut contains_relevant = false;
match self.height_of_hash(block.block_hash()).await {
Some(height) => {
self.dialog
.send_data(NodeMessage::Block(IndexedBlock::new(height, block.clone())))
.await;
for tx in &block.txdata {
if self.scan_inputs(&tx.input) || self.scan_outputs(&tx.output) {
contains_relevant = true;
self.dialog
.send_data(NodeMessage::Transaction(IndexedTransaction::new(
tx.clone(),
Expand All @@ -589,11 +590,6 @@ impl Chain {
.await;
}
}
if contains_relevant {
self.dialog
.send_data(NodeMessage::Block(IndexedBlock::new(height, block.clone())))
.await;
}
Ok(())
}
None => Err(BlockScanError::NoBlockHash),
Expand All @@ -612,6 +608,7 @@ impl Chain {
.any(|out| self.scripts.contains(&out.script_pubkey))
}

// Add more scripts to our list
pub(crate) fn put_scripts(&mut self, scripts: HashSet<ScriptBuf>) {
for script in scripts {
self.scripts.insert(script);
Expand Down
1 change: 1 addition & 0 deletions src/node/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl Node {
let mut node_map = PeerMap::new(mtx, self.network);
let mut tx_broadcaster = Broadcaster::new();
loop {
// Try to advance the state of the node and remove old connections
self.advance_state().await;
node_map.clean().await;
// Rehydrate on peers when lower than a threshold
Expand Down

0 comments on commit 3249894

Please sign in to comment.