Skip to content

Commit 0562170

Browse files
authored
feat: index tx_hash in ibc transfers (#5247)
1 parent 03dad6f commit 0562170

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

crates/bin/pindexer/src/ibc/ibc.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ CREATE TABLE IF NOT EXISTS ibc_transfer (
1313
-- The address on the other side.
1414
foreign_addr TEXT NOT NULL,
1515
-- What kind of transfer this is.
16-
kind TEXT NOT NULL CHECK (kind IN ('inbound', 'outbound', 'refund_timeout', 'refund_error', 'refund_other'))
16+
kind TEXT NOT NULL CHECK (kind IN ('inbound', 'outbound', 'refund_timeout', 'refund_error', 'refund_other')),
17+
-- The transaction hash associated with this transfer
18+
tx_hash BYTEA
1719
);

crates/bin/pindexer/src/ibc/mod.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::anyhow;
22
use cometindex::{
33
async_trait,
4-
index::{EventBatch, EventBatchContext},
4+
index::{EventBatch, EventBatchContext, Version},
55
AppView, ContextualizedEvent, PgTransaction,
66
};
77
use penumbra_sdk_asset::Value;
@@ -176,15 +176,17 @@ async fn create_transfer(
176176
dbtx: &mut PgTransaction<'_>,
177177
height: u64,
178178
transfer: DatabaseTransfer,
179+
tx_hash: &[u8],
179180
) -> anyhow::Result<()> {
180-
sqlx::query("INSERT INTO ibc_transfer VALUES (DEFAULT, $7, $1, $6::NUMERIC(39, 0) * $2::NUMERIC(39, 0), $3, $4, $5)")
181+
sqlx::query("INSERT INTO ibc_transfer VALUES (DEFAULT, $7, $1, $6::NUMERIC(39, 0) * $2::NUMERIC(39, 0), $3, $4, $5, $8)")
181182
.bind(transfer.value.asset_id.to_bytes())
182183
.bind(transfer.value.amount.to_string())
183184
.bind(transfer.penumbra_addr.to_vec())
184185
.bind(transfer.foreign_addr)
185186
.bind(transfer.kind)
186187
.bind(if transfer.negate { -1i32 } else { 1i32 })
187188
.bind(i64::try_from(height)?)
189+
.bind(tx_hash.to_vec())
188190
.execute(dbtx.as_mut())
189191
.await?;
190192
Ok(())
@@ -205,6 +207,20 @@ impl AppView for Component {
205207
"ibc".to_string()
206208
}
207209

210+
fn version(&self) -> Version {
211+
Version::with_major(1)
212+
}
213+
214+
async fn reset(&self, dbtx: &mut PgTransaction) -> Result<(), anyhow::Error> {
215+
for statement in include_str!("reset.sql").split(";") {
216+
let trimmed = statement.trim();
217+
if !trimmed.is_empty() {
218+
sqlx::query(trimmed).execute(dbtx.as_mut()).await?;
219+
}
220+
}
221+
Ok(())
222+
}
223+
208224
async fn init_chain(
209225
&self,
210226
dbtx: &mut PgTransaction,
@@ -225,7 +241,15 @@ impl AppView for Component {
225241
Err(_) => continue,
226242
};
227243
let transfer = parsed.db_transfer();
228-
create_transfer(dbtx, event.block_height, transfer).await?;
244+
create_transfer(
245+
dbtx,
246+
event.block_height,
247+
transfer,
248+
&event
249+
.tx_hash()
250+
.expect("IBC events should have associated transaction hash"),
251+
)
252+
.await?;
229253
}
230254
Ok(())
231255
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Drop the IBC transfer table
2+
DROP TABLE IF EXISTS ibc_transfer CASCADE;

0 commit comments

Comments
 (0)