Skip to content

Commit

Permalink
add log index to event id
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Sep 13, 2024
1 parent c8ac63e commit 44caf94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
26 changes: 23 additions & 3 deletions crates/astria-bridge-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ use astria_withdrawer::{
SequencerWithdrawalFilter,
};
use ethers::{
self,
abi::AbiEncode,
contract::EthEvent,
providers::Middleware,
types::{
Filter,
Log,
H256,
},
utils::hex::ToHexExt as _,
};
pub use generated::*;

Expand Down Expand Up @@ -379,10 +380,16 @@ where
.ok_or_else(|| GetWithdrawalActionsError::log_without_block_number(&log))?
.as_u64();

let rollup_withdrawal_event_id = log
let transaction_hash = log
.transaction_hash
.ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?
.encode_hex();
let event_index = log
.log_index
.ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?
.encode_hex();

let rollup_withdrawal_event_id = format!("{transaction_hash}.{event_index}");

let event = decode_log::<Ics20WithdrawalFilter>(log)
.map_err(GetWithdrawalActionsError::decode_log)?;
Expand Down Expand Up @@ -437,10 +444,16 @@ where
.ok_or_else(|| GetWithdrawalActionsError::log_without_block_number(&log))?
.as_u64();

let rollup_withdrawal_event_id = log
let transaction_hash = log
.transaction_hash
.ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?
.encode_hex();
let event_index = log
.log_index
.ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?
.encode_hex();

let rollup_withdrawal_event_id = format!("{transaction_hash}.{event_index}");

let event = decode_log::<SequencerWithdrawalFilter>(log)
.map_err(GetWithdrawalActionsError::decode_log)?;
Expand Down Expand Up @@ -503,6 +516,11 @@ impl GetWithdrawalActionsError {
fn log_without_transaction_hash(_log: &Log) -> Self {
Self(GetWithdrawalActionsErrorKind::LogWithoutTransactionHash)
}

// XXX: Somehow identify the log?
fn log_without_log_index(_log: &Log) -> Self {
Self(GetWithdrawalActionsErrorKind::LogWithoutLogIndex)
}
}

#[derive(Debug, thiserror::Error)]
Expand All @@ -519,6 +537,8 @@ enum GetWithdrawalActionsErrorKind {
LogWithoutBlockNumber,
#[error("log did not contain a transaction hash")]
LogWithoutTransactionHash,
#[error("log did not contain a log index")]
LogWithoutLogIndex,
#[error(transparent)]
CalculateWithdrawalAmount(CalculateWithdrawalAmountError),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use astria_core::{
},
};
use ethers::{
abi::AbiEncode,
types::TransactionReceipt,
utils::hex::ToHexExt as _,
};
use futures::Future;
use ibc_types::core::{
Expand Down Expand Up @@ -432,12 +432,14 @@ impl From<Ics20Withdrawal> for SubsetOfIcs20Withdrawal {
#[must_use]
pub fn make_bridge_unlock_action(receipt: &TransactionReceipt) -> Action {
let denom = default_native_asset();
let rollup_transaction_hash = receipt.transaction_hash.encode_hex();
let event_index = receipt.logs[0].log_index.unwrap().encode_hex();

let inner = BridgeUnlockAction {
to: default_sequencer_address(),
amount: 1_000_000u128,
rollup_block_number: receipt.block_number.unwrap().as_u64(),
// TODO: add event index
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex(),
rollup_withdrawal_event_id: format!("{rollup_transaction_hash}.{event_index}"),
memo: String::new(),
fee_asset: denom,
bridge_address: default_bridge_address(),
Expand All @@ -450,6 +452,9 @@ pub fn make_ics20_withdrawal_action(receipt: &TransactionReceipt) -> Action {
let timeout_height = IbcHeight::new(u64::MAX, u64::MAX).unwrap();
let timeout_time = make_ibc_timeout_time();
let denom = default_ibc_asset();
let rollup_transaction_hash = receipt.transaction_hash.encode_hex();
let event_index = receipt.logs[0].log_index.unwrap().encode_hex();

let inner = Ics20Withdrawal {
denom: denom.clone(),
destination_chain_address: default_sequencer_address().to_string(),
Expand All @@ -459,8 +464,7 @@ pub fn make_ics20_withdrawal_action(receipt: &TransactionReceipt) -> Action {
memo: "nootwashere".to_string(),
rollup_return_address: receipt.from.to_string(),
rollup_block_number: receipt.block_number.unwrap().as_u64(),
// TODO: add event index
rollup_withdrawal_event_id: receipt.transaction_hash.encode_hex(),
rollup_withdrawal_event_id: format!("{rollup_transaction_hash}.{event_index}"),
})
.unwrap(),
fee_asset: denom,
Expand Down

0 comments on commit 44caf94

Please sign in to comment.