Skip to content

Commit 44caf94

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

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

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

+23-3
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,10 +380,16 @@ where
379380
.ok_or_else(|| GetWithdrawalActionsError::log_without_block_number(&log))?
380381
.as_u64();
381382

382-
let rollup_withdrawal_event_id = log
383+
let transaction_hash = log
383384
.transaction_hash
384385
.ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?
385386
.encode_hex();
387+
let event_index = log
388+
.log_index
389+
.ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?
390+
.encode_hex();
391+
392+
let rollup_withdrawal_event_id = format!("{transaction_hash}.{event_index}");
386393

387394
let event = decode_log::<Ics20WithdrawalFilter>(log)
388395
.map_err(GetWithdrawalActionsError::decode_log)?;
@@ -437,10 +444,16 @@ where
437444
.ok_or_else(|| GetWithdrawalActionsError::log_without_block_number(&log))?
438445
.as_u64();
439446

440-
let rollup_withdrawal_event_id = log
447+
let transaction_hash = log
441448
.transaction_hash
442449
.ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?
443450
.encode_hex();
451+
let event_index = log
452+
.log_index
453+
.ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?
454+
.encode_hex();
455+
456+
let rollup_withdrawal_event_id = format!("{transaction_hash}.{event_index}");
444457

445458
let event = decode_log::<SequencerWithdrawalFilter>(log)
446459
.map_err(GetWithdrawalActionsError::decode_log)?;
@@ -503,6 +516,11 @@ impl GetWithdrawalActionsError {
503516
fn log_without_transaction_hash(_log: &Log) -> Self {
504517
Self(GetWithdrawalActionsErrorKind::LogWithoutTransactionHash)
505518
}
519+
520+
// XXX: Somehow identify the log?
521+
fn log_without_log_index(_log: &Log) -> Self {
522+
Self(GetWithdrawalActionsErrorKind::LogWithoutLogIndex)
523+
}
506524
}
507525

508526
#[derive(Debug, thiserror::Error)]
@@ -519,6 +537,8 @@ enum GetWithdrawalActionsErrorKind {
519537
LogWithoutBlockNumber,
520538
#[error("log did not contain a transaction hash")]
521539
LogWithoutTransactionHash,
540+
#[error("log did not contain a log index")]
541+
LogWithoutLogIndex,
522542
#[error(transparent)]
523543
CalculateWithdrawalAmount(CalculateWithdrawalAmountError),
524544
}

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

+9-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::{
@@ -432,12 +432,14 @@ impl From<Ics20Withdrawal> for SubsetOfIcs20Withdrawal {
432432
#[must_use]
433433
pub fn make_bridge_unlock_action(receipt: &TransactionReceipt) -> Action {
434434
let denom = default_native_asset();
435+
let rollup_transaction_hash = receipt.transaction_hash.encode_hex();
436+
let event_index = receipt.logs[0].log_index.unwrap().encode_hex();
437+
435438
let inner = BridgeUnlockAction {
436439
to: default_sequencer_address(),
437440
amount: 1_000_000u128,
438441
rollup_block_number: receipt.block_number.unwrap().as_u64(),
439-
// TODO: add event index
440-
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex(),
442+
rollup_withdrawal_event_id: format!("{rollup_transaction_hash}.{event_index}"),
441443
memo: String::new(),
442444
fee_asset: denom,
443445
bridge_address: default_bridge_address(),
@@ -450,6 +452,9 @@ pub fn make_ics20_withdrawal_action(receipt: &TransactionReceipt) -> Action {
450452
let timeout_height = IbcHeight::new(u64::MAX, u64::MAX).unwrap();
451453
let timeout_time = make_ibc_timeout_time();
452454
let denom = default_ibc_asset();
455+
let rollup_transaction_hash = receipt.transaction_hash.encode_hex();
456+
let event_index = receipt.logs[0].log_index.unwrap().encode_hex();
457+
453458
let inner = Ics20Withdrawal {
454459
denom: denom.clone(),
455460
destination_chain_address: default_sequencer_address().to_string(),
@@ -459,8 +464,7 @@ pub fn make_ics20_withdrawal_action(receipt: &TransactionReceipt) -> Action {
459464
memo: "nootwashere".to_string(),
460465
rollup_return_address: receipt.from.to_string(),
461466
rollup_block_number: receipt.block_number.unwrap().as_u64(),
462-
// TODO: add event index
463-
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex(),
467+
rollup_withdrawal_event_id: format!("{rollup_transaction_hash}.{event_index}"),
464468
})
465469
.unwrap(),
466470
fee_asset: denom,

0 commit comments

Comments
 (0)