/ node / src / traits.rs
traits.rs
 1  // Copyright (c) 2025 ADnet Contributors
 2  // This file is part of the AlphaOS library.
 3  
 4  // Licensed under the Apache License, Version 2.0 (the "License");
 5  // you may not use this file except in compliance with the License.
 6  // You may obtain a copy of the License at:
 7  
 8  // http://www.apache.org/licenses/LICENSE-2.0
 9  
10  // Unless required by applicable law or agreed to in writing, software
11  // distributed under the License is distributed on an "AS IS" BASIS,
12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  // See the License for the specific language governing permissions and
14  // limitations under the License.
15  
16  use alphaos_node_network::{NodeType, PeerPoolHandling};
17  use alphaos_node_router::Routing;
18  
19  use alphaos_utilities::SignalHandler;
20  
21  use alphavm::prelude::{Address, Network, PrivateKey, ViewKey};
22  
23  #[async_trait]
24  pub trait NodeInterface<N: Network>: Routing<N> {
25      /// Returns the node type.
26      fn node_type(&self) -> NodeType {
27          self.router().node_type()
28      }
29  
30      /// Returns the account private key of the node.
31      fn private_key(&self) -> &PrivateKey<N> {
32          self.router().private_key()
33      }
34  
35      /// Returns the account view key of the node.
36      fn view_key(&self) -> &ViewKey<N> {
37          self.router().view_key()
38      }
39  
40      /// Returns the account address of the node.
41      fn address(&self) -> Address<N> {
42          self.router().address()
43      }
44  
45      /// Returns `true` if the node is in development mode.
46      fn is_dev(&self) -> bool {
47          self.router().is_dev()
48      }
49  
50      /// Blocks until a shutdown signal was received or manual shutdown was triggered.
51      async fn wait_for_signals(&self, handler: &SignalHandler) {
52          handler.wait_for_signals().await;
53  
54          // If the node is already initialized, then shut it down.
55          self.shut_down().await;
56      }
57  
58      /// Shuts down the node.
59      async fn shut_down(&self);
60  }