diff --git a/examples/simple.rs b/examples/simple.rs index ec18b5af..440b6076 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -8,8 +8,7 @@ async fn main() { .network(Network::Gemini2a) .name("i1i1") .port(1337) - .directory("node") - .build() + .build("node") .await .expect("Failed to init a node"); @@ -17,12 +16,13 @@ async fn main() { 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"); @@ -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"); diff --git a/src/farmer.rs b/src/farmer.rs index 47bf8c33..8f53a05c 100644 --- a/src/farmer.rs +++ b/src/farmer.rs @@ -35,12 +35,8 @@ impl PlotDescription { #[derive(Default)] pub struct Builder { - reward_address: Option, - node: Option, listen_on: Option, ws_rpc: Option, - // TODO: Should we just require a single plot? - plots: Vec, } impl Builder { @@ -48,21 +44,6 @@ impl Builder { 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 @@ -74,7 +55,14 @@ impl Builder { } /// It supposed to open node at the supplied location - pub async fn build(self) -> Result { + // TODO: Should we just require multiple plots? + pub async fn build( + self, + reward_address: PublicKey, + node: Node, + plot: PlotDescription, + ) -> Result { + let _ = (reward_address, node, plot); todo!() } } diff --git a/src/lib.rs b/src/lib.rs index 761f1ebc..e5bfd7c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, }; @@ -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> From

for Directory { + fn from(path: P) -> Self { + Self::Custom(path.into()) + } } diff --git a/src/node.rs b/src/node.rs index bee30473..9ebb0814 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - use crate::Directory; #[non_exhaustive] @@ -23,7 +21,6 @@ pub struct Builder { mode: Mode, network: Network, name: Option, - directory: Directory, port: u16, } @@ -49,23 +46,14 @@ impl Builder { self } - pub fn directory(mut self, path: impl Into) -> 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 { + pub async fn build(self, directory: impl Into) -> Result { + let _ = directory; todo!() } }