use bitflags::bitflags;
use multiaddr::Multiaddr;
use nimiq_serde::{Deserialize, Serialize};
bitflags! {
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct Services: u32 {
const FULL_BLOCKS = 1 << 0;
const HISTORY = 1 << 1;
const ACCOUNTS_PROOF = 1 << 3;
const ACCOUNTS_CHUNKS = 1 << 4;
const MEMPOOL = 1 << 5;
const TRANSACTION_INDEX = 1 << 6;
const VALIDATOR = 1 << 7;
const PRE_GENESIS_TRANSACTIONS = 1 << 8;
}
}
pub enum NodeType {
History,
Light,
Full,
Pico,
}
impl Services {
pub fn provided(node_type: NodeType) -> Self {
match node_type {
NodeType::History => {
Services::HISTORY
| Services::FULL_BLOCKS
| Services::ACCOUNTS_PROOF
| Services::ACCOUNTS_CHUNKS
}
NodeType::Light => Services::empty(),
NodeType::Full => {
Services::ACCOUNTS_PROOF | Services::FULL_BLOCKS | Services::ACCOUNTS_CHUNKS
}
NodeType::Pico => Services::empty(),
}
}
pub fn required(node_type: NodeType) -> Self {
match node_type {
NodeType::History => Services::HISTORY | Services::FULL_BLOCKS,
NodeType::Light => Services::ACCOUNTS_PROOF,
NodeType::Full => Services::FULL_BLOCKS | Services::HISTORY | Services::ACCOUNTS_CHUNKS,
NodeType::Pico => Services::ACCOUNTS_PROOF,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct PeerInfo {
address: Multiaddr,
services: Services,
}
impl PeerInfo {
pub fn new(address: Multiaddr, services: Services) -> Self {
Self { address, services }
}
pub fn get_address(&self) -> Multiaddr {
self.address.clone()
}
pub fn get_services(&self) -> Services {
self.services
}
}