Skip to content

Commit f31129f

Browse files
committed
add log index to event id
1 parent c8ac63e commit f31129f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

crates/astria-bridge-contracts/src/lib.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ use astria_withdrawer::{
2525
SequencerWithdrawalFilter,
2626
};
2727
use ethers::{
28+
self,
29+
abi::AbiEncode,
2830
contract::EthEvent,
2931
providers::Middleware,
3032
types::{
3133
Filter,
3234
Log,
3335
H256,
3436
},
35-
utils::hex::ToHexExt as _,
3637
};
3738
pub use generated::*;
3839

@@ -379,6 +380,7 @@ where
379380
.ok_or_else(|| GetWithdrawalActionsError::log_without_block_number(&log))?
380381
.as_u64();
381382

383+
// TODO: add log index
382384
let rollup_withdrawal_event_id = log
383385
.transaction_hash
384386
.ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?
@@ -437,10 +439,16 @@ where
437439
.ok_or_else(|| GetWithdrawalActionsError::log_without_block_number(&log))?
438440
.as_u64();
439441

440-
let rollup_withdrawal_event_id = log
442+
let transaction_hash = log
441443
.transaction_hash
442444
.ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?
443445
.encode_hex();
446+
let event_index = log
447+
.log_index
448+
.ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?
449+
.encode_hex();
450+
451+
let rollup_withdrawal_event_id = transaction_hash + &event_index;
444452

445453
let event = decode_log::<SequencerWithdrawalFilter>(log)
446454
.map_err(GetWithdrawalActionsError::decode_log)?;
@@ -503,6 +511,11 @@ impl GetWithdrawalActionsError {
503511
fn log_without_transaction_hash(_log: &Log) -> Self {
504512
Self(GetWithdrawalActionsErrorKind::LogWithoutTransactionHash)
505513
}
514+
515+
// XXX: Somehow identify the log?
516+
fn log_without_log_index(_log: &Log) -> Self {
517+
Self(GetWithdrawalActionsErrorKind::LogWithoutLogIndex)
518+
}
506519
}
507520

508521
#[derive(Debug, thiserror::Error)]
@@ -519,6 +532,8 @@ enum GetWithdrawalActionsErrorKind {
519532
LogWithoutBlockNumber,
520533
#[error("log did not contain a transaction hash")]
521534
LogWithoutTransactionHash,
535+
#[error("log did not contain a log index")]
536+
LogWithoutLogIndex,
522537
#[error(transparent)]
523538
CalculateWithdrawalAmount(CalculateWithdrawalAmountError),
524539
}

crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use astria_core::{
2929
},
3030
};
3131
use ethers::{
32+
abi::AbiEncode,
3233
types::TransactionReceipt,
33-
utils::hex::ToHexExt as _,
3434
};
3535
use futures::Future;
3636
use ibc_types::core::{
@@ -436,8 +436,8 @@ pub fn make_bridge_unlock_action(receipt: &TransactionReceipt) -> Action {
436436
to: default_sequencer_address(),
437437
amount: 1_000_000u128,
438438
rollup_block_number: receipt.block_number.unwrap().as_u64(),
439-
// TODO: add event index
440-
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex(),
439+
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex()
440+
+ &receipt.logs[0].log_index.unwrap().encode_hex(),
441441
memo: String::new(),
442442
fee_asset: denom,
443443
bridge_address: default_bridge_address(),
@@ -459,8 +459,8 @@ pub fn make_ics20_withdrawal_action(receipt: &TransactionReceipt) -> Action {
459459
memo: "nootwashere".to_string(),
460460
rollup_return_address: receipt.from.to_string(),
461461
rollup_block_number: receipt.block_number.unwrap().as_u64(),
462-
// TODO: add event index
463-
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex(),
462+
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex()
463+
+ &receipt.logs[0].log_index.unwrap().encode_hex(),
464464
})
465465
.unwrap(),
466466
fee_asset: denom,

0 commit comments

Comments
 (0)