// EVM DNA definitions (filter).
syntax = "proto3";

package evm.v2;

import "v2/common.proto";

message Filter {
  // Include header.
  HeaderFilter header = 1;
  // Filter withdrawals.
  repeated WithdrawalFilter withdrawals = 2;
  // Filter transactions.
  repeated TransactionFilter transactions = 3;
  // Filter logs.
  repeated LogFilter logs = 4;
}

enum HeaderFilter {
  HEADER_FILTER_UNSPECIFIED = 0;
  HEADER_FILTER_ALWAYS = 1;
  HEADER_FILTER_ON_DATA = 2;
  HEADER_FILTER_ON_DATA_OR_ON_NEW_BLOCK = 3;
}

message WithdrawalFilter {
  uint32 id = 1;
  // Filter based on the validator index.
  optional uint32 validator_index = 2;
  // Filter based on the withdrawal's target address.
  Address address = 3;
}

message TransactionFilter {
  uint32 id = 1;
  // Filter based on the transaction's sender address.
  Address from = 2;
  // Filter based on the transaction's recipient address.
  Address to = 3;
  /// Only return `create` transactions. Defaults to `false`.
  optional bool create = 4;
  // Filter based on the transaction status.
  //
  // Defaults to `Succeeded`.
  optional TransactionStatusFilter transaction_status = 5;
  // Flag to request the transaction's receipt. Defaults to `false`.
  optional bool include_receipt = 6;
  // Flag to request the transaction's logs. Defaults to `false`.
  optional bool include_logs = 7;
  // Flag to request the transaction's trace. Defaults to `false`.
  optional bool include_transaction_trace = 8;
}

message LogFilter {
  uint32 id = 1;
  // Filter based on the log's contract address.
  Address address = 2;
  // Filter based on the log's topics.
  repeated Topic topics = 3;
  // Only returns logs with topics of exactly the same length as the filter.
  //
  // Defaults to `false`.
  optional bool strict = 4;
  // Filter based on the transaction status.
  //
  // Defaults to `Succeeded`.
  optional TransactionStatusFilter transaction_status = 5;
  // Flag to request the log's transaction. Defaults to `false`.
  optional bool include_transaction = 6;
  // Flag to request the log's receipt. Defaults to `false`.
  optional bool include_receipt = 7;
  // Include sibling logs, that is logs emitted by the same transaction.
  //
  // Defaults to false.
  optional bool include_siblings = 8;
  // Flag to request the log's trace. Defaults to `false`.
  optional bool include_transaction_trace = 9;
}

// Topic filter.
message Topic {
  // Topic value. Leave empty to match any topic.
  B256 value = 1;
}

enum TransactionStatusFilter {
  TRANSACTION_STATUS_FILTER_UNSPECIFIED = 0;
  TRANSACTION_STATUS_FILTER_SUCCEEDED = 1;
  TRANSACTION_STATUS_FILTER_REVERTED = 2;
  TRANSACTION_STATUS_FILTER_ALL = 3;
}
