/ node / src / traits.rs
traits.rs
 1  // Copyright (c) 2025-2026 ACDC Network
 2  // This file is part of the alphaos library.
 3  //
 4  // Alpha Chain | Delta Chain Protocol
 5  // International Monetary Graphite.
 6  //
 7  // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com).
 8  // They built world-class ZK infrastructure. We installed the EASY button.
 9  // Their cryptography: elegant. Our modifications: bureaucracy-compatible.
10  // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours.
11  //
12  // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
13  // All modifications and new work: CC0 1.0 Universal Public Domain Dedication.
14  // No rights reserved. No permission required. No warranty. No refunds.
15  //
16  // https://creativecommons.org/publicdomain/zero/1.0/
17  // SPDX-License-Identifier: CC0-1.0
18  
19  use alphaos_node_network::{NodeType, PeerPoolHandling};
20  use alphaos_node_router::Routing;
21  
22  use alphaos_utilities::SignalHandler;
23  
24  use alphavm::prelude::{Address, Network, PrivateKey, ViewKey};
25  
26  #[async_trait]
27  pub trait NodeInterface<N: Network>: Routing<N> {
28      /// Returns the node type.
29      fn node_type(&self) -> NodeType {
30          self.router().node_type()
31      }
32  
33      /// Returns the account private key of the node.
34      fn private_key(&self) -> &PrivateKey<N> {
35          self.router().private_key()
36      }
37  
38      /// Returns the account view key of the node.
39      fn view_key(&self) -> &ViewKey<N> {
40          self.router().view_key()
41      }
42  
43      /// Returns the account address of the node.
44      fn address(&self) -> Address<N> {
45          self.router().address()
46      }
47  
48      /// Returns `true` if the node is in development mode.
49      fn is_dev(&self) -> bool {
50          self.router().is_dev()
51      }
52  
53      /// Blocks until a shutdown signal was received or manual shutdown was triggered.
54      async fn wait_for_signals(&self, handler: &SignalHandler) {
55          handler.wait_for_signals().await;
56  
57          // If the node is already initialized, then shut it down.
58          self.shut_down().await;
59      }
60  
61      /// Shuts down the node.
62      async fn shut_down(&self);
63  }