From 59ac03f08de000ad736fdfaacaab5521c47eb2f6 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 9 Dec 2023 14:42:35 -0300 Subject: [PATCH] update RelayInterface() to match new go-nostr API. --- go.mod | 2 +- go.sum | 4 ++-- relay_interface.go | 19 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index c5ab93c..c4ab6af 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/lib/pq v1.10.9 github.com/mailru/easyjson v0.7.7 github.com/mattn/go-sqlite3 v1.14.18 - github.com/nbd-wtf/go-nostr v0.25.3 + github.com/nbd-wtf/go-nostr v0.27.0 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.7 golang.org/x/exp v0.0.0-20231006140011-7918f672742d diff --git a/go.sum b/go.sum index 81024c7..b2ed238 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI= github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= -github.com/nbd-wtf/go-nostr v0.25.3 h1:RPPh4cOosw0OZi5KG627pZ3GlKxiKsjARluzen/mB9g= -github.com/nbd-wtf/go-nostr v0.25.3/go.mod h1:bkffJI+x914sPQWum9ZRUn66D7NpDnAoWo1yICvj3/0= +github.com/nbd-wtf/go-nostr v0.27.0 h1:h6JmMMmfNcAORTL2kk/K3+U6Mju6rk/IjcHA/PMeOc8= +github.com/nbd-wtf/go-nostr v0.27.0/go.mod h1:bkffJI+x914sPQWum9ZRUn66D7NpDnAoWo1yICvj3/0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/relay_interface.go b/relay_interface.go index c79515a..ac4a925 100644 --- a/relay_interface.go +++ b/relay_interface.go @@ -9,7 +9,7 @@ import ( // RelayInterface is a wrapper thing that unifies Store and nostr.Relay under a common API. type RelayInterface interface { - Publish(ctx context.Context, event nostr.Event) (nostr.Status, error) + Publish(ctx context.Context, event nostr.Event) error QuerySync(ctx context.Context, filter nostr.Filter, opts ...nostr.SubscriptionOption) ([]*nostr.Event, error) } @@ -19,19 +19,19 @@ type RelayWrapper struct { var _ RelayInterface = (*RelayWrapper)(nil) -func (w RelayWrapper) Publish(ctx context.Context, evt nostr.Event) (nostr.Status, error) { +func (w RelayWrapper) Publish(ctx context.Context, evt nostr.Event) error { if 20000 <= evt.Kind && evt.Kind < 30000 { // do not store ephemeral events - return nostr.PublishStatusSucceeded, nil + return nil } else if evt.Kind == 0 || evt.Kind == 3 || (10000 <= evt.Kind && evt.Kind < 20000) { // replaceable event, delete before storing ch, err := w.Store.QueryEvents(ctx, nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}}) if err != nil { - return nostr.PublishStatusFailed, fmt.Errorf("failed to query before replacing: %w", err) + return fmt.Errorf("failed to query before replacing: %w", err) } if previous := <-ch; previous != nil && isOlder(previous, &evt) { if err := w.Store.DeleteEvent(ctx, previous); err != nil { - return nostr.PublishStatusFailed, fmt.Errorf("failed to delete event for replacing: %w", err) + return fmt.Errorf("failed to delete event for replacing: %w", err) } } } else if 30000 <= evt.Kind && evt.Kind < 40000 { @@ -40,22 +40,21 @@ func (w RelayWrapper) Publish(ctx context.Context, evt nostr.Event) (nostr.Statu if d != nil { ch, err := w.Store.QueryEvents(ctx, nostr.Filter{Authors: []string{evt.PubKey}, Kinds: []int{evt.Kind}, Tags: nostr.TagMap{"d": []string{d.Value()}}}) if err != nil { - return nostr.PublishStatusFailed, fmt.Errorf("failed to query before parameterized replacing: %w", err) + return fmt.Errorf("failed to query before parameterized replacing: %w", err) } if previous := <-ch; previous != nil && isOlder(previous, &evt) { if err := w.Store.DeleteEvent(ctx, previous); err != nil { - return nostr.PublishStatusFailed, - fmt.Errorf("failed to delete event for parameterized replacing: %w", err) + return fmt.Errorf("failed to delete event for parameterized replacing: %w", err) } } } } if err := w.SaveEvent(ctx, &evt); err != nil && err != ErrDupEvent { - return nostr.PublishStatusFailed, fmt.Errorf("failed to save: %w", err) + return fmt.Errorf("failed to save: %w", err) } - return nostr.PublishStatusSucceeded, nil + return nil } func (w RelayWrapper) QuerySync(ctx context.Context, filter nostr.Filter, opts ...nostr.SubscriptionOption) ([]*nostr.Event, error) {