linera_core/
environment.rs1#[cfg(web)]
5pub trait AutoTraits: 'static {}
6#[cfg(web)]
7impl<T: 'static> AutoTraits for T {}
8
9#[cfg(not(web))]
10trait_set::trait_set! {
11 pub trait AutoTraits = Send + Sync + 'static;
12}
13
14trait_set::trait_set! {
15 pub trait Network = crate::node::ValidatorNodeProvider + AutoTraits;
16 pub trait Signer = linera_base::crypto::Signer + AutoTraits;
17 pub trait Storage = linera_storage::Storage + Clone + Send + Sync + 'static;
18}
19
20pub trait Environment: AutoTraits {
21 type Storage: Storage<Context = Self::StorageContext>;
22 type Network: Network<Node = Self::ValidatorNode>;
23 type Signer: Signer;
24 type ValidatorNode: crate::node::ValidatorNode + AutoTraits + Clone;
25 type StorageContext: linera_views::context::Context<Extra: linera_execution::ExecutionRuntimeContext>
26 + Send
27 + Sync
28 + 'static;
29
30 fn storage(&self) -> &Self::Storage;
31 fn network(&self) -> &Self::Network;
32 fn signer(&self) -> &Self::Signer;
33}
34
35pub struct Impl<Storage, Network, Signer> {
36 pub storage: Storage,
37 pub network: Network,
38 pub signer: Signer,
39}
40
41impl<St: Storage, N: Network, Si: Signer> Environment for Impl<St, N, Si> {
42 type Storage = St;
43 type Network = N;
44 type Signer = Si;
45 type ValidatorNode = N::Node;
46 type StorageContext = St::Context;
47
48 fn storage(&self) -> &St {
49 &self.storage
50 }
51
52 fn network(&self) -> &N {
53 &self.network
54 }
55
56 fn signer(&self) -> &Si {
57 &self.signer
58 }
59}
60
61cfg_if::cfg_if! {
62 if #[cfg(with_testing)] {
63 pub type TestStorage = linera_storage::DbStorage<linera_views::memory::MemoryStore, linera_storage::TestClock>;
64 pub type TestNetwork = crate::test_utils::NodeProvider<TestStorage>;
65 pub type TestSigner = linera_base::crypto::InMemorySigner;
66 pub type Test = Impl<TestStorage, TestNetwork, TestSigner>;
67 }
68}