linera_core/environment/
mod.rs1pub mod wallet;
8
9use linera_base::util::traits::AutoTraits;
10
11trait_set::trait_set! {
12 pub trait Network = crate::node::ValidatorNodeProvider + AutoTraits;
14 pub trait Signer = linera_base::crypto::Signer + AutoTraits;
16 pub trait Storage = linera_storage::Storage + Clone + AutoTraits;
18 pub trait Wallet = wallet::Wallet + AutoTraits;
20}
21
22pub trait Environment: AutoTraits {
24 type Storage: Storage<Context = Self::StorageContext>;
26 type Network: Network<Node = Self::ValidatorNode>;
28 type Signer: Signer;
30 type Wallet: Wallet;
32
33 type ValidatorNode: crate::node::ValidatorNode + AutoTraits + Clone;
35 type StorageContext: linera_views::context::Context<Extra: linera_execution::ExecutionRuntimeContext>
37 + AutoTraits;
38
39 fn storage(&self) -> &Self::Storage;
41 fn network(&self) -> &Self::Network;
43 fn signer(&self) -> &Self::Signer;
45 fn wallet(&self) -> &Self::Wallet;
47}
48
49pub struct Impl<
51 Storage,
52 Network,
53 Signer = linera_base::crypto::InMemorySigner,
54 Wallet = wallet::Memory,
55> {
56 pub storage: Storage,
58 pub network: Network,
60 pub signer: Signer,
62 pub wallet: Wallet,
64}
65
66impl<St: Storage, N: Network, Si: Signer, W: Wallet> Environment for Impl<St, N, Si, W> {
67 type Storage = St;
68 type Network = N;
69 type Signer = Si;
70 type Wallet = W;
71
72 type ValidatorNode = N::Node;
73 type StorageContext = St::Context;
74
75 fn storage(&self) -> &St {
76 &self.storage
77 }
78
79 fn network(&self) -> &N {
80 &self.network
81 }
82
83 fn signer(&self) -> &Si {
84 &self.signer
85 }
86
87 fn wallet(&self) -> &W {
88 &self.wallet
89 }
90}
91
92cfg_if::cfg_if! {
93 if #[cfg(with_testing)] {
94 pub type TestStorage = linera_storage::DbStorage<linera_views::memory::MemoryDatabase, linera_storage::TestClock>;
96 pub type TestNetwork = crate::test_utils::NodeProvider<TestStorage>;
98 pub type TestSigner = linera_base::crypto::InMemorySigner;
100 pub type TestWallet = crate::wallet::Memory;
102 pub type Test = Impl<TestStorage, TestNetwork, TestSigner, TestWallet>;
104 }
105}