Skip to content

Commit

Permalink
Simplify testnet setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SHAcollision committed Jan 9, 2025
1 parent e4c443a commit 4da5fa5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 26 deletions.
9 changes: 1 addition & 8 deletions examples/new_homeserver_user.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Result;
use log::info;
use mainline::Testnet;
use pubky::Client;
use pubky_app_specs::{traits::HasPath, PubkyAppUser, PubkyAppUserLink, PROTOCOL};
use pubky_common::crypto::{Keypair, PublicKey};
Expand All @@ -13,13 +12,7 @@ async fn main() -> Result<()> {

// Initialize the Client based on configuration
let client = match config.testnet {
true => {
let testnet = Testnet {
bootstrap: vec![config.bootstrap.clone()],
nodes: vec![],
};
Client::builder().testnet(&testnet).build()?
}
true => Client::testnet()?,
false => Client::new()?,
};

Expand Down
9 changes: 1 addition & 8 deletions examples/stress_network_sim.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Result;
use chrono::Utc;
use mainline::Testnet;
use pubky::Client;
use pubky_app_specs::{
traits::{HashId, TimestampId},
Expand Down Expand Up @@ -43,13 +42,7 @@ async fn main() -> Result<()> {

// Initialize the Client based on configuration
let client = match config.testnet {
true => {
let testnet = Testnet {
bootstrap: vec![config.bootstrap.clone()],
nodes: vec![],
};
Client::builder().testnet(&testnet).build()?
}
true => Client::testnet()?,
false => Client::new()?,
};

Expand Down
2 changes: 0 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub struct Config {
pub server_port: String,
pub reindex: bool,
pub testnet: bool,
pub bootstrap: String,
pub homeserver: String,
pub events_limit: u32,
pub watcher_sleep: u64,
Expand Down Expand Up @@ -46,7 +45,6 @@ impl Config {
.unwrap_or_else(|_| "false".to_string())
.parse()
.unwrap_or(true),
bootstrap: env::var("BOOTSTRAP").unwrap_or_else(|_| "127.0.0.1:6881".to_string()),
homeserver: env::var("HOMESERVER").expect("HOMESERVER pubky id not set"),
events_limit: env::var("EVENTS_LIMIT")
.unwrap_or("1000".to_string())
Expand Down
11 changes: 4 additions & 7 deletions src/db/connectors/pubky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ impl PubkyConnector {
let pubky_client = match testnet {
Some(testnet) => Client::builder().testnet(testnet).build()?,
None => match config.testnet {
true => {
let testnet = Testnet {
bootstrap: vec![config.bootstrap.clone()],
nodes: vec![],
};
Client::builder().testnet(&testnet).build()?
}
true => Client::testnet()?,
false => Client::new()?,
},
};

println!("CLIEEENNNNNNNNNNNNT, {:?}", pubky_client);
let manager = Self {
pubky_client: Arc::new(pubky_client),
};

PUBKY_CONNECTOR_SINGLETON
.set(manager)
.map_err(|_| PubkyConnectorError::AlreadyInitialized)?;
Expand Down
2 changes: 2 additions & 0 deletions src/events/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl EventProcessor {
let res: String;
{
let pubky_client = PubkyConnector::get_pubky_client()?;
debug!("BEFORE PUBKY CLIENT");
res = pubky_client
.get(format!(
"https://{}/events/?cursor={}&limit={}",
Expand All @@ -71,6 +72,7 @@ impl EventProcessor {
.await?
.text()
.await?;
debug!("AFTER PUBKY CLIENT");
}

let lines: Vec<String> = res.trim().split('\n').map(|s| s.to_string()).collect();
Expand Down
2 changes: 1 addition & 1 deletion src/models/homeserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Homeserver {

pub async fn from_config(config: &Config) -> Result<Homeserver, DynError> {
let homeserver_id = config.homeserver.clone();

println!("HOMESERVERRRRRRRRRRRRRRRRRRRRRRRR {}", homeserver_id);
// Create a PubkyId from the homeserver public key
let id = PubkyId::try_from(&homeserver_id)?;

Expand Down

0 comments on commit 4da5fa5

Please sign in to comment.