Skip to content

Commit

Permalink
Move Node struct from network to types mod
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Oct 24, 2024
1 parent c2542c6 commit 6d9dfad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 60 deletions.
5 changes: 1 addition & 4 deletions core/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
network::rpc::Node as RpcNode,
types::{BlockRange, Uuid},
};
use crate::types::{BlockRange, Node as RpcNode, Uuid};
use avail_rust::{sp_core::ed25519, AvailHeader};
use codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
Expand Down
63 changes: 9 additions & 54 deletions core/src/network/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ use avail_rust::{
sp_core::bytes::from_hex,
AvailHeader, H256,
};
use codec::{Decode, Encode};
use codec::Decode;
use color_eyre::{eyre::eyre, Result};
use configuration::RPCConfig;
use rand::{seq::SliceRandom, thread_rng, Rng};
use serde::{de, Deserialize, Serialize};
use std::{collections::HashSet, fmt::Display};
use serde::{de, Deserialize};
use std::collections::HashSet;
use tokio::{
sync::broadcast,
time::{self, timeout},
};
use tracing::{debug, info};

use crate::{data::Database, network::rpc, shutdown::Controller, types::GrandpaJustification};
use crate::{
data::Database,
network::rpc,
shutdown::Controller,
types::{GrandpaJustification, Node},
};

mod client;
pub mod configuration;
Expand Down Expand Up @@ -69,56 +74,6 @@ impl<'de> Deserialize<'de> for WrappedProof {
}
}

#[derive(Clone, Debug, Serialize, Deserialize, Decode, Encode)]
pub struct Node {
pub host: String,
pub system_version: String,
pub spec_version: u32,
pub genesis_hash: H256,
}

impl Node {
pub fn new(
host: String,
system_version: String,
spec_version: u32,
genesis_hash: H256,
) -> Self {
Self {
host,
system_version,
spec_version,
genesis_hash,
}
}

pub fn network(&self) -> String {
format!(
"{host}/{system_version}/{spec_version}",
host = self.host,
system_version = self.system_version,
spec_version = self.spec_version,
)
}
}

impl Default for Node {
fn default() -> Self {
Self {
host: "{host}".to_string(),
system_version: "{system_version}".to_string(),
spec_version: 0,
genesis_hash: Default::default(),
}
}
}

impl Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "v{}", self.system_version)
}
}

#[derive(Clone)]
pub struct Nodes {
list: Vec<Node>,
Expand Down
4 changes: 2 additions & 2 deletions core/src/network/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ use tokio_retry::Retry;
use tokio_stream::StreamExt;
use tracing::{debug, error, info, trace, warn};

use super::{configuration::RetryConfig, Node, Nodes, Subscription, WrappedProof};
use super::{configuration::RetryConfig, Nodes, Subscription, WrappedProof};
use crate::{
data::{Database, RpcNodeKey, SignerNonceKey},
shutdown::Controller,
types::{Base64, DEV_FLAG_GENHASH},
types::{Base64, Node, DEV_FLAG_GENHASH},
};

#[derive(Debug, thiserror::Error)]
Expand Down
49 changes: 49 additions & 0 deletions core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,52 @@ impl From<Base64> for String {
general_purpose::STANDARD.encode(value.0)
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Decode, Encode)]
pub struct Node {
pub host: String,
pub system_version: String,
pub spec_version: u32,
pub genesis_hash: H256,
}

impl Node {
pub fn new(
host: String,
system_version: String,
spec_version: u32,
genesis_hash: H256,
) -> Self {
Self {
host,
system_version,
spec_version,
genesis_hash,
}
}

pub fn network(&self) -> String {
format!(
"{host}/{system_version}/{spec_version}",
host = self.host,
system_version = self.system_version,
spec_version = self.spec_version,
)
}
}

impl Default for Node {
fn default() -> Self {
Self {
host: "{host}".to_string(),
system_version: "{system_version}".to_string(),
spec_version: 0,
genesis_hash: Default::default(),
}
}
}

impl Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "v{}", self.system_version)
}
}

0 comments on commit 6d9dfad

Please sign in to comment.