use std::{collections::HashMap, io::Result};
use crate::{
ids,
rpcchainvm::{
common::{
apphandler::AppHandler, appsender::AppSender, http_handler::HttpHandler,
message::Message,
},
context::Context,
database::manager::Manager,
health::Checkable,
snow::State,
},
};
use tokio::sync::mpsc::Sender;
#[tonic::async_trait]
pub trait Vm: AppHandler + Connector + Checkable {
async fn initialize(
&mut self,
ctx: Option<Context>,
db_manager: Box<dyn Manager + Send + Sync>,
genesis_bytes: &[u8],
upgrade_bytes: &[u8],
config_bytes: &[u8],
to_engine: Sender<Message>,
fxs: &[Fx],
app_sender: Box<dyn AppSender + Send + Sync>,
) -> Result<()>;
async fn set_state(&self, state: State) -> Result<()>;
async fn shutdown(&self) -> Result<()>;
async fn version(&self) -> Result<String>;
async fn create_static_handlers(&self) -> Result<HashMap<String, HttpHandler>>;
async fn create_handlers(&self) -> Result<HashMap<String, HttpHandler>>;
}
#[tonic::async_trait]
pub trait Connector {
async fn connected(&self, id: &ids::node::Id) -> Result<()>;
async fn disconnected(&self, id: &ids::node::Id) -> Result<()>;
}
pub type Fx = ();