Skip to main content

tronz_primitives/
log.rs

1//! TRON smart-contract event log type.
2
3use crate::{Address, B256, Bytes};
4
5/// An EVM-style event log emitted during contract execution.
6#[derive(Clone, Debug)]
7#[non_exhaustive]
8pub struct Log {
9    /// Emitting contract address.
10    pub address: Address,
11    /// Indexed topics (topic0 = event signature hash).
12    pub topics: Vec<B256>,
13    /// Non-indexed data.
14    pub data: Bytes,
15}
16
17impl Log {
18    /// Construct a log from its three fields.
19    pub fn new(address: Address, topics: Vec<B256>, data: impl Into<Bytes>) -> Self {
20        Self { address, topics, data: data.into() }
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn constructs_from_shared_primitive_fields() {
30        let address = Address::from_evm_bytes([0x11; 20]);
31        let topic = B256::from([0x22; 32]);
32        let log = Log::new(address, vec![topic], b"payload".to_vec());
33
34        assert_eq!(log.address, address);
35        assert_eq!(log.topics, vec![topic]);
36        assert_eq!(log.data.as_ref(), b"payload");
37    }
38}