Skip to content

Commit

Permalink
pindexer: ibc: store height in transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Oct 3, 2024
1 parent 4745046 commit 259c320
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/bin/pindexer/src/ibc/ibc.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
CREATE TABLE IF NOT EXISTS ibc_transfer (
id SERIAL PRIMARY KEY,
-- The height that this transfer happened at.
height BIGINT NOT NULL,
-- The AssetID of whatever is being transferred.
asset BYTEA NOT NULL,
-- The amount being transf
Expand Down
6 changes: 4 additions & 2 deletions crates/bin/pindexer/src/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,17 @@ async fn init_db(dbtx: &mut PgTransaction<'_>) -> anyhow::Result<()> {

async fn create_transfer(
dbtx: &mut PgTransaction<'_>,
height: u64,
transfer: DatabaseTransfer,
) -> anyhow::Result<()> {
sqlx::query("INSERT INTO ibc_transfer VALUES (DEFAULT, $1, $6::NUMERIC(39, 0) * $2::NUMERIC(39, 0), $3, $4, $5)")
sqlx::query("INSERT INTO ibc_transfer VALUES (DEFAULT, $7, $1, $6::NUMERIC(39, 0) * $2::NUMERIC(39, 0), $3, $4, $5)")
.bind(transfer.value.asset_id.to_bytes())
.bind(transfer.value.amount.to_string())
.bind(transfer.penumbra_addr.to_vec())
.bind(transfer.foreign_addr)
.bind(transfer.kind)
.bind(if transfer.negate { -1i32 } else { 1i32 })
.bind(i64::try_from(height)?)
.execute(dbtx.as_mut())
.await?;
Ok(())
Expand Down Expand Up @@ -216,6 +218,6 @@ impl AppView for Component {
_src_db: &PgPool,
) -> anyhow::Result<()> {
let transfer = Event::try_from(event)?.db_transfer();
create_transfer(dbtx, transfer).await
create_transfer(dbtx, event.block_height, transfer).await
}
}

0 comments on commit 259c320

Please sign in to comment.