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
2 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#![allow(unreachable_code, unused_variables, clippy::diverging_sub_expression)] | ||
|
||
use std::{future::Future, pin::Pin}; | ||
|
||
use subspace_sdk::{ | ||
Farmer, FarmerBuilder, Network, Node, NodeBuilder, NodeMode, PlotDescription, RewardAddress, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut node: Node = NodeBuilder::new() | ||
.mode(NodeMode::Full) | ||
.network(Network::Gemini2a) | ||
.name("i1i1") | ||
.port(1337) | ||
.directory("node") | ||
.build() | ||
.await | ||
.expect("Failed to init a node"); | ||
|
||
node.sync().await; | ||
|
||
let reward_address: RewardAddress = todo!("Can't construct reward address right now :("); | ||
let mut farmer: Farmer = FarmerBuilder::new() | ||
.node(node.clone()) | ||
.plot(PlotDescription::new("plot", 10 * 1024 * 1024 * 1024)) | ||
.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() | ||
.await | ||
.expect("Failed to init a farmer"); | ||
|
||
farmer.sync().await; | ||
|
||
farmer | ||
.on_solution(|solution| { | ||
// Yeah very cumbersome, but rust can't coerce types here. | ||
// TODO: look into https://doc.rust-lang.org/stable/std/ops/trait.CoerceUnsized.html | ||
let fut: Pin<Box<dyn Future<Output = ()>>> = Box::pin(async move { | ||
eprintln!("Found solution: {solution:?}"); | ||
}); | ||
fut | ||
}) | ||
.await; | ||
node.on_block(|block| { | ||
let fut: Pin<Box<dyn Future<Output = ()>>> = Box::pin(async move { | ||
eprintln!("New block: {block:?}"); | ||
}); | ||
fut | ||
}) | ||
.await; | ||
|
||
farmer.start_farming().await; | ||
|
||
dbg!(node.get_info().await); | ||
dbg!(farmer.get_info().await); | ||
|
||
farmer.stop_farming().await; | ||
farmer.close().await; | ||
node.close().await; | ||
|
||
// Restarting | ||
let mut node = NodeBuilder::new() | ||
.mode(NodeMode::Full) | ||
.network(Network::Gemini2a) | ||
.directory("node") | ||
.build() | ||
.await | ||
.expect("Failed to init a node"); | ||
node.sync().await; | ||
|
||
let mut farmer = FarmerBuilder::new() | ||
.node(node.clone()) | ||
.plot(PlotDescription::new("plot", 10 * 1024 * 1024 * 1024)) | ||
.reward_address(reward_address) | ||
.build() | ||
.await | ||
.expect("Failed to init a farmer"); | ||
|
||
farmer.sync().await; | ||
farmer.start_farming().await; | ||
|
||
// Delete everything | ||
for plot in farmer.plots().await { | ||
plot.delete().await; | ||
} | ||
farmer.wipe().await; | ||
node.wipe().await; | ||
} |