This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
260 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use std::{net::SocketAddr, path::PathBuf}; | ||
|
||
use libp2p_core::multiaddr::Multiaddr; | ||
|
||
use crate::{AsyncFn, Node, RewardAddress}; | ||
|
||
// TODO: Should it be non-exhaustive? | ||
pub struct PlotDescription { | ||
pub directory: PathBuf, | ||
pub space_pledged: u64, | ||
} | ||
|
||
impl PlotDescription { | ||
// TODO: should we check that plot is valid at this stage? | ||
// Or it can be literally a description of a plot | ||
pub fn new(directory: impl Into<PathBuf>, space_pledged: u64) -> Self { | ||
Self { | ||
directory: directory.into(), | ||
space_pledged, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Builder { | ||
reward_address: Option<RewardAddress>, | ||
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: RewardAddress) -> 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 | ||
} | ||
|
||
pub fn ws_rpc(mut self, ws_rpc: SocketAddr) -> Self { | ||
self.ws_rpc = Some(ws_rpc); | ||
self | ||
} | ||
|
||
/// It supposed to open node at the supplied location | ||
pub async fn build(self) -> Result<Farmer, ()> { | ||
todo!() | ||
} | ||
} | ||
|
||
pub struct Farmer { | ||
_ensure_cant_construct: (), | ||
} | ||
|
||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub struct Info { | ||
pub version: String, | ||
pub reward_address: RewardAddress, | ||
pub dsn_peers: u64, | ||
pub space_pledged: u64, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Solution { | ||
_ensure_cant_construct: (), | ||
} | ||
|
||
pub struct Plot { | ||
_ensure_cant_construct: (), | ||
} | ||
|
||
impl Plot { | ||
pub async fn delete(&mut self) {} | ||
} | ||
|
||
impl Farmer { | ||
pub async fn sync(&mut self) {} | ||
|
||
pub async fn start_farming(&mut self) {} | ||
|
||
pub async fn stop_farming(&mut self) {} | ||
|
||
pub async fn get_info(&mut self) -> Info { | ||
todo!() | ||
} | ||
|
||
pub async fn on_solution(&mut self, on_solution: impl AsyncFn<Solution, ()>) { | ||
let _ = on_solution; | ||
} | ||
|
||
pub async fn plots(&mut self) -> &mut [Plot] { | ||
todo!() | ||
} | ||
|
||
// Stops farming, closes plots, and sends signal to the node | ||
pub async fn close(self) {} | ||
|
||
// Runs `.close()` and also wipes farmer's state | ||
pub async fn wipe(self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
#![feature(trait_alias)] | ||
|
||
pub mod farmer; | ||
pub mod node; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
pub use farmer::{ | ||
Builder as FarmerBuilder, Farmer, Info as NodeInfo, Plot, PlotDescription, Solution, | ||
}; | ||
pub use node::{Builder as NodeBuilder, Info as FarmerInfo, Mode as NodeMode, Network, Node}; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
#[derive(Default)] | ||
#[non_exhaustive] | ||
enum Directory { | ||
#[default] | ||
Default, | ||
Tmp, | ||
Custom(std::path::PathBuf), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct RewardAddress { | ||
// TODO: Put proper type | ||
_ensure_cant_construct: (), | ||
} | ||
|
||
pub trait AsyncFn<Input, Output> = | ||
Fn(Input) -> std::pin::Pin<Box<dyn std::future::Future<Output = Output>>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use std::path::PathBuf; | ||
|
||
use crate::{AsyncFn, Directory}; | ||
|
||
#[non_exhaustive] | ||
#[derive(Debug, Default)] | ||
pub enum Mode { | ||
#[default] | ||
Full, | ||
} | ||
|
||
#[non_exhaustive] | ||
#[derive(Debug, Default)] | ||
pub enum Network { | ||
#[default] | ||
Gemini2a, | ||
// TODO: put proper type here | ||
Custom(std::convert::Infallible), | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Builder { | ||
mode: Mode, | ||
network: Network, | ||
name: Option<String>, | ||
directory: Directory, | ||
port: u16, | ||
} | ||
|
||
impl Builder { | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
pub fn mode(mut self, ty: Mode) -> Self { | ||
self.mode = ty; | ||
self | ||
} | ||
|
||
pub fn network(mut self, network: Network) -> Self { | ||
self.network = network; | ||
self | ||
} | ||
|
||
pub fn name(mut self, name: impl AsRef<str>) -> Self { | ||
if !name.as_ref().is_empty() { | ||
self.name = Some(name.as_ref().to_owned()); | ||
} | ||
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, ()> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Node { | ||
_ensure_cant_construct: (), | ||
} | ||
|
||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub struct Info { | ||
pub version: String, | ||
pub network: Network, | ||
pub mode: Mode, | ||
pub name: Option<String>, | ||
pub connected_peers: u64, | ||
pub best_block: u64, | ||
pub total_space_pledged: u64, | ||
pub total_history_size: u64, | ||
pub space_pledged: u64, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Block { | ||
_ensure_cant_construct: (), | ||
} | ||
|
||
impl Node { | ||
pub async fn sync(&mut self) {} | ||
|
||
// Leaves the network and gracefully shuts down | ||
pub async fn close(self) {} | ||
|
||
// Runs `.close()` and also wipes node's state | ||
pub async fn wipe(self) {} | ||
|
||
pub async fn get_info(&mut self) -> Info { | ||
todo!() | ||
} | ||
|
||
pub async fn on_block(&mut self, callback: impl AsyncFn<Block, ()>) { | ||
let _ = callback; | ||
} | ||
} |