ethabi/
log.rs

1// Copyright 2015-2020 Parity Technologies
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11
12#[cfg(not(feature = "std"))]
13use crate::no_std_prelude::*;
14use crate::{Bytes, Hash, Result, Token, TopicFilter};
15
16/// Common filtering functions that are available for any event.
17pub trait LogFilter {
18	/// Match any log parameters.
19	fn wildcard_filter(&self) -> TopicFilter;
20}
21
22/// trait common to things (events) that have an associated `Log` type
23/// that can be parsed from a `RawLog`
24pub trait ParseLog {
25	/// the associated `Log` type that can be parsed from a `RawLog`
26	/// by calling `parse_log`
27	type Log;
28
29	/// parse the associated `Log` type from a `RawLog`
30	fn parse_log(&self, log: RawLog) -> Result<Self::Log>;
31}
32
33/// Ethereum log.
34#[derive(Debug, PartialEq, Eq, Clone)]
35pub struct RawLog {
36	/// Indexed event params are represented as log topics.
37	pub topics: Vec<Hash>,
38	/// Others are just plain data.
39	pub data: Bytes,
40}
41
42impl From<(Vec<Hash>, Bytes)> for RawLog {
43	fn from(raw: (Vec<Hash>, Bytes)) -> Self {
44		RawLog { topics: raw.0, data: raw.1 }
45	}
46}
47
48/// Decoded log param.
49#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
50#[derive(Debug, PartialEq, Clone)]
51pub struct LogParam {
52	/// Decoded log name.
53	pub name: String,
54	/// Decoded log value.
55	pub value: Token,
56}
57
58/// Decoded log.
59#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
60#[derive(Debug, PartialEq, Clone)]
61pub struct Log {
62	/// Log params.
63	pub params: Vec<LogParam>,
64}