ethabi_next/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
9use crate::{Bytes, Hash, Result, Token, TopicFilter};
10
11/// Common filtering functions that are available for any event.
12pub trait LogFilter {
13 /// Match any log parameters.
14 fn wildcard_filter(&self) -> TopicFilter;
15}
16
17/// trait common to things (events) that have an associated `Log` type
18/// that can be parsed from a `RawLog`
19pub trait ParseLog {
20 /// the associated `Log` type that can be parsed from a `RawLog`
21 /// by calling `parse_log`
22 type Log;
23
24 /// parse the associated `Log` type from a `RawLog`
25 fn parse_log(&self, log: RawLog) -> Result<Self::Log>;
26}
27
28/// Ethereum log.
29#[derive(Debug, PartialEq, Clone)]
30pub struct RawLog {
31 /// Indexed event params are represented as log topics.
32 pub topics: Vec<Hash>,
33 /// Others are just plain data.
34 pub data: Bytes,
35}
36
37impl From<(Vec<Hash>, Bytes)> for RawLog {
38 fn from(raw: (Vec<Hash>, Bytes)) -> Self {
39 RawLog { topics: raw.0, data: raw.1 }
40 }
41}
42
43/// Decoded log param.
44#[derive(Debug, PartialEq, Clone)]
45pub struct LogParam {
46 /// Decoded log name.
47 pub name: String,
48 /// Decoded log value.
49 pub value: Token,
50}
51
52/// Decoded log.
53#[derive(Debug, PartialEq, Clone)]
54pub struct Log {
55 /// Log params.
56 pub params: Vec<LogParam>,
57}