feat: Make blockfetch observer mutable (#86)

This commit is contained in:
Santiago Carmuega 2022-04-08 18:52:38 -03:00 committed by GitHub
parent 07169cc45a
commit 86a2bcc9ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -16,7 +16,7 @@ use std::net::TcpStream;
struct BlockPrinter;
impl Observer for BlockPrinter {
fn on_block_received(&self, body: Vec<u8>) -> Result<(), Box<dyn std::error::Error>> {
fn on_block_received(&mut self, body: Vec<u8>) -> Result<(), Box<dyn std::error::Error>> {
println!("{}", hex::encode(&body));
println!("----------");
Ok(())

View file

@ -88,7 +88,7 @@ impl<'b> Decode<'b> for Message {
}
pub trait Observer {
fn on_block_received(&self, body: Vec<u8>) -> Result<(), Box<dyn std::error::Error>> {
fn on_block_received(&mut self, body: Vec<u8>) -> Result<(), Box<dyn std::error::Error>> {
log::debug!("block received, sice: {}", body.len());
Ok(())
}
@ -148,7 +148,7 @@ where
})
}
fn on_block(self, body: Vec<u8>) -> Transition<Self> {
fn on_block(mut self, body: Vec<u8>) -> Transition<Self> {
log::debug!("received block body, size {}", body.len());
self.observer.on_block_received(body)?;
@ -287,7 +287,7 @@ where
})
}
fn on_block(self, body: Vec<u8>) -> Transition<Self> {
fn on_block(mut self, body: Vec<u8>) -> Transition<Self> {
log::debug!("received block body, size {}", body.len());
self.observer.on_block_received(body)?;