11use anyhow:: anyhow;
22use cometindex:: {
33 async_trait,
4- index:: { EventBatch , EventBatchContext } ,
4+ index:: { EventBatch , EventBatchContext , Version } ,
55 AppView , ContextualizedEvent , PgTransaction ,
66} ;
77use 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 }
0 commit comments