Skip to content

Commit

Permalink
Integrate modules
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Aug 19, 2022
1 parent e85c7c4 commit a5afe9c
Show file tree
Hide file tree
Showing 30 changed files with 306 additions and 1,618 deletions.
824 changes: 156 additions & 668 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ categories = [ "cryptography", "operating-systems" ]
license = "GPL-3.0"
edition = "2021"

[workspace]
members = [ "environment" ]

[lib]
path = "snarkos/lib.rs"

[[bin]]
name = "main"
path = "src/main.rs"
name = "snarkos"
path = "snarkos/main.rs"

#[[bin]]
#name = "main"
#path = "src/main.rs"

[dependencies]
backoff = { version = "0.4", features = ["tokio"] }
Expand Down Expand Up @@ -96,6 +106,9 @@ version = "1"
[dependencies.serde_json]
version = "1"

[dependencies.thiserror]
version = "1.0"

[dependencies.tokio]
version = "1"
features = [ "full" ]
Expand Down
5 changes: 2 additions & 3 deletions environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ version = "1"
version = "1"

[dependencies.snarkvm]
path = "../../snarkVM"
#git = "https://github.com/AleoHQ/snarkVM.git"
#branch = "testnet3"
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "7555dc0"
features = ["console", "utilities"]

[dependencies.tokio]
Expand Down
6 changes: 3 additions & 3 deletions environment/src/helpers/node_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ use std::fmt;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[repr(u8)]
pub enum NodeType {
/// A client node is a full node, capable of sending and receiving blocks.
/// A client node is a full node, capable of syncing with the network.
Client = 0,
/// A prover is a full node, capable of producing proofs for consensus.
Prover,
/// A validator is a full node, capable of producing blocks with provers.
/// A validator is a full node, capable of validating blocks.
Validator,
/// A beacon is a discovery node, capable of syncing nodes on the network.
/// A beacon is a full node, capable of producing blocks.
Beacon,
}

Expand Down
10 changes: 10 additions & 0 deletions src/account.rs → snarkos/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ impl<N: Network> Account<N> {
signature.verify(&self.address, message)
}

/// Returns the account private key.
pub const fn private_key(&self) -> &PrivateKey<N> {
&self.private_key
}

/// Returns the account view key.
pub const fn view_key(&self) -> &ViewKey<N> {
&self.view_key
}

/// Returns the account address.
pub const fn address(&self) -> &Address<N> {
&self.address
Expand Down
50 changes: 20 additions & 30 deletions snarkos/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.

use crate::{display::Display, Node, Updater};
use snarkos_consensus::account::Account;
use crate::{Account, Node, Updater};
use snarkos_environment::{helpers::NodeType, Beacon, Client, Environment, Prover, Validator};
// use snarkos_storage::storage::{rocksdb::RocksDB, ReadOnly};
use snarkvm::prelude::{Address, Network, PrivateKey, ViewKey};
Expand Down Expand Up @@ -69,9 +68,6 @@ pub struct CLI {
/// Enables development mode, specify a unique ID for the local node.
#[clap(long)]
pub dev: Option<u16>,
/// If the flag is set, the node will render a read-only display.
#[clap(long)]
pub display: bool,

/// Specify an optional subcommand.
#[clap(subcommand)]
Expand All @@ -92,9 +88,9 @@ impl CLI {
}
None => match (self.network, self.node_type()?) {
(3, NodeType::Client) => self.start_node::<Testnet3, Client<Testnet3>>(&None).await,
(3, NodeType::Prover) => self.start_node::<Testnet3, Prover<Testnet3>>(&self.prover).await,
(3, NodeType::Validator) => self.start_node::<Testnet3, Validator<Testnet3>>(&self.validator).await,
(3, NodeType::Beacon) => self.start_node::<Testnet3, Beacon<Testnet3>>(&None).await,
(3, NodeType::Prover) => bail!("Provers will be available in Phase 2"),
(3, NodeType::Validator) => bail!("Validators will be available in Phase 3"),
(3, NodeType::Beacon) => bail!("Beacons will be available in Phase 3"),
_ => bail!("Unsupported network"),
},
}
Expand Down Expand Up @@ -137,7 +133,7 @@ impl CLI {
};

// Print the welcome.
println!("{}", crate::display::welcome_message());
println!("{}", crate::logger::welcome_message());
// Print the Aleo address.
println!("Your Aleo address is {}.\n", account.address());
// Print the node type and network.
Expand All @@ -149,27 +145,21 @@ impl CLI {
// Initialize signal handling and maintain ownership of the node - to keep it in scope.
Self::handle_signals(node.clone());

// Initialize the display, if enabled.
if self.display {
println!("\nThe snarkOS console is initializing...\n");
Display::<N, E>::start(node.clone(), self.verbosity)?;
};

// Connect to peer(s) if given as an argument.
if let Some(peer_ips) = &self.connect {
// Separate the IP addresses.
for peer_ip in peer_ips.split(',') {
// Parse each IP address.
node.connect_to(match peer_ip.parse() {
Ok(ip) => ip,
Err(e) => {
error!("The IP supplied to --connect ('{peer_ip}') is malformed: {e}");
continue;
}
})
.await?;
}
}
// // Connect to peer(s) if given as an argument.
// if let Some(peer_ips) = &self.connect {
// // Separate the IP addresses.
// for peer_ip in peer_ips.split(',') {
// // Parse each IP address.
// node.connect_to(match peer_ip.parse() {
// Ok(ip) => ip,
// Err(e) => {
// error!("The IP supplied to --connect ('{peer_ip}') is malformed: {e}");
// continue;
// }
// })
// .await?;
// }
// }

// Note: Do not move this. The pending await must be here otherwise
// other snarkOS commands will not exit.
Expand Down
188 changes: 0 additions & 188 deletions snarkos/display/console.rs

This file was deleted.

Loading

0 comments on commit a5afe9c

Please sign in to comment.