Skip to content

Commit

Permalink
feat: publish command to publish full relay index
Browse files Browse the repository at this point in the history
  • Loading branch information
ursuscamp committed Nov 22, 2023
1 parent 752d96a commit 7a27d61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions nomen/src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub enum Subcommand {
/// Rebroadcast Nostr record events
Rebroadcast,

/// Publish full name index to relay servers
Publish,

/// Prints the current version of application
Version,
}
6 changes: 6 additions & 0 deletions nomen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use config::Config;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// No log output by default
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "off");
}

tracing_subscriber::fmt::init();
let config = parse_config()?;

Expand All @@ -37,6 +42,7 @@ async fn main() -> anyhow::Result<()> {
config::Subcommand::Rebroadcast => {
subcommands::rebroadcast(&config, &pool).await?;
}
config::Subcommand::Publish => subcommands::publish(&config, &pool).await?,
config::Subcommand::Version => {
subcommands::version();
}
Expand Down
2 changes: 1 addition & 1 deletion nomen/src/subcommands/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{config::Config, db};

mod blockchain;
mod events;
pub mod events;

pub async fn index(config: &Config) -> anyhow::Result<()> {
let pool = config.sqlite().await?;
Expand Down
11 changes: 8 additions & 3 deletions nomen/src/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) async fn reindex(
pool: &SqlitePool,
blockheight: i64,
) -> anyhow::Result<()> {
tracing::info!("Re-indexing blockchain from blockheight {blockheight}.");
println!("Re-indexing blockchain from blockheight {blockheight}.");
db::index::reindex(pool, blockheight).await?;
Ok(())
}
Expand All @@ -34,7 +34,7 @@ pub(crate) async fn rescan(
pool: &SqlitePool,
blockheight: i64,
) -> anyhow::Result<()> {
tracing::info!("Re-scanning blockchain from blockheight {blockheight}.");
println!("Re-scanning blockchain from blockheight {blockheight}.");
db::index::reindex(pool, blockheight).await?;
sqlx::query("DELETE FROM index_height WHERE blockheight >= ?;")
.bind(blockheight)
Expand All @@ -59,7 +59,7 @@ pub(crate) async fn rebroadcast(config: &Config, pool: &SqlitePool) -> anyhow::R
)
.fetch_all(pool)
.await?;
tracing::info!(
println!(
"Rebroadcasing {} events to {} relays",
events.len(),
config.relays().len()
Expand All @@ -72,3 +72,8 @@ pub(crate) async fn rebroadcast(config: &Config, pool: &SqlitePool) -> anyhow::R

Ok(())
}

pub(crate) async fn publish(config: &Config, pool: &SqlitePool) -> anyhow::Result<()> {
println!("Publishing full relay index");
index::events::relay_index::publish(config, pool).await
}

0 comments on commit 7a27d61

Please sign in to comment.