Skip to content

Commit

Permalink
Merge branch 'main' into fork/TERITORI/handle-genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Sep 13, 2024
2 parents 4feb0f0 + 9921720 commit f1d4b50
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 92 deletions.
9 changes: 6 additions & 3 deletions .github/golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ run:
modules-download-mode: readonly
allow-parallel-runners: false
go: ""
skip-dirs:
- serve/filters/mocks

output:
uniq-by-line: false
Expand All @@ -25,6 +23,8 @@ issues:
linters:
- nilnil
- gosec
exclude-dirs:
- serve/filters/mocks

linters:
fast: false
Expand All @@ -35,7 +35,7 @@ linters:
- bidichk # Checks for dangerous unicode character sequences
- durationcheck # Check for two durations multiplied together
- errcheck # Forces to not skip error check
- exportloopref # Checks for pointers to enclosing loop variables
- copyloopvar # Checks for pointers to enclosing loop variables
- gocritic # Bundles different linting checks
- godot # Checks for periods at the end of comments
- gomoddirectives # Allow or ban replace directives in go.mod
Expand Down Expand Up @@ -124,3 +124,6 @@ linters-settings:
rules:
json: goCamel
yaml: goCamel
gosec:
excludes:
- G115 # G115: integer overflow conversion uint64 -> int6
2 changes: 1 addition & 1 deletion .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
cache: true

- uses: sigstore/cosign-installer@v3.6.0
- uses: anchore/sbom-action/download-syft@v0.17.0
- uses: anchore/sbom-action/download-syft@v0.17.1

- uses: docker/login-action@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ git clone https://github.com/gnolang/tx-indexer.git
2. **Build the binary**

```bash
cd tx-indexer
make build
```

Expand Down Expand Up @@ -104,7 +105,7 @@ A GraphQL playground is available at `/graphql`. There you have all the document
```graphql
{
transactions(
filter: { message: {vm_param: {add_package: {}}}}
filter: { messages: {vm_param: {add_package: {}}}}
) {
index
hash
Expand Down
2 changes: 0 additions & 2 deletions cmd/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ func (w *waiter) wait() error {
})

for _, fn := range w.waitFns {
fn := fn

g.Go(
func() error {
return fn(ctx)
Expand Down
2 changes: 0 additions & 2 deletions events/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func TestSubscription_EventSupported(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions fetch/slots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func TestSlots_FindGaps(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module github.com/gnolang/tx-indexer

go 1.22

toolchain go1.22.5

require (
github.com/99designs/gqlgen v0.17.49
github.com/cockroachdb/pebble v1.1.1
github.com/cockroachdb/pebble v1.1.2
github.com/gnolang/gno v0.1.1
github.com/go-chi/chi/v5 v5.1.0
github.com/go-chi/httprate v0.12.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/e
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/pebble v1.1.1 h1:XnKU22oiCLy2Xn8vp1re67cXg4SAasg/WDt1NtcRFaw=
github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU=
github.com/cockroachdb/pebble v1.1.2 h1:CUh2IPtR4swHlEj48Rhfzw6l/d0qA31fItcIszQVIsA=
github.com/cockroachdb/pebble v1.1.2/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
Expand Down
2 changes: 0 additions & 2 deletions serve/filters/filter/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func TestBaseFilter_GetType(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions serve/filters/filter/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func TestBlockFilter_GetChanges(t *testing.T) {

// Update the block filter with dummy blocks
for _, block := range blocks {
block := block

f.UpdateWith(block)
}

Expand Down
2 changes: 0 additions & 2 deletions serve/filters/filter/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func TestApplyFilters(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -295,7 +294,6 @@ func TestApplyFiltersWithLargeData(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions serve/filters/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func Test_NewBlockEvents(t *testing.T) {
defer filterManager.UninstallFilter(id)

for _, block := range blocks {
block := block

blockCh <- &types.NewBlock{
Block: block,
}
Expand Down
1 change: 0 additions & 1 deletion serve/filters/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (sm *subscriptionMap) sendEvent(eventType events.Type, data any) {
}

for id, sub := range sm.subscriptions {
sub := sub
if sub.GetType() != eventType {
continue
}
Expand Down
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
2 changes: 0 additions & 2 deletions serve/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func TestHTTP_Handle(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions serve/handlers/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ func TestGetBlock_InvalidParams(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 0 additions & 6 deletions serve/handlers/subs/subs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ func TestUninstallFilter_InvalidParams(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -211,8 +209,6 @@ func TestGetFilterChanges_InvalidParams(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -546,8 +542,6 @@ func TestSubscribeUnsubscribe_InvalidParams(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
Loading

0 comments on commit f1d4b50

Please sign in to comment.