Skip to content

Commit

Permalink
Populate transaction index in LogMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
ameten committed Oct 30, 2024
1 parent fe375f0 commit 7eb54f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions rust/main/chains/hyperlane-sealevel/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl SealevelMailboxIndexer {
Err(HyperlaneSealevelError::TooManyTransactions("Block contains more than one dispatch message transaction operating on the same dispatch message store PDA".to_owned()))?
}

let transaction_hash = transaction_hashes
let (transaction_index, transaction_hash) = transaction_hashes
.into_iter()
.next()
.ok_or(HyperlaneSealevelError::NoTransactions("block which should contain message dispatch transaction does not contain any after filtering".to_owned()))?;
Expand All @@ -723,7 +723,7 @@ impl SealevelMailboxIndexer {
// It's inconvenient to get these :|
block_hash,
transaction_id: transaction_hash,
transaction_index: 0,
transaction_index: transaction_index as u64,
log_index: U256::zero(),
},
))
Expand Down
17 changes: 9 additions & 8 deletions rust/main/chains/hyperlane-sealevel/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ pub fn search_dispatched_message_transactions(
mailbox_program_id: &Pubkey,
message_storage_pda_pubkey: &Pubkey,
transactions: Vec<EncodedTransactionWithStatusMeta>,
) -> Vec<H512> {
) -> Vec<(usize, H512)> {
transactions
.into_iter()
.filter_map(|tx| match (tx.transaction, tx.meta) {
.enumerate()
.filter_map(|(index, tx)| match (tx.transaction, tx.meta) {
// We support only transactions encoded as JSON
// We need none-empty metadata as well
(EncodedTransaction::Json(t), Some(m)) => Some((t, m)),
(EncodedTransaction::Json(t), Some(m)) => Some((index, t, m)),
_ => None,
})
.filter_map(|(t, m)| {
.filter_map(|(index, t, m)| {
let transaction_hash = match t.signatures.first() {
Some(h) => h,
None => return None, // if transaction is not signed, we continue the search
Expand Down Expand Up @@ -70,9 +71,9 @@ pub fn search_dispatched_message_transactions(
OptionSerializer::None | OptionSerializer::Skip => return None,
};

Some((transaction_hash, message, instructions))
Some((index, transaction_hash, message, instructions))
})
.filter_map(|(hash, message, instructions)| {
.filter_map(|(index, hash, message, instructions)| {
let account_keys = message
.account_keys
.into_iter()
Expand Down Expand Up @@ -125,9 +126,9 @@ pub fn search_dispatched_message_transactions(
return None;
}

Some(hash)
Some((index, hash))
})
.collect::<Vec<H512>>()
.collect::<Vec<(usize, H512)>>()
}

#[cfg(test)]
Expand Down

0 comments on commit 7eb54f8

Please sign in to comment.