filter.rs

Overview

This file defines the MessageFilter struct, which acts as a flexible input filter for querying message data based on various optional criteria. It is designed to be used within a GraphQL API context, allowing clients to specify complex filtering conditions for messages, including fields such as identifiers, timestamps, source and destination addresses, message types, and status codes. The filter supports logical OR operations to combine multiple filter conditions recursively.

Components

MessageFilter Struct

Fields

Field

Type

Description

id

OptStringFilter

Optional string-based filter applied to the message's identifier.

created_at

OptFloatFilter

Optional floating point filter for filtering messages by their creation timestamp.

dst

OptStringFilter

Optional string filter for the destination address of the message.

msg_type

OptIntFilter

Optional integer filter to specify the message type.

src

OptStringFilter

Optional string filter for the source address of the message.

status

OptIntFilter

Optional integer filter for the message status code.

or

Option>

Optional nested filter that allows combining this filter with another using logical OR.

Usage Example

let filter = MessageFilter {
    id: OptStringFilter::equals("msg123".to_string()),
    created_at: OptFloatFilter::greater_than(1625097600.0),
    dst: OptStringFilter::contains("0xabc123".to_string()),
    msg_type: OptIntFilter::equals(1),
    src: OptStringFilter::is_null(false),
    status: OptIntFilter::in(vec![1, 2, 3]),
    or: Some(Box::new(MessageFilter {
        status: OptIntFilter::equals(4),
        ..Default::default()
    })),
};

This example illustrates how to construct a MessageFilter that matches messages with a specific ID, created after a certain timestamp, destined for an address containing "0xabc123", with a message type of 1, a non-null source, status in a list of values, or alternatively, status equal to 4.

WhereOp Trait Implementation

MessageFilter implements the WhereOp trait, which likely defines behavior or constraints needed for filtering operations within the system. This implementation enables MessageFilter to be used polymorphically wherever a WhereOp is required, such as composing query conditions in the GraphQL resolver layer.

Implementation Details

Interaction with Other Parts of the System

Diagram

classDiagram
class MessageFilter {
-id: OptStringFilter
-created_at: OptFloatFilter
-dst: OptStringFilter
-msg_type: OptIntFilter
-src: OptStringFilter
-status: OptIntFilter
-or: Option<MessageFilter>
+WhereOp
}
MessageFilter --> OptStringFilter : "id, dst, src"
MessageFilter --> OptFloatFilter : "created_at"
MessageFilter --> OptIntFilter : "msg_type, status"
MessageFilter --> MessageFilter : "or (recursive)"

The diagram illustrates the MessageFilter struct with its fields and the recursive relationship via the or field. It also shows dependencies on the optional filter types. This structure supports composable and flexible message filtering within the GraphQL API.