Skip to content

Commit

Permalink
feat: Add transaction message filter in GraphQL (#20)
Browse files Browse the repository at this point in the history
* chore: Separate Graphql schemas

* chore: mod tidy

* feat: Implements transaction message encoding and message filter

* chore: Separate Graphql schemas

* feat: Implements transaction message encoding and message filter

* fix: Fix lints

* fix: Remove filter data model

* fix: Remove utils

* feat: Change filter logic

* fix: Fix lints

* chore: Add graphql comments for docs

* refactor: Change a graph structure

* chore: Add descriptions for docs

* feat: Create Filter Functions

* feat: Add a token amount filter

* feat: Improve transaction performance and handle exception cases

* chore: Add descriptions for docs

* fix: Fix lints

* chore: Add descriptions for docs

* fix: Added descriptions to filter functions and made minor fixes

* fix: Fix naming conventions

Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>

* fix: Fix naming conventions

Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>

* fix: Fix naming conventions

Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>

* fix: Fix naming conventions

Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>

* feat: Update generated models

---------

Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>
  • Loading branch information
jinoosss and ajnavarro authored Apr 8, 2024
1 parent 2a70d0e commit 0ad639a
Show file tree
Hide file tree
Showing 19 changed files with 5,331 additions and 1,172 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8=
Expand Down Expand Up @@ -178,6 +180,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/linxGnu/grocksdb v1.8.5 h1:Okfk5B1h0ikCYdDM7Tc5yJUS8LTwAmMBq5IPWTmOLPs=
Expand Down
8 changes: 6 additions & 2 deletions gqlgen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Where are all the schema files located? globs are supported eg src/**/*.graphql
schema:
- serve/graph/*.graphql
- serve/graph/schema/*.graphql
- serve/graph/schema/**/*.graphql

# Where should the generated server code go?
exec:
Expand Down Expand Up @@ -85,4 +86,7 @@ models:
- github.com/gnolang/tx-indexer/serve/graph/model.Block
Transaction:
model:
- github.com/gnolang/tx-indexer/serve/graph/model.Transaction
- github.com/gnolang/tx-indexer/serve/graph/model.Transaction
TransactionMessage:
model:
- github.com/gnolang/tx-indexer/serve/graph/model.TransactionMessage
31 changes: 31 additions & 0 deletions serve/graph/block_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package graph

import (
"time"

"github.com/gnolang/tx-indexer/serve/graph/model"
)

// `FilteredBlockBy` checks for conditions in BlockTime.
// By default, the condition is only checked if the input parameter exists.
func FilteredBlockBy(block *model.Block, filter model.BlockFilter) bool {
if block == nil {
return false
}

return filteredBlockByBlockTime(block, filter.FromTime, filter.ToTime)
}

// `filteredBlockByBlockTime` checks block based on block time.
func filteredBlockByBlockTime(block *model.Block, filterFromTime, filterToTime *time.Time) bool {
fromTime := deref(filterFromTime)
toTime := deref(filterToTime)

if filterToTime == nil {
toTime = time.Now()
}

blockTime := block.Time()

return (blockTime.After(fromTime) || blockTime.Equal(fromTime)) && (toTime.IsZero() || blockTime.Before(toTime))
}
Loading

0 comments on commit 0ad639a

Please sign in to comment.