Skip to content

Commit

Permalink
pindexer: implement override for hardcoded values in app views
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby authored and conorsch committed Nov 19, 2024
1 parent ad95d8c commit f794074
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
24 changes: 7 additions & 17 deletions crates/bin/pindexer/src/indexer_ext.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
use std::str::FromStr;

pub trait IndexerExt: Sized {
fn with_default_penumbra_app_views(self) -> Self;
fn with_default_penumbra_app_views(self, options: &crate::Options) -> Self;
}

impl IndexerExt for cometindex::Indexer {
fn with_default_penumbra_app_views(self) -> Self {
fn with_default_penumbra_app_views(self, options: &crate::Options) -> Self {
self.with_index(Box::new(crate::block::Block {}))
.with_index(Box::new(crate::stake::ValidatorSet {}))
.with_index(Box::new(crate::stake::Slashings {}))
.with_index(Box::new(crate::stake::DelegationTxs {}))
.with_index(Box::new(crate::stake::UndelegationTxs {}))
.with_index(Box::new(crate::governance::GovernanceProposals {}))
.with_index(Box::new(crate::dex_ex::Component::new(
penumbra_asset::asset::Id::from_str(
// USDC
"passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6",
)
.expect("should be able to parse passet"),
100.0 * 1000_0000.0,
options.indexing_denom,
options.dex_ex_min_liquidity as f64,
)))
.with_index(Box::new(crate::supply::Component::new()))
.with_index(Box::new(crate::ibc::Component::new()))
.with_index(Box::new(crate::insights::Component::new(
penumbra_asset::asset::Id::from_str(
// USDC
"passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6",
)
.ok(),
)))
.with_index(Box::new(crate::insights::Component::new(Some(
options.indexing_denom,
))))
}
}
18 changes: 17 additions & 1 deletion crates/bin/pindexer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub use cometindex::{opt::Options, AppView, ContextualizedEvent, Indexer, PgPool, PgTransaction};
pub use cometindex::{AppView, ContextualizedEvent, Indexer, PgPool, PgTransaction};

mod indexer_ext;
pub use indexer_ext::IndexerExt;
use penumbra_asset::asset;
pub mod block;
pub mod dex_ex;
pub mod ibc;
Expand All @@ -11,3 +12,18 @@ pub mod stake;
pub mod supply;

pub mod governance;

#[derive(clap::Parser, Clone, Debug)]
pub struct Options {
#[clap(flatten)]
pub cometindex: cometindex::opt::Options,
/// The denom to use for indexing related components, of the form passet1...
#[clap(
long,
default_value = "passet1w6e7fvgxsy6ccy3m8q0eqcuyw6mh3yzqu3uq9h58nu8m8mku359spvulf6"
)]
pub indexing_denom: asset::Id,
/// The minimum liquidity for the indexing denom in the dex explorer app view.
#[clap(long, default_value = "100000000")]
pub dex_ex_min_liquidity: u128,
}
5 changes: 3 additions & 2 deletions crates/bin/pindexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use pindexer::{Indexer, IndexerExt as _, Options};

#[tokio::main]
async fn main() -> Result<()> {
Indexer::new(Options::parse())
let opts = Options::parse();
Indexer::new(opts.cometindex.clone())
.with_default_tracing()
.with_default_penumbra_app_views()
.with_default_penumbra_app_views(&opts)
.run()
.await?;

Expand Down

0 comments on commit f794074

Please sign in to comment.