Skip to content

Commit

Permalink
pindexer: store indexing denom in dex explorer metadata table (#4944)
Browse files Browse the repository at this point in the history
This allows the dex explorer to read it out, which makes having separate
testnet / mainnet logic easier.

This makes it easier to swap between mainnet and testnet data.

For testing, run pindexer, verify that the metadata is there.

## Checklist before requesting a review

- [x] I have added guiding text to explain how a reviewer should test
these changes.

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > indexing only
  • Loading branch information
cronokirby authored Dec 1, 2024
1 parent c129373 commit 3bacb85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/bin/pindexer/src/dex_ex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,26 @@ mod summary {
}
}

mod metadata {
use super::*;

pub async fn set(dbtx: &mut PgTransaction<'_>, quote_asset: asset::Id) -> anyhow::Result<()> {
sqlx::query(
"
INSERT INTO dex_ex_metadata
VALUES (1, $1)
ON CONFLICT (id) DO UPDATE
SET id = EXCLUDED.id,
quote_asset_id = EXCLUDED.quote_asset_id
",
)
.bind(quote_asset.to_bytes())
.execute(dbtx.as_mut())
.await?;
Ok(())
}
}

#[derive(Debug, Default, Clone, Copy)]
struct PairMetrics {
trades: f64,
Expand Down Expand Up @@ -810,6 +830,7 @@ impl AppView for Component {
dbtx: &mut PgTransaction,
batch: EventBatch,
) -> Result<(), anyhow::Error> {
metadata::set(dbtx, self.denom).await?;
let mut charts = HashMap::new();
let mut snapshots = HashMap::new();
let mut last_time = None;
Expand Down
6 changes: 6 additions & 0 deletions crates/bin/pindexer/src/dex_ex/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ CREATE TABLE IF NOT EXISTS dex_ex_aggregate_summary (
top_price_mover_end BYTEA NOT NULL,
top_price_mover_change_percent FLOAT8 NOT NULL
);

CREATE TABLE IF NOT EXISTS dex_ex_metadata (
id INT PRIMARY KEY,
-- The asset id to use for prices in places such as the aggregate summary.
quote_asset_id BYTEA NOT NULL
);

0 comments on commit 3bacb85

Please sign in to comment.