Skip to content

Commit

Permalink
Merge pull request #11 from felixbrucker/add-join-pool
Browse files Browse the repository at this point in the history
Add join pool command
  • Loading branch information
DaOneLuna authored Feb 14, 2024
2 parents 995afdf + ca6a914 commit e8c3f8e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
47 changes: 46 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::farmer::config::{BladebitHarvesterConfig, Config, FarmingInfo, PoolWalletConfig};
use clap::{Parser, Subcommand};
use dg_xch_cli::wallet_commands::migrate_plot_nft;
use dg_xch_cli::wallets::plotnft_utils::{get_plotnft_by_launcher_id, scrounge_for_plotnfts};
use dg_xch_clients::rpc::full_node::FullnodeClient;
use dg_xch_core::blockchain::sized_bytes::Bytes48;
use dg_xch_core::blockchain::sized_bytes::{Bytes32, Bytes48};
use dg_xch_core::consensus::constants::CONSENSUS_CONSTANTS_MAP;
use dg_xch_keys::{
key_from_mnemonic, master_sk_to_farmer_sk, master_sk_to_pool_sk,
Expand Down Expand Up @@ -51,6 +52,16 @@ pub enum Action {
plot_directories: Option<Vec<String>>,
},
UpdatePoolInfo {},
JoinPool {
#[arg(short = 'u', long)]
pool_url: String,
#[arg(short = 'm', long)]
mnemonic: String,
#[arg(short = 'i', long)]
launcher_id: Option<String>,
#[arg(short = 'f', long)]
fee: Option<u64>,
},
}
impl Default for Action {
fn default() -> Self {
Expand Down Expand Up @@ -267,3 +278,37 @@ pub async fn update_pool_info(config: Config) -> Result<Config, Error> {

Ok(updated_config)
}

pub async fn join_pool(
config: Config,
pool_url: String,
mnemonic: String,
launcher_id: Option<String>,
fee: Option<u64>,
) -> Result<Config, Error> {
let launcher_id_bytes: Option<Bytes32> = launcher_id.map(|l| l.into());
let client = FullnodeClient::new(
&config.fullnode_rpc_host,
config.fullnode_rpc_port,
config.ssl_root_path.clone(),
&None,
);
for farmer_info in &config.farmer_info {
let launcher_id = farmer_info.launcher_id.unwrap();
if let Some(selected_launcher_id) = launcher_id_bytes {
if selected_launcher_id != launcher_id {
continue;
}
}
migrate_plot_nft(
&client,
&pool_url,
&launcher_id,
&mnemonic,
fee.unwrap_or_default(),
)
.await?;
}

update_pool_info(config).await
}
29 changes: 28 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::cli::{generate_config_from_mnemonic, update_pool_info, Action, Cli, GenerateConfig};
use crate::cli::{
generate_config_from_mnemonic, join_pool, update_pool_info, Action, Cli, GenerateConfig,
};
use crate::farmer::config::{load_keys, Config};
use crate::farmer::{Farmer, FarmerSharedState};
use crate::tasks::pool_state_updater::pool_updater;
Expand Down Expand Up @@ -210,6 +212,31 @@ async fn main() -> Result<(), Error> {
let updated_config = update_pool_info(config).await?;
updated_config.save_as_yaml(config_path)?;

Ok(())
}
Action::JoinPool {
pool_url,
mnemonic,
launcher_id,
fee,
} => {
if !config_path.exists() {
eprintln!(
"Failed to find config at {:?}, please run init",
config_path
);
return Ok(());
}
SimpleLogger::new()
.with_colors(true)
.with_level(LevelFilter::Info)
.env()
.init()
.unwrap_or_default();
let config = Config::try_from(&config_path).unwrap_or_default();
let updated_config = join_pool(config, pool_url, mnemonic, launcher_id, fee).await?;
updated_config.save_as_yaml(config_path)?;

Ok(())
}
}
Expand Down

0 comments on commit e8c3f8e

Please sign in to comment.