cold_io/state.rs
1// Copyright 2021 Vladislav Melnik
2// SPDX-License-Identifier: MIT
3
4use super::{
5 proposal::{Proposal, ReadOnce, WriteOnce},
6 request::Request,
7};
8
9/// The deterministic state machine.
10/// It accepts proposals from network and issues requests.
11/// All business logic should be implemented inside.
12pub trait State<R, W>
13where
14 R: ReadOnce,
15 W: WriteOnce,
16{
17 /// Some user defined inputs to the state machine
18 type Ext;
19
20 /// Randomness needed by the state machine
21 type Rng;
22
23 /// In order to preserve determinism, it should be the only input to the state machine.
24 fn accept(&mut self, proposal: Proposal<R, W, Self::Ext, Self::Rng>) -> Request;
25}