Skip to content

Commit

Permalink
[Indexer-Grpc-V2] Add proto for filters. (#15851)
Browse files Browse the repository at this point in the history
  • Loading branch information
grao1991 authored Feb 1, 2025
1 parent 20a11aa commit e0002dd
Show file tree
Hide file tree
Showing 10 changed files with 2,244 additions and 642 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ impl DataClient {
starting_version: Some(starting_version),
transactions_count: None,
batch_size: None,
transaction_filter: None,
};
loop {
let mut client = self
.connection_manager
.get_grpc_manager_client_for_request();
let response = client.get_transactions(request).await;
let response = client.get_transactions(request.clone()).await;
if let Ok(response) = response {
return response.into_inner().transactions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ impl DataService for DataServiceWrapperWrapper {
if let Some(historical_data_service) = self.historical_data_service.as_ref() {
let request = req.into_inner();
let mut stream = live_data_service
.get_transactions(Request::new(request))
.get_transactions(Request::new(request.clone()))
.await?
.into_inner();
let peekable = std::pin::pin!(stream.as_mut().peekable());
if let Some(Ok(_)) = peekable.peek().await {
return live_data_service
.get_transactions(Request::new(request))
.get_transactions(Request::new(request.clone()))
.await;
}

Expand Down
63 changes: 63 additions & 0 deletions protos/proto/aptos/indexer/v1/filter.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package aptos.indexer.v1;

import "aptos/transaction/v1/transaction.proto";

message LogicalAndFilters {
repeated BooleanTransactionFilter filters = 1;
}

message LogicalOrFilters {
repeated BooleanTransactionFilter filters = 1;
}

message TransactionRootFilter {
optional bool success = 1;
optional aptos.transaction.v1.Transaction.TransactionType transaction_type = 2;
}

message EntryFunctionFilter {
optional string address = 1;
optional string module_name = 2;
optional string function = 3;
}

message UserTransactionPayloadFilter {
optional EntryFunctionFilter entry_function_filter = 1;
}

message UserTransactionFilter {
optional string sender = 1;
optional UserTransactionPayloadFilter payload_filter = 2;
}


message MoveStructTagFilter {
optional string address = 1;
optional string module = 2;
optional string name = 3;
}

message EventFilter {
optional MoveStructTagFilter struct_type = 1;
optional string data_substring_filter = 2;
}

message APIFilter {
optional TransactionRootFilter transaction_root_filter = 1;
optional UserTransactionFilter user_transaction_filter = 2;
optional EventFilter event_filter = 3;
}

message BooleanTransactionFilter {
oneof filter {
APIFilter api_filter = 1;
LogicalAndFilters logical_and = 2;
LogicalOrFilters logical_or = 3;
BooleanTransactionFilter logical_not = 4;
}
}
4 changes: 4 additions & 0 deletions protos/proto/aptos/indexer/v1/raw_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ syntax = "proto3";

package aptos.indexer.v1;

import "aptos/indexer/v1/filter.proto";
import "aptos/transaction/v1/transaction.proto";

// This is for storage only.
Expand All @@ -26,6 +27,9 @@ message GetTransactionsRequest {
// Optional; number of transactions in each `TransactionsResponse` for current stream.
// If not present, default to 1000. If larger than 1000, request will be rejected.
optional uint64 batch_size = 3;

// If provided, only transactions that match the filter will be included.
optional BooleanTransactionFilter transaction_filter = 4;
}

// TransactionsResponse is a batch of transactions.
Expand Down
19 changes: 10 additions & 9 deletions protos/python/aptos_protos/aptos/indexer/v1/raw_data_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion protos/python/aptos_protos/aptos/indexer/v1/raw_data_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from typing import Mapping as _Mapping
from typing import Optional as _Optional
from typing import Union as _Union

from aptos.indexer.v1 import filter_pb2 as _filter_pb2
from aptos.transaction.v1 import transaction_pb2 as _transaction_pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
Expand All @@ -28,18 +29,28 @@ class TransactionsInStorage(_message.Message):
) -> None: ...

class GetTransactionsRequest(_message.Message):
__slots__ = ["starting_version", "transactions_count", "batch_size"]
__slots__ = [
"starting_version",
"transactions_count",
"batch_size",
"transaction_filter",
]
STARTING_VERSION_FIELD_NUMBER: _ClassVar[int]
TRANSACTIONS_COUNT_FIELD_NUMBER: _ClassVar[int]
BATCH_SIZE_FIELD_NUMBER: _ClassVar[int]
TRANSACTION_FILTER_FIELD_NUMBER: _ClassVar[int]
starting_version: int
transactions_count: int
batch_size: int
transaction_filter: _filter_pb2.BooleanTransactionFilter
def __init__(
self,
starting_version: _Optional[int] = ...,
transactions_count: _Optional[int] = ...,
batch_size: _Optional[int] = ...,
transaction_filter: _Optional[
_Union[_filter_pb2.BooleanTransactionFilter, _Mapping]
] = ...,
) -> None: ...

class TransactionsResponse(_message.Message):
Expand Down
Loading

0 comments on commit e0002dd

Please sign in to comment.