/ node / network / src / node_type.rs
node_type.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 alphavm::prelude::{error, FromBytes, ToBytes};
20  
21  use serde::{Deserialize, Serialize};
22  use std::io;
23  
24  #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
25  #[repr(u8)]
26  pub enum NodeType {
27      /// A client node is a full node, capable of syncing with the network.
28      Client = 0,
29      /// A prover is a light node, capable of producing proofs for consensus.
30      Prover,
31      /// A validator is a full node, capable of validating blocks.
32      Validator,
33      /// A bootstrapclient is a light node dedicated to serving peer lists.
34      BootstrapClient,
35  }
36  
37  impl NodeType {
38      /// Returns a string representation of the node type.
39      pub const fn description(&self) -> &str {
40          match self {
41              Self::Client => "a client node",
42              Self::Prover => "a prover node",
43              Self::Validator => "a validator node",
44              Self::BootstrapClient => "a bootstrap client node",
45          }
46      }
47  
48      /// Returns `true` if the node type is a client.
49      pub const fn is_client(&self) -> bool {
50          matches!(self, Self::Client)
51      }
52  
53      /// Returns `true` if the node type is a prover.
54      pub const fn is_prover(&self) -> bool {
55          matches!(self, Self::Prover)
56      }
57  
58      /// Returns `true` if the node type is a validator.
59      pub const fn is_validator(&self) -> bool {
60          matches!(self, Self::Validator)
61      }
62  }
63  
64  impl core::fmt::Display for NodeType {
65      fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66          write!(f, "{}", match self {
67              Self::Client => "Client",
68              Self::Prover => "Prover",
69              Self::Validator => "Validator",
70              Self::BootstrapClient => "Bootstrap Client",
71          })
72      }
73  }
74  
75  impl ToBytes for NodeType {
76      fn write_le<W: io::Write>(&self, writer: W) -> io::Result<()> {
77          (*self as u8).write_le(writer)
78      }
79  }
80  
81  impl FromBytes for NodeType {
82      fn read_le<R: io::Read>(reader: R) -> io::Result<Self> {
83          match u8::read_le(reader)? {
84              0 => Ok(Self::Client),
85              1 => Ok(Self::Prover),
86              2 => Ok(Self::Validator),
87              3 => Ok(Self::BootstrapClient),
88              x => Err(error(format!("Invalid node type: expected 0..=3, got {x}."))),
89          }
90      }
91  }