use crate::rpc;
use sc_client_api::backend::{Backend as ClientBackend, Finalizer};
use sp_runtime::{traits::Block as BlockT, Justification};
use std::{marker::PhantomData, sync::Arc};
pub struct FinalizeBlockParams<B: BlockT, F, CB> {
pub hash: <B as BlockT>::Hash,
pub sender: rpc::Sender<()>,
pub justification: Option<Justification>,
pub finalizer: Arc<F>,
pub _phantom: PhantomData<CB>,
}
pub async fn finalize_block<B, F, CB>(params: FinalizeBlockParams<B, F, CB>)
where
B: BlockT,
F: Finalizer<B, CB>,
CB: ClientBackend<B>,
{
let FinalizeBlockParams { hash, mut sender, justification, finalizer, .. } = params;
match finalizer.finalize_block(hash, justification, true) {
Err(e) => {
log::warn!("Failed to finalize block {}", e);
rpc::send_result(&mut sender, Err(e.into()))
},
Ok(()) => {
log::info!("✅ Successfully finalized block: {}", hash);
rpc::send_result(&mut sender, Ok(()))
},
}
}