Skip to content

Commit

Permalink
feat: filtering transaction messages by multiple conditions (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Miloš Živković <[email protected]>
  • Loading branch information
jinoosss and zivkovicmilos authored Aug 22, 2024
1 parent a36e834 commit ae33bd6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 55 deletions.
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

0 comments on commit ae33bd6

Please sign in to comment.