From 9541b208a1e5723583af8a26e650a5cbb397dfec Mon Sep 17 00:00:00 2001 From: Ulisse Bordignon Date: Mon, 19 Feb 2024 16:54:27 +0100 Subject: [PATCH] feat(ethereum): <- add EthReceipt parser to PTokensRouterMetadataEvent --- .../src/eth_contracts/ptokens_router.rs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/ethereum/src/eth_contracts/ptokens_router.rs b/common/ethereum/src/eth_contracts/ptokens_router.rs index 46ac50a9..eef0f16a 100644 --- a/common/ethereum/src/eth_contracts/ptokens_router.rs +++ b/common/ethereum/src/eth_contracts/ptokens_router.rs @@ -5,7 +5,11 @@ use common_metadata::{MetadataChainId, METADATA_CHAIN_ID_NUMBER_OF_BYTES}; use derive_more::Constructor; use ethabi::{decode as eth_abi_decode, ParamType as EthAbiParamType, Token as EthAbiToken}; -use crate::{EthLog, EthLogExt}; +use crate::{EthLog, EthLogExt, EthReceipt}; + +crate::make_topics!( + PTOKENS_ROUTER_METADATA_EVENT_TOPIC => "41954c3bf6e497b17fc12f429900878df830619bbcccb5f61aedc91e6ccc9e64", +); #[derive(Debug, Clone, Constructor, Eq, PartialEq, Default)] pub struct PTokensRouterMetadataEvent { @@ -61,3 +65,20 @@ impl TryFrom<&EthLog> for PTokensRouterMetadataEvent { }) } } + +impl TryFrom<&EthReceipt> for PTokensRouterMetadataEvent { + type Error = AppError; + + fn try_from(receipt: &EthReceipt) -> std::result::Result { + info!("decoding `PTokensRouterMetadataEvent` from receipt..."); + + match receipt + .logs + .iter() + .find(|log| log.contains_topic(&PTOKENS_ROUTER_METADATA_EVENT_TOPIC)) + { + Some(log) => Self::try_from(log), + None => Err("no matching log found".to_string())?, + } + } +}