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