muta_protocol/traits/
executor.rs1use std::sync::Arc;
2
3use crate::traits::{ServiceMapping, Storage};
4use crate::types::{
5 Address, Bloom, MerkleRoot, Receipt, ServiceContext, SignedTransaction, TransactionRequest,
6};
7use crate::ProtocolResult;
8
9#[derive(Debug, Clone)]
10pub struct ExecutorResp {
11 pub receipts: Vec<Receipt>,
12 pub all_cycles_used: u64,
13 pub logs_bloom: Bloom,
14 pub state_root: MerkleRoot,
15}
16
17#[derive(Debug, Clone)]
18pub struct ExecutorParams {
19 pub state_root: MerkleRoot,
20 pub epoch_id: u64,
21 pub timestamp: u64,
22 pub cycles_limit: u64,
23}
24
25#[derive(Debug, Clone)]
26pub struct ExecResp {
27 pub ret: String,
28 pub is_error: bool,
29}
30
31pub trait ExecutorFactory<DB: cita_trie::DB, S: Storage, Mapping: ServiceMapping>:
32 Send + Sync
33{
34 fn from_root(
35 root: MerkleRoot,
36 db: Arc<DB>,
37 storage: Arc<S>,
38 mapping: Arc<Mapping>,
39 ) -> ProtocolResult<Box<dyn Executor>>;
40}
41
42pub trait Executor {
43 fn exec(
44 &mut self,
45 params: &ExecutorParams,
46 txs: &[SignedTransaction],
47 ) -> ProtocolResult<ExecutorResp>;
48
49 fn read(
50 &self,
51 params: &ExecutorParams,
52 caller: &Address,
53 cycles_price: u64,
54 request: &TransactionRequest,
55 ) -> ProtocolResult<ExecResp>;
56}
57
58pub trait Dispatcher {
60 fn read(&self, context: ServiceContext) -> ProtocolResult<ExecResp>;
61
62 fn write(&self, context: ServiceContext) -> ProtocolResult<ExecResp>;
63}
64
65pub struct NoopDispatcher;
66
67impl Dispatcher for NoopDispatcher {
68 fn read(&self, _context: ServiceContext) -> ProtocolResult<ExecResp> {
69 unimplemented!()
70 }
71
72 fn write(&self, _context: ServiceContext) -> ProtocolResult<ExecResp> {
73 unimplemented!()
74 }
75}