Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filtering transaction messages by multiple conditions #74

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions serve/graph/generated.go

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

6 changes: 4 additions & 2 deletions serve/graph/model/models_gen.go

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

6 changes: 4 additions & 2 deletions serve/graph/schema/filter/transaction_filter.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ input TransactionFilter {

"""
Transaction's message to filter Transactions.
`message` can be configured as a filter with a transaction message's `router` and `type` and `parameters(bank / vm)`.
`messages` can be configured as a filter with a transaction message's `router` and `type` and `parameters(bank / vm)`.
`messages` is entered as an array and works exclusively.
ex) `messages[0] || messages[1] || messages[2]`
"""
message: TransactionMessageInput
messages: [TransactionMessageInput!]

"""
`memo` are string information stored within a transaction.
Expand Down
62 changes: 19 additions & 43 deletions serve/graph/transaction_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,8 @@ func FilteredTransactionBy(tx *model.Transaction, filter model.TransactionFilter
return false
}

if filter.Message != nil {
if !filteredTransactionByMessageRoute(tx, filter.Message.Route) {
return false
}

if !filteredTransactionByMessageType(tx, filter.Message.TypeURL) {
return false
}

if !filteredTransactionByMessages(tx, filter.Message) {
return false
}
if !filteredTransactionByMessages(tx, filter.Messages) {
return false
}

return true
Expand Down Expand Up @@ -209,43 +199,21 @@ func filteredTransactionByMemo(tx *model.Transaction, filterMemo *string) bool {
}

// `filteredTransactionByMessages` checks transaction's messages.
func filteredTransactionByMessages(tx *model.Transaction, messageInput *model.TransactionMessageInput) bool {
messages := tx.Messages()
for _, message := range messages {
if !filteredTransactionMessageBy(message, messageInput) {
return false
}
}

return true
}

// `filteredTransactionByMessageRoute` checks if the transaction message contains the route value.
func filteredTransactionByMessageRoute(tx *model.Transaction, messageRoute *model.MessageRoute) bool {
if messageRoute == nil {
func filteredTransactionByMessages(tx *model.Transaction, messageInputs []*model.TransactionMessageInput) bool {
if len(messageInputs) == 0 {
return true
}

messages := tx.Messages()
for _, message := range messages {
if message.Route == messageRoute.String() {
return true
}
}

return false
}

// `filteredTransactionByMessageType` checks if the transaction message contains the type value.
func filteredTransactionByMessageType(tx *model.Transaction, messageType *model.MessageType) bool {
if messageType == nil {
return true
if len(messages) == 0 {
return false
}

messages := tx.Messages()
for _, message := range messages {
if message.TypeURL == messageType.String() {
return true
for _, messageInput := range messageInputs {
if filteredTransactionMessageBy(message, messageInput) {
return true
}
}
}

Expand All @@ -257,7 +225,15 @@ func filteredTransactionMessageBy(
tm *model.TransactionMessage,
messageInput *model.TransactionMessageInput,
) bool {
if messageInput.TypeURL != nil && messageInput.TypeURL.String() != tm.TypeURL {
if tm == nil {
return false
}

if messageInput.Route != nil && deref(messageInput.Route) != model.MessageRoute(tm.Route) {
return false
}

if messageInput.TypeURL != nil && deref(messageInput.TypeURL) != model.MessageType(tm.TypeURL) {
return false
}

Expand Down
Loading