Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Require currently required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
i1i1 committed Oct 6, 2022
1 parent 81ac516 commit 44ea07a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
24 changes: 12 additions & 12 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ async fn main() {
.network(Network::Gemini2a)
.name("i1i1")
.port(1337)
.directory("node")
.build()
.build("node")
.await
.expect("Failed to init a node");

node.sync().await;

let reward_address = PublicKey::from([0; 32]);
let mut farmer: Farmer = Farmer::builder()
.node(node.clone())
.plot(PlotDescription::new("plot", ByteSize::gb(10)))
.ws_rpc("127.0.0.1:9955".parse().unwrap())
.listen_on("/ip4/0.0.0.0/tcp/40333".parse().unwrap())
.reward_address(reward_address)
.build()
.build(
reward_address,
node.clone(),
PlotDescription::new("plot", ByteSize::gb(10)),
)
.await
.expect("Failed to init a farmer");

Expand Down Expand Up @@ -51,17 +51,17 @@ async fn main() {
let mut node = Node::builder()
.mode(NodeMode::Full)
.network(Network::Gemini2a)
.directory("node")
.build()
.build("node")
.await
.expect("Failed to init a node");
node.sync().await;

let mut farmer = Farmer::builder()
.node(node.clone())
.plot(PlotDescription::new("plot", ByteSize::gb(10)))
.reward_address(reward_address)
.build()
.build(
reward_address,
node.clone(),
PlotDescription::new("plot", ByteSize::gb(10)),
)
.await
.expect("Failed to init a farmer");

Expand Down
28 changes: 8 additions & 20 deletions src/farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,15 @@ impl PlotDescription {

#[derive(Default)]
pub struct Builder {
reward_address: Option<PublicKey>,
node: Option<Node>,
listen_on: Option<Multiaddr>,
ws_rpc: Option<SocketAddr>,
// TODO: Should we just require a single plot?
plots: Vec<PlotDescription>,
}

impl Builder {
pub fn new() -> Self {
Self::default()
}

pub fn node(mut self, node: Node) -> Self {
self.node = Some(node);
self
}

pub fn reward_address(mut self, reward_address: PublicKey) -> Self {
self.reward_address = Some(reward_address);
self
}

pub fn plot(mut self, plot: PlotDescription) -> Self {
self.plots.push(plot);
self
}

pub fn listen_on(mut self, multiaddr: Multiaddr) -> Self {
self.listen_on = Some(multiaddr);
self
Expand All @@ -74,7 +55,14 @@ impl Builder {
}

/// It supposed to open node at the supplied location
pub async fn build(self) -> Result<Farmer, ()> {
// TODO: Should we just require multiple plots?
pub async fn build(
self,
reward_address: PublicKey,
node: Node,
plot: PlotDescription,
) -> Result<Farmer, ()> {
let _ = (reward_address, node, plot);
todo!()
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod farmer;
pub mod node;

use std::path::PathBuf;

pub use farmer::{
Builder as FarmerBuilder, Farmer, Info as NodeInfo, Plot, PlotDescription, Solution,
};
Expand All @@ -9,9 +11,15 @@ pub use subspace_core_primitives::PublicKey;

#[derive(Default)]
#[non_exhaustive]
enum Directory {
pub enum Directory {
#[default]
Default,
Tmp,
Custom(std::path::PathBuf),
Custom(PathBuf),
}

impl<P: Into<PathBuf>> From<P> for Directory {
fn from(path: P) -> Self {
Self::Custom(path.into())
}
}
16 changes: 2 additions & 14 deletions src/node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use crate::Directory;

#[non_exhaustive]
Expand All @@ -23,7 +21,6 @@ pub struct Builder {
mode: Mode,
network: Network,
name: Option<String>,
directory: Directory,
port: u16,
}

Expand All @@ -49,23 +46,14 @@ impl Builder {
self
}

pub fn directory(mut self, path: impl Into<PathBuf>) -> Self {
self.directory = Directory::Custom(path.into());
self
}

pub fn tmp_directory(mut self) -> Self {
self.directory = Directory::Tmp;
self
}

pub fn port(mut self, port: u16) -> Self {
self.port = port;
self
}

/// It supposed to open node at the supplied location
pub async fn build(self) -> Result<Node, ()> {
pub async fn build(self, directory: impl Into<Directory>) -> Result<Node, ()> {
let _ = directory;
todo!()
}
}
Expand Down

0 comments on commit 44ea07a

Please sign in to comment.