mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-18 03:22:22 +02:00
negentropy.
- a way to handle custom messages from Relay (NEG-whatever etc) - negentropy implementation (adapted from that other one) - nip77 nostr negentropy extension - QueryEvents method for RelayStore that returns a channel (makes negentropy syncing work more seamlessly)
This commit is contained in:
61
nip77/example/example.go
Normal file
61
nip77/example/example.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/fiatjaf/eventstore"
|
||||
"github.com/fiatjaf/eventstore/slicestore"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nip77"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
db := &slicestore.SliceStore{}
|
||||
db.Init()
|
||||
|
||||
sk := nostr.GeneratePrivateKey()
|
||||
local := eventstore.RelayWrapper{Store: db}
|
||||
|
||||
for {
|
||||
for i := 0; i < 20; i++ {
|
||||
{
|
||||
evt := nostr.Event{
|
||||
Kind: 1,
|
||||
Content: fmt.Sprintf("same old hello %d", i),
|
||||
CreatedAt: nostr.Timestamp(i),
|
||||
Tags: nostr.Tags{},
|
||||
}
|
||||
evt.Sign(sk)
|
||||
db.SaveEvent(ctx, &evt)
|
||||
}
|
||||
|
||||
{
|
||||
evt := nostr.Event{
|
||||
Kind: 1,
|
||||
Content: fmt.Sprintf("custom hello %d", i),
|
||||
CreatedAt: nostr.Now(),
|
||||
Tags: nostr.Tags{},
|
||||
}
|
||||
evt.Sign(sk)
|
||||
db.SaveEvent(ctx, &evt)
|
||||
}
|
||||
}
|
||||
|
||||
err := nip77.NegentropySync(ctx,
|
||||
local, "ws://localhost:7777", nostr.Filter{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
data, err := local.QuerySync(ctx, nostr.Filter{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("total local events:", len(data))
|
||||
time.Sleep(time.Second * 10)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user