@ -3,7 +3,7 @@ use itertools::Itertools;
use sea_orm ::{ prelude ::* , ActiveValue ::* , Insert , QuerySelect } ;
use sea_orm ::{ prelude ::* , ActiveValue ::* , Insert , QuerySelect } ;
use tracing ::{ debug , instrument , trace } ;
use tracing ::{ debug , instrument , trace } ;
use hyperlane_core ::{ h256_to_bytes , InterchainGasPayment , LogMeta } ;
use hyperlane_core ::{ address_to_bytes , h256_to_bytes , InterchainGasPayment , LogMeta , H256 } ;
use migration ::OnConflict ;
use migration ::OnConflict ;
use crate ::conversions ::u256_to_decimal ;
use crate ::conversions ::u256_to_decimal ;
@ -14,6 +14,7 @@ use super::generated::gas_payment;
pub struct StorablePayment < ' a > {
pub struct StorablePayment < ' a > {
pub payment : & ' a InterchainGasPayment ,
pub payment : & ' a InterchainGasPayment ,
pub sequence : Option < i64 > ,
pub meta : & ' a LogMeta ,
pub meta : & ' a LogMeta ,
/// The database id of the transaction the payment was made in
/// The database id of the transaction the payment was made in
pub txn_id : i64 ,
pub txn_id : i64 ,
@ -24,9 +25,11 @@ impl ScraperDb {
pub async fn store_payments (
pub async fn store_payments (
& self ,
& self ,
domain : u32 ,
domain : u32 ,
interchain_gas_paymaster : & H256 ,
payments : impl Iterator < Item = StorablePayment < ' _ > > ,
payments : impl Iterator < Item = StorablePayment < ' _ > > ,
) -> Result < u64 > {
) -> Result < u64 > {
let latest_id_before = self . latest_payment_id ( domain ) . await ? ;
let latest_id_before = self . latest_payment_id ( domain ) . await ? ;
let interchain_gas_paymaster = address_to_bytes ( interchain_gas_paymaster ) ;
// we have a race condition where a message may not have been scraped yet even
// we have a race condition where a message may not have been scraped yet even
let models = payments
let models = payments
@ -39,6 +42,10 @@ impl ScraperDb {
gas_amount : Set ( u256_to_decimal ( storable . payment . gas_amount ) ) ,
gas_amount : Set ( u256_to_decimal ( storable . payment . gas_amount ) ) ,
tx_id : Unchanged ( storable . txn_id ) ,
tx_id : Unchanged ( storable . txn_id ) ,
log_index : Unchanged ( storable . meta . log_index . as_u64 ( ) as i64 ) ,
log_index : Unchanged ( storable . meta . log_index . as_u64 ( ) as i64 ) ,
origin : Set ( Some ( domain as i32 ) ) ,
destination : Set ( Some ( storable . payment . destination as i32 ) ) ,
interchain_gas_paymaster : Set ( Some ( interchain_gas_paymaster . clone ( ) ) ) ,
sequence : Set ( storable . sequence ) ,
} )
} )
. collect_vec ( ) ;
. collect_vec ( ) ;
@ -61,6 +68,10 @@ impl ScraperDb {
gas_payment ::Column ::TimeCreated ,
gas_payment ::Column ::TimeCreated ,
gas_payment ::Column ::Payment ,
gas_payment ::Column ::Payment ,
gas_payment ::Column ::GasAmount ,
gas_payment ::Column ::GasAmount ,
gas_payment ::Column ::Origin ,
gas_payment ::Column ::Destination ,
gas_payment ::Column ::InterchainGasPaymaster ,
gas_payment ::Column ::Sequence ,
] )
] )
. to_owned ( ) ,
. to_owned ( ) ,
)
)