Skip to content

Commit

Permalink
refactor: new node module
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan committed Jun 13, 2020
1 parent c27266e commit 08e5bc7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
16 changes: 0 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,11 @@
extern crate log;
use colored::*;

// color values for pretty console output
const PROMINENT_COLOR: &str = "cyan";
const MSG_COLOR: &str = "yellow";
const ERR_COLOR: &str = "red";
const PROMPT_COLOR: &str = "blue";

// list all modules
mod blockchain;
mod command;
mod message;
mod node;
mod peer;
mod utils;

// bring some inner components out for convenience
use blockchain::{Block, Blockchain, Transaction};
use command::Command;
use message::{Request, Response};
use node::Event;
pub use node::Node; // make it public for main.rs
use peer::PeerInfo;
use utils::*;

pub type Result<T> = std::result::Result<T, failure::Error>;
2 changes: 1 addition & 1 deletion src/command.rs → src/node/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::*;
use super::*;
use colored::Colorize;
use std::io::{stdin, stdout, Write};
use std::sync::mpsc::Sender;
Expand Down
2 changes: 1 addition & 1 deletion src/message.rs → src/node/message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::*;
use super::*;
use serde::{Deserialize, Serialize};
use serde_json::Deserializer;
use std::net::TcpListener;
Expand Down
21 changes: 21 additions & 0 deletions src/node/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mod command;
mod message;
mod node;
mod peer;
mod utils;

// color values for pretty console output
const PROMINENT_COLOR: &str = "cyan";
const MSG_COLOR: &str = "yellow";
const ERR_COLOR: &str = "red";
const PROMPT_COLOR: &str = "blue";

// bring some inner components out for convenience
use crate::*;
use command::Command;
use message::{Request, Response};
use node::Event;
use peer::PeerInfo;
use utils::*;

pub use node::Node;
2 changes: 1 addition & 1 deletion src/node.rs → src/node/node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The blockchain node
use crate::*;
use super::*;
use serde_json::Deserializer;
use std::collections::HashSet;
use std::io::{stdout, Write};
Expand Down
2 changes: 1 addition & 1 deletion src/peer.rs → src/node/peer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::*;
use super::*;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use uuid::Uuid;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs → src/node/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::*;
use super::*;
use std::net::{SocketAddr, ToSocketAddrs};

pub fn parse_addr(addr: String) -> Result<SocketAddr> {
Expand Down

0 comments on commit 08e5bc7

Please sign in to comment.