Skip to content

Commit 1631bed

Browse files
Update go-lib and write docs
1 parent 9fdcc57 commit 1631bed

26 files changed

Lines changed: 901 additions & 553 deletions

File tree

README.md

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,98 @@
1-
# Software Development Kit for indexers
2-
SDK for creation indexers by DipDup. It's a set of package which can be used for building indexers.
1+
# DipDup Indexer SDK
32

4-
## Storage
3+
SDK for building indexers by [DipDup](https://dipdup.io). Provides a set of packages for constructing modular, flow-based indexing pipelines.
54

6-
Abstract layer of data storage is described in the package. Detailed docs can be found [here](/pkg/storage/).
5+
## Architecture
76

8-
## Modules
7+
The SDK follows a **flow-based programming (FBP)** approach: independent asynchronous modules communicate through typed inputs and outputs, forming a processing pipeline (workflow).
98

10-
The workflow is builded by modules. SDK uses flow-based programming approach. Detailed docs can be found [here](/pkg/modules/).
9+
```
10+
┌──────────┐ ┌──────────┐ ┌──────────┐
11+
│ Source │────>│ Process │────>│ Sink │
12+
│ (gRPC, │ │ (custom │ │ (storage,│
13+
│ cron) │ │ logic) │ │ printer)│
14+
└──────────┘ └──────────┘ └──────────┘
15+
```
16+
17+
## Packages
18+
19+
| Package | Description |
20+
|---------|-------------|
21+
| [`pkg/modules`](pkg/modules/) | Flow-based module system: interfaces, inputs/outputs, workflow orchestration |
22+
| [`pkg/modules/grpc`](pkg/modules/grpc/) | gRPC client and server modules with subscription support |
23+
| [`pkg/modules/cron`](pkg/modules/cron/) | Cron scheduler module |
24+
| [`pkg/modules/zipper`](pkg/modules/zipper/) | Aggregates two input streams by key |
25+
| [`pkg/modules/stopper`](pkg/modules/stopper/) | Graceful shutdown via context cancellation |
26+
| [`pkg/modules/printer`](pkg/modules/printer/) | Debug module that logs received messages |
27+
| [`pkg/storage`](pkg/storage/) | Abstract storage layer with generic interfaces |
28+
| [`pkg/storage/postgres`](pkg/storage/postgres/) | PostgreSQL implementation (pgx + bun) |
29+
| [`pkg/sync`](pkg/sync/) | Thread-safe generic `Map[K, V]` |
30+
| [`pkg/contract`](pkg/contract/) | Contract ABI to JSON Schema transformer (EVM) |
31+
| [`pkg/rlp`](pkg/rlp/) | RLP encoding/decoding for Ethereum logs |
32+
| [`pkg/jsonschema`](pkg/jsonschema/) | JSON Schema types (Draft 2019-09) |
33+
34+
## Quick Start
35+
36+
### Module Workflow
37+
38+
```go
39+
import (
40+
"github.com/dipdup-net/indexer-sdk/pkg/modules"
41+
"github.com/dipdup-net/indexer-sdk/pkg/modules/cron"
42+
)
43+
44+
// Create modules
45+
cronModule, _ := cron.NewModule(cfg.Cron)
46+
customModule := NewCustomModule()
47+
48+
// Connect cron output to custom module input
49+
modules.Connect(cronModule, customModule, "every_second", "input")
50+
51+
// Start workflow
52+
ctx, cancel := context.WithCancel(context.Background())
53+
cronModule.Start(ctx)
54+
customModule.Start(ctx)
55+
```
56+
57+
### Storage
58+
59+
```go
60+
import (
61+
"github.com/dipdup-io/go-lib/config"
62+
"github.com/dipdup-net/indexer-sdk/pkg/storage/postgres"
63+
)
64+
65+
cfg := config.Database{
66+
Host: "127.0.0.1", Port: 5432,
67+
User: "user", Password: "password", Database: "mydb",
68+
}
69+
70+
storage, _ := postgres.Create(ctx, cfg, func(ctx context.Context, conn *database.Bun) error {
71+
_, err := conn.DB().NewCreateTable().Model((*MyModel)(nil)).IfNotExists().Exec(ctx)
72+
return err
73+
})
74+
defer storage.Close()
75+
```
76+
77+
## Code Generation
78+
79+
The `cmd/dipdup-gen` tool generates boilerplate for new indexer projects from EVM contract ABIs.
80+
81+
```bash
82+
go run ./cmd/dipdup-gen abi --input contract.json --output ./generated
83+
```
84+
85+
## Examples
86+
87+
Working examples are available in the [`examples/`](examples/) directory:
88+
89+
- [`examples/cron`](examples/cron/) — cron scheduler usage
90+
- [`examples/storage`](examples/storage/) — PostgreSQL storage layer
91+
- [`examples/grpc`](examples/grpc/) — gRPC client/server with subscriptions
92+
- [`examples/zipper`](examples/zipper/) — stream aggregation by key
93+
94+
## Installation
95+
96+
```bash
97+
go get github.com/dipdup-net/indexer-sdk
98+
```

cmd/dipdup-gen/templates/cmd/main.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/dipdup-net/evm-indexer/pkg/modules/grpc"
1212
"github.com/dipdup-net/evm-indexer/pkg/modules/layer2"
1313
"github.com/dipdup-net/indexer-sdk/pkg/modules"
14-
"github.com/dipdup-net/go-lib/config"
14+
"github.com/dipdup-io/go-lib/config"
1515
"github.com/ethereum/go-ethereum/accounts/abi"
1616
"github.com/spf13/cobra"
1717

cmd/dipdup-gen/templates/modules/postgres_module.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"sync"
66

7-
"github.com/dipdup-net/go-lib/config"
7+
"github.com/dipdup-io/go-lib/config"
88
"{{ .PackageName }}/internal/storage/postgres"
99
"{{ .PackageName }}/internal/storage"
1010
"github.com/dipdup-net/evm-indexer/pkg/modules/grpc/pb"

cmd/dipdup-gen/templates/storage/postgres.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package postgres
22

33
import (
44
"{{ .PackageName }}/internal/storage"
5-
"github.com/dipdup-net/go-lib/database"
5+
"github.com/dipdup-io/go-lib/database"
66
"github.com/dipdup-net/indexer-sdk/pkg/storage/postgres"
77
)
88

cmd/dipdup-gen/templates/storage/postgres_core.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package postgres
33
import (
44
"context"
55

6-
"github.com/dipdup-net/go-lib/config"
7-
"github.com/dipdup-net/go-lib/database"
6+
"github.com/dipdup-io/go-lib/config"
7+
"github.com/dipdup-io/go-lib/database"
88
models "{{ .PackageName }}/internal/storage"
99
"github.com/dipdup-net/indexer-sdk/pkg/storage"
1010
"github.com/dipdup-net/indexer-sdk/pkg/storage/postgres"

examples/cron/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os/signal"
88
"syscall"
99

10-
"github.com/dipdup-net/go-lib/config"
10+
"github.com/dipdup-io/go-lib/config"
1111
"github.com/dipdup-net/indexer-sdk/pkg/modules"
1212
"github.com/dipdup-net/indexer-sdk/pkg/modules/cron"
1313
)

examples/storage/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"log"
66

7-
"github.com/dipdup-net/go-lib/config"
7+
"github.com/dipdup-io/go-lib/config"
88
"github.com/dipdup-net/indexer-sdk/examples/storage/storage"
99
"github.com/dipdup-net/indexer-sdk/examples/storage/storage/postgres"
1010
)

examples/storage/storage/postgres/core.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"database/sql"
66

7-
"github.com/dipdup-net/go-lib/config"
8-
"github.com/dipdup-net/go-lib/database"
7+
"github.com/dipdup-io/go-lib/config"
8+
"github.com/dipdup-io/go-lib/database"
99
models "github.com/dipdup-net/indexer-sdk/examples/storage/storage"
1010
"github.com/dipdup-net/indexer-sdk/pkg/storage/postgres"
1111
"github.com/uptrace/bun"

examples/storage/storage/postgres/person.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package postgres
33
import (
44
"context"
55

6-
"github.com/dipdup-net/go-lib/database"
6+
"github.com/dipdup-io/go-lib/database"
77
"github.com/dipdup-net/indexer-sdk/examples/storage/storage"
88
"github.com/dipdup-net/indexer-sdk/pkg/storage/postgres"
99
)

go.mod

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ module github.com/dipdup-net/indexer-sdk
33
go 1.25.7
44

55
require (
6+
github.com/dipdup-io/go-lib/config v1.0.0
7+
github.com/dipdup-io/go-lib/database v1.0.0
68
github.com/dipdup-io/workerpool v0.0.4
7-
github.com/dipdup-net/go-lib v0.5.0
89
github.com/ethereum/go-ethereum v1.17.0
9-
github.com/go-testfixtures/testfixtures/v3 v3.16.0
10+
github.com/go-testfixtures/testfixtures/v3 v3.19.0
1011
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0-rc.0
1112
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.5
1213
github.com/iancoleman/strcase v0.3.0
1314
github.com/jackc/pgx/v5 v5.8.0
1415
github.com/json-iterator/go v1.1.12
15-
github.com/lib/pq v1.10.9
16+
github.com/lib/pq v1.11.2
1617
github.com/pkg/errors v0.9.1
1718
github.com/prometheus/client_golang v1.22.0
1819
github.com/robfig/cron/v3 v3.0.1
@@ -23,12 +24,12 @@ require (
2324
github.com/uptrace/bun/dialect/pgdialect v1.2.18
2425
go.uber.org/mock v0.5.0
2526
golang.org/x/time v0.11.0
26-
google.golang.org/grpc v1.77.0
27+
google.golang.org/grpc v1.79.1
2728
google.golang.org/protobuf v1.36.11
2829
)
2930

3031
require (
31-
dario.cat/mergo v1.0.1 // indirect
32+
dario.cat/mergo v1.0.2 // indirect
3233
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
3334
github.com/Microsoft/go-winio v0.6.2 // indirect
3435
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect
@@ -37,28 +38,31 @@ require (
3738
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
3839
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3940
github.com/consensys/gnark-crypto v0.18.1 // indirect
41+
github.com/containerd/errdefs v1.0.0 // indirect
42+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
4043
github.com/containerd/log v0.1.0 // indirect
4144
github.com/containerd/platforms v0.2.1 // indirect
4245
github.com/cpuguy83/dockercfg v0.3.2 // indirect
4346
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
4447
github.com/davecgh/go-spew v1.1.1 // indirect
4548
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
49+
github.com/dipdup-io/go-lib/hasura v1.0.0 // indirect
4650
github.com/distribution/reference v0.6.0 // indirect
47-
github.com/docker/docker v28.0.4+incompatible // indirect
48-
github.com/docker/go-connections v0.5.0 // indirect
51+
github.com/docker/docker v28.5.1+incompatible // indirect
52+
github.com/docker/go-connections v0.6.0 // indirect
4953
github.com/docker/go-units v0.5.0 // indirect
50-
github.com/ebitengine/purego v0.8.2 // indirect
54+
github.com/ebitengine/purego v0.8.4 // indirect
5155
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
5256
github.com/felixge/httpsnoop v1.0.4 // indirect
53-
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
57+
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
5458
github.com/go-logr/logr v1.4.3 // indirect
5559
github.com/go-logr/stdr v1.2.2 // indirect
5660
github.com/go-ole/go-ole v1.3.0 // indirect
5761
github.com/go-playground/locales v0.14.1 // indirect
5862
github.com/go-playground/universal-translator v0.18.1 // indirect
59-
github.com/go-playground/validator/v10 v10.26.0 // indirect
60-
github.com/goccy/go-yaml v1.17.1 // indirect
61-
github.com/gogo/protobuf v1.3.2 // indirect
63+
github.com/go-playground/validator/v10 v10.30.1 // indirect
64+
github.com/goccy/go-yaml v1.18.0 // indirect
65+
github.com/golang/mock v1.7.0-rc.1 // indirect
6266
github.com/google/uuid v1.6.0 // indirect
6367
github.com/holiman/uint256 v1.3.2 // indirect
6468
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -73,9 +77,10 @@ require (
7377
github.com/mattn/go-colorable v0.1.14 // indirect
7478
github.com/mattn/go-isatty v0.0.20 // indirect
7579
github.com/moby/docker-image-spec v1.3.1 // indirect
80+
github.com/moby/go-archive v0.1.0 // indirect
7681
github.com/moby/patternmatcher v0.6.0 // indirect
77-
github.com/moby/sys/sequential v0.5.0 // indirect
78-
github.com/moby/sys/user v0.3.0 // indirect
82+
github.com/moby/sys/sequential v0.6.0 // indirect
83+
github.com/moby/sys/user v0.4.0 // indirect
7984
github.com/moby/sys/userns v0.1.0 // indirect
8085
github.com/moby/term v0.5.0 // indirect
8186
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -91,12 +96,12 @@ require (
9196
github.com/prometheus/procfs v0.15.1 // indirect
9297
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
9398
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
94-
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
99+
github.com/shirou/gopsutil/v4 v4.25.6 // indirect
95100
github.com/sirupsen/logrus v1.9.3 // indirect
96101
github.com/spf13/pflag v1.0.6 // indirect
97102
github.com/supranational/blst v0.3.16-0.20250831170142-f48500c1fdbe // indirect
98-
github.com/testcontainers/testcontainers-go v0.37.0 // indirect
99-
github.com/testcontainers/testcontainers-go/modules/postgres v0.37.0 // indirect
103+
github.com/testcontainers/testcontainers-go v0.40.0 // indirect
104+
github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0 // indirect
100105
github.com/tklauser/go-sysconf v0.3.12 // indirect
101106
github.com/tklauser/numcpus v0.6.1 // indirect
102107
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
@@ -113,6 +118,7 @@ require (
113118
golang.org/x/sync v0.19.0 // indirect
114119
golang.org/x/sys v0.41.0 // indirect
115120
golang.org/x/text v0.34.0 // indirect
121+
google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b // indirect
116122
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect
117123
gopkg.in/yaml.v3 v3.0.1 // indirect
118124
)

0 commit comments

Comments
 (0)