Skip to content

Commit 525e239

Browse files
Deps: go-lib and docs
1 parent 04acfa4 commit 525e239

10 files changed

Lines changed: 242 additions & 141 deletions

File tree

CLAUDE.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
```bash
8+
# Run all tests (requires Docker for PostgreSQL containers)
9+
make test
10+
# or: go test -p 8 -timeout 60s ./...
11+
12+
# Run a single test
13+
go test -run TestCelestialsTestSuite/TestSync ./pkg/module/...
14+
15+
# Lint
16+
make lint
17+
18+
# Regenerate mocks and enums
19+
make generate
20+
```
21+
22+
## Architecture
23+
24+
This is a **Celestia blockchain indexing module** built on the [DipDup indexer SDK](https://github.com/dipdup-net/indexer-sdk). It scans for changes to Celestial IDs (blockchain domains) from an external API and persists them to PostgreSQL.
25+
26+
### Data flow
27+
28+
1. `Module` (pkg/module) runs a periodic sync loop (default: 1 min interval)
29+
2. Fetches changes from external API (`pkg/api/v1`) starting from the last known `change_id`
30+
3. Writes results to PostgreSQL in a transaction: upsert celestials → update state → flush
31+
4. `CelestialState` table tracks the last processed `change_id` to enable resumable syncing
32+
33+
### Key packages
34+
35+
- **`pkg/module`** — Core orchestration. `Module` embeds DipDup's `BaseModule` and implements the sync loop. Configured via `ModuleOption` functions (`WithIndexPeriod`, `WithLimit`, `WithDatabaseTimeout`). Accepts an `AddressHandler` callback to resolve blockchain addresses.
36+
- **`pkg/api`** — External Celestials API client interface + `v1/` HTTP implementation using fast-shot (rate-limited to 5 req/s).
37+
- **`pkg/storage`** — Storage interfaces (`ICelestial`, `ICelestialState`, `CelestialTransaction`) and status enum (`NOT_VERIFIED`, `VERIFIED`, `PRIMARY`).
38+
- **`pkg/storage/postgres`** — Bun ORM implementation. Uses PostgreSQL `ON CONFLICT DO UPDATE` for idempotent upserts. Status transitions: `PRIMARY → VERIFIED` when a new primary address is set for an existing celestial.
39+
40+
### Testing
41+
42+
Tests use `testcontainers` to spin up a real PostgreSQL 15.8 + TimescaleDB instance. Fixtures are loaded from `/test/*.yml` via go-testfixtures. Mocks for all interfaces are auto-generated via mockgen (stored in `pkg/*/mock/`).
43+
44+
When adding new interfaces, add a `//go:generate mockgen ...` directive and run `make generate`.

README.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,96 @@
1-
# Celestial module
2-
Package containig Celestials module for indexing its data
1+
# Celestial Module
2+
3+
A Go module for indexing [Celestial IDs](https://celestials.id/) — domain names on the Celestia network. Built on top of the [DipDup Indexer SDK](https://github.com/dipdup-net/indexer-sdk) and designed to be embedded into an indexer as a standalone module.
4+
5+
## What it does
6+
7+
The module periodically polls the external Celestials API, fetches domain changes (registrations, address updates, status changes), and persists them to PostgreSQL. It tracks progress using a `change_id` — the module remembers the last processed identifier and resumes from that point on restart.
8+
9+
## Requirements
10+
11+
- Go 1.25+
12+
- PostgreSQL 15+ with the TimescaleDB extension
13+
- Docker (for running tests)
14+
15+
## Installation
16+
17+
```bash
18+
go get github.com/celenium-io/celestial-module
19+
```
20+
21+
## Usage
22+
23+
```go
24+
import (
25+
"github.com/celenium-io/celestial-module/pkg/module"
26+
"github.com/celenium-io/celestial-module/pkg/storage"
27+
"github.com/celenium-io/celestial-module/pkg/storage/postgres"
28+
)
29+
30+
m := module.New(
31+
celestialsDatasource, // config.DataSource with Celestials API URL
32+
addressHandler, // func(ctx, address string) (uint64, error)
33+
celestialsStorage, // storage.ICelestial
34+
stateStorage, // storage.ICelestialState
35+
transactable, // sdk.Transactable
36+
"my-indexer", // indexer name for state tracking
37+
"celestia", // network name
38+
module.WithIndexPeriod(30*time.Second), // sync interval (default: 1 min)
39+
module.WithLimit(200), // batch size (default: 100)
40+
module.WithDatabaseTimeout(2*time.Minute), // DB operation timeout (default: 1 min)
41+
)
42+
43+
m.Start(ctx)
44+
defer m.Close()
45+
```
46+
47+
`AddressHandler` is a callback the module uses to resolve a string address into an internal address ID. It should be implemented on the indexer side.
48+
49+
## Structure
50+
51+
```
52+
pkg/
53+
├── api/ # External Celestials API client
54+
│ ├── v1/ # HTTP implementation (fast-shot, rate limited to 5 req/s)
55+
│ └── mock/ # Auto-generated mocks
56+
├── module/ # Core indexing module
57+
└── storage/ # Storage interfaces and data models
58+
├── postgres/ # Bun ORM implementation (PostgreSQL)
59+
└── mock/ # Auto-generated mocks
60+
```
61+
62+
## Data models
63+
64+
**Celestial** — a domain name:
65+
66+
| Field | Type | Description |
67+
|-------|------|-------------|
68+
| `id` | string | Domain identifier (PK) |
69+
| `address_id` | uint64 | Internal ID of the linked address |
70+
| `image_url` | string | Image URL |
71+
| `change_id` | int64 | ID of the last change |
72+
| `status` | enum | `NOT_VERIFIED`, `VERIFIED`, `PRIMARY` |
73+
74+
**CelestialState** — sync state:
75+
76+
| Field | Type | Description |
77+
|-------|------|-------------|
78+
| `name` | string | Indexer name (PK) |
79+
| `change_id` | int64 | Last processed change ID |
80+
81+
## Development
82+
83+
```bash
84+
# Run tests (requires Docker)
85+
make test
86+
87+
# Lint
88+
make lint
89+
90+
# Regenerate mocks and enum methods
91+
make generate
92+
```
93+
94+
## License
95+
96+
[MIT](LICENSE)

go.mod

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ go 1.25.7
55
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
66

77
require (
8-
github.com/dipdup-net/go-lib v0.5.0
9-
github.com/dipdup-net/indexer-sdk v0.0.9
10-
github.com/go-testfixtures/testfixtures/v3 v3.16.0
8+
github.com/dipdup-io/go-lib/config v1.0.0
9+
github.com/dipdup-io/go-lib/database v1.0.0
10+
github.com/dipdup-net/indexer-sdk v0.0.11
11+
github.com/go-testfixtures/testfixtures/v3 v3.19.0
1112
github.com/goccy/go-json v0.10.5
1213
github.com/jackc/pgx/v5 v5.8.0
1314
github.com/opus-domini/fast-shot v1.1.4
@@ -20,31 +21,34 @@ require (
2021
)
2122

2223
require (
23-
dario.cat/mergo v1.0.1 // indirect
24+
dario.cat/mergo v1.0.2 // indirect
2425
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
2526
github.com/Microsoft/go-winio v0.6.2 // indirect
2627
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2728
github.com/cespare/xxhash/v2 v2.3.0 // indirect
29+
github.com/containerd/errdefs v1.0.0 // indirect
30+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
2831
github.com/containerd/log v0.1.0 // indirect
2932
github.com/containerd/platforms v0.2.1 // indirect
3033
github.com/cpuguy83/dockercfg v0.3.2 // indirect
3134
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
35+
github.com/dipdup-io/go-lib/hasura v1.0.0 // indirect
3236
github.com/dipdup-io/workerpool v0.0.4 // indirect
3337
github.com/distribution/reference v0.6.0 // indirect
34-
github.com/docker/docker v28.0.4+incompatible // indirect
35-
github.com/docker/go-connections v0.5.0 // indirect
38+
github.com/docker/docker v28.5.1+incompatible // indirect
39+
github.com/docker/go-connections v0.6.0 // indirect
3640
github.com/docker/go-units v0.5.0 // indirect
37-
github.com/ebitengine/purego v0.8.2 // indirect
41+
github.com/ebitengine/purego v0.8.4 // indirect
3842
github.com/felixge/httpsnoop v1.0.4 // indirect
39-
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
43+
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
4044
github.com/go-logr/logr v1.4.3 // indirect
4145
github.com/go-logr/stdr v1.2.2 // indirect
4246
github.com/go-ole/go-ole v1.3.0 // indirect
4347
github.com/go-playground/locales v0.14.1 // indirect
4448
github.com/go-playground/universal-translator v0.18.1 // indirect
45-
github.com/go-playground/validator/v10 v10.26.0 // indirect
46-
github.com/goccy/go-yaml v1.17.1 // indirect
47-
github.com/gogo/protobuf v1.3.3 // indirect
49+
github.com/go-playground/validator/v10 v10.30.1 // indirect
50+
github.com/goccy/go-yaml v1.18.0 // indirect
51+
github.com/golang/mock v1.7.0-rc.1 // indirect
4852
github.com/google/uuid v1.6.0 // indirect
4953
github.com/jackc/pgpassfile v1.0.0 // indirect
5054
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
@@ -58,9 +62,10 @@ require (
5862
github.com/mattn/go-colorable v0.1.14 // indirect
5963
github.com/mattn/go-isatty v0.0.20 // indirect
6064
github.com/moby/docker-image-spec v1.3.1 // indirect
65+
github.com/moby/go-archive v0.1.0 // indirect
6166
github.com/moby/patternmatcher v0.6.0 // indirect
62-
github.com/moby/sys/sequential v0.5.0 // indirect
63-
github.com/moby/sys/user v0.3.0 // indirect
67+
github.com/moby/sys/sequential v0.6.0 // indirect
68+
github.com/moby/sys/user v0.4.0 // indirect
6469
github.com/moby/sys/userns v0.1.0 // indirect
6570
github.com/moby/term v0.5.0 // indirect
6671
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -71,10 +76,10 @@ require (
7176
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7277
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
7378
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
74-
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
79+
github.com/shirou/gopsutil/v4 v4.25.6 // indirect
7580
github.com/sirupsen/logrus v1.9.3 // indirect
76-
github.com/testcontainers/testcontainers-go v0.37.0 // indirect
77-
github.com/testcontainers/testcontainers-go/modules/postgres v0.37.0 // indirect
81+
github.com/testcontainers/testcontainers-go v0.40.0 // indirect
82+
github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0 // indirect
7883
github.com/tklauser/go-sysconf v0.3.12 // indirect
7984
github.com/tklauser/numcpus v0.6.1 // indirect
8085
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
@@ -90,9 +95,10 @@ require (
9095
go.opentelemetry.io/otel/trace v1.40.0 // indirect
9196
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
9297
golang.org/x/crypto v0.48.0 // indirect
93-
golang.org/x/net v0.49.0 // indirect
9498
golang.org/x/sync v0.19.0 // indirect
9599
golang.org/x/sys v0.41.0 // indirect
96100
golang.org/x/text v0.34.0 // indirect
101+
google.golang.org/genproto/googleapis/api v0.0.0-20260217215200-42d3e9bedb6d // indirect
102+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d // indirect
97103
gopkg.in/yaml.v3 v3.0.1 // indirect
98104
)

0 commit comments

Comments
 (0)