Jay 496112e0e0 Fix deadlock by buffering return values.
Remove standalone error return value.
2026-03-05 16:54:53 -05:00
2026-03-05 09:36:36 -05:00
2026-03-02 14:50:27 -05:00
2026-03-05 09:36:36 -05:00
2026-03-05 00:28:40 -05:00

Go-Heartwood - Nostr Event Storage for Neo4j

Source: https://git.wisehodl.dev/jay/go-heartwood

Mirror: https://github.com/wisehodl/go-heartwood

This library is in active development and not yet ready for use.

go-heartwood is a Neo4j-based event storage layer for Nostr events. It stores events as nodes in a graph and foreign-key references as relationships.

Installation

Add go-heartwood to your project:

go get git.wisehodl.dev/jay/go-heartwood

If the primary repository is unavailable, use the replace directive in your go.mod file to get the package from the github mirror:

replace git.wisehodl.dev/jay/go-heartwood => github.com/wisehodl/go-heartwood latest

Usage

Further usage examples will be added as the API stabilizes.

Writing Events

package main

import (
	"context"
	"encoding/json"
	"log"

	"git.wisehodl.dev/jay/go-roots/events"
	"git.wisehodl.dev/jay/go-roots/keys"
	"git.wisehodl.dev/jay/go-heartwood"

	"github.com/boltdb/bolt"
)

func main() {
	ctx := context.Background()

	// Connect to Neo4j
	driver, err := heartwood.ConnectNeo4j(ctx, "bolt://localhost:7687", "neo4j", "password")
	if err != nil {
		log.Fatal(err)
	}
	defer driver.Close(ctx)

    // Ensure the necessary indexes and constraints exist
	if err := heartwood.SetNeo4jSchema(ctx, driver); err != nil {
		log.Fatal(err)
	}

	// Open BoltDB
	boltdb, err := bolt.Open("events.db", 0600, nil)
	if err != nil {
		log.Fatal(err)
	}
	defer boltdb.Close()

	// Build events using go-roots
	sk, _ := keys.GeneratePrivateKey()
	pk, _ := keys.GetPublicKey(sk)

	event := events.Event{
		PubKey:    pk,
		CreatedAt: 1000,
		Kind:      1,
		Content:   "hello from heartwood",
		Tags:      []events.Tag{},
	}
	event.ID, _ = events.GenerateEventID(event)
	event.Sig, _ = events.SignEvent(event, sk)

	eventJSON, _ := json.Marshal(event)

	// Write events
	report, err := heartwood.WriteEvents(
		[][]byte{eventJSON},
		driver, boltdb,
		nil, // default WriteOptions
	)
	if err != nil {
		log.Fatal(err)
	}

    log.Printf("created: %d, excluded: %d, duration: %s",
        report.CreatedEventCount,
        len(report.ExcludedEvents),
        report.Duration,
    )
}

Testing

Run tests with:

go test ./...

Run with race detector:

go test -race ./...
Description
Nostr Graph Event Storage Library written in Golang
Readme 171 KiB
Languages
Go 100%