use consensus::engine::{Block, BlockId, Error, PeerId};
use std::collections::HashMap;
pub trait Service {
#[allow(clippy::ptr_arg)]
fn send_to(&mut self, peer: &PeerId, message_type: &str, payload: Vec<u8>)
-> Result<(), Error>;
fn broadcast(&mut self, message_type: &str, payload: Vec<u8>) -> Result<(), Error>;
fn initialize_block(&mut self, previous_id: Option<BlockId>) -> Result<(), Error>;
fn summarize_block(&mut self) -> Result<Vec<u8>, Error>;
fn finalize_block(&mut self, data: Vec<u8>) -> Result<BlockId, Error>;
fn cancel_block(&mut self) -> Result<(), Error>;
fn check_blocks(&mut self, priority: Vec<BlockId>) -> Result<(), Error>;
fn commit_block(&mut self, block_id: BlockId) -> Result<(), Error>;
fn ignore_block(&mut self, block_id: BlockId) -> Result<(), Error>;
fn fail_block(&mut self, block_id: BlockId) -> Result<(), Error>;
fn get_blocks(&mut self, block_ids: Vec<BlockId>) -> Result<HashMap<BlockId, Block>, Error>;
fn get_chain_head(&mut self) -> Result<Block, Error>;
fn get_settings(
&mut self,
block_id: BlockId,
keys: Vec<String>,
) -> Result<HashMap<String, String>, Error>;
fn get_state(
&mut self,
block_id: BlockId,
addresses: Vec<String>,
) -> Result<HashMap<String, Vec<u8>>, Error>;
}
#[cfg(test)]
pub mod tests {
use super::*;
use std::default::Default;
pub struct MockService {}
impl Service for MockService {
fn send_to(
&mut self,
_peer: &PeerId,
_message_type: &str,
_payload: Vec<u8>,
) -> Result<(), Error> {
Ok(())
}
fn broadcast(&mut self, _message_type: &str, _payload: Vec<u8>) -> Result<(), Error> {
Ok(())
}
fn initialize_block(&mut self, _previous_id: Option<BlockId>) -> Result<(), Error> {
Ok(())
}
fn summarize_block(&mut self) -> Result<Vec<u8>, Error> {
Ok(Default::default())
}
fn finalize_block(&mut self, _data: Vec<u8>) -> Result<BlockId, Error> {
Ok(Default::default())
}
fn cancel_block(&mut self) -> Result<(), Error> {
Ok(())
}
fn check_blocks(&mut self, _priority: Vec<BlockId>) -> Result<(), Error> {
Ok(())
}
fn commit_block(&mut self, _block_id: BlockId) -> Result<(), Error> {
Ok(())
}
fn ignore_block(&mut self, _block_id: BlockId) -> Result<(), Error> {
Ok(())
}
fn fail_block(&mut self, _block_id: BlockId) -> Result<(), Error> {
Ok(())
}
fn get_blocks(
&mut self,
_block_ids: Vec<BlockId>,
) -> Result<HashMap<BlockId, Block>, Error> {
Ok(Default::default())
}
fn get_chain_head(&mut self) -> Result<Block, Error> {
Ok(Default::default())
}
fn get_settings(
&mut self,
_block_id: BlockId,
_settings: Vec<String>,
) -> Result<HashMap<String, String>, Error> {
Ok(Default::default())
}
fn get_state(
&mut self,
_block_id: BlockId,
_addresses: Vec<String>,
) -> Result<HashMap<String, Vec<u8>>, Error> {
Ok(Default::default())
}
}
}