Skip to content

Commit

Permalink
Fixing event id
Browse files Browse the repository at this point in the history
  • Loading branch information
leboiko committed Dec 19, 2024
1 parent 4cf572d commit 3894642
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion consumer/src/mode/decoded/atom/atom_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl AtomCreated {
) -> Result<Event, ConsumerError> {
// Create the event
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::AtomCreated)
.atom_id(self.vaultID)
.block_number(U256Wrapper::from_str(&event.block_number.to_string())?)
Expand Down
4 changes: 2 additions & 2 deletions consumer/src/mode/decoded/deposited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Deposited {
// Create the event
let event = if self.isTriple {
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::Deposited)
.block_number(U256Wrapper::try_from(event.block_number)?)
.block_timestamp(event.block_timestamp)
Expand All @@ -113,7 +113,7 @@ impl Deposited {
.build()
} else {
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::Deposited)
.block_number(U256Wrapper::try_from(event.block_number)?)
.block_timestamp(event.block_timestamp)
Expand Down
2 changes: 1 addition & 1 deletion consumer/src/mode/decoded/fees_transfered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl FeesTransferred {
) -> Result<Event, ConsumerError> {
// Create the event
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::FeesTransfered)
.fee_transfer_id(event.transaction_hash.clone())
.block_number(U256Wrapper::try_from(event.block_number)?)
Expand Down
4 changes: 2 additions & 2 deletions consumer/src/mode/decoded/redeemed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Redeemed {
) -> Result<(), ConsumerError> {
if let Some(triple_id) = vault.triple_id.clone() {
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::Redeemed)
.block_number(U256Wrapper::try_from(event.block_number)?)
.block_timestamp(event.block_timestamp)
Expand All @@ -51,7 +51,7 @@ impl Redeemed {
.await?;
} else {
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::Redeemed)
.block_number(U256Wrapper::try_from(event.block_number)?)
.block_timestamp(event.block_timestamp)
Expand Down
2 changes: 1 addition & 1 deletion consumer/src/mode/decoded/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl TripleCreated {
) -> Result<Event, ConsumerError> {
// Create the event
Event::builder()
.id(event.transaction_hash.clone())
.id(DecodedMessage::event_id(event))
.event_type(EventType::TripleCreated)
.triple_id(self.vaultID)
.block_number(U256Wrapper::try_from(event.block_number)?)
Expand Down
7 changes: 7 additions & 0 deletions consumer/src/schemas/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct DecodedMessage {
pub block_number: i64,
pub block_timestamp: i64,
pub transaction_hash: String,
pub log_index: i64,
}

/// This function creates a new [`DecodedMessage`] struct
Expand All @@ -27,8 +28,14 @@ impl DecodedMessage {
block_number: raw_log.block_number,
block_timestamp: raw_log.block_timestamp,
transaction_hash: raw_log.transaction_hash,
log_index: raw_log.log_index,
}
}

/// This function formats the event id
pub fn event_id(event: &DecodedMessage) -> String {
format!("{}-{}", event.transaction_hash.clone(), event.log_index)
}
}

/// This implementation of the [`Display`] trait allows us to print the
Expand Down

0 comments on commit 3894642

Please sign in to comment.