Skip to content

Commit

Permalink
feat(ethereum): <- add EthReceipt parser to PTokensRouterMetadataEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
ubordignon committed Feb 19, 2024
1 parent 064cad8 commit 9541b20
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion common/ethereum/src/eth_contracts/ptokens_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Self, Self::Error> {
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())?,
}
}
}

0 comments on commit 9541b20

Please sign in to comment.