nip34: get patches from repo.

This commit is contained in:
fiatjaf 2024-02-08 16:33:52 -03:00
parent 9c4ea87d0b
commit c362be0e82
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 21 additions and 2 deletions

2
go.mod
View File

@ -3,6 +3,7 @@ module github.com/nbd-wtf/go-nostr
go 1.21
require (
github.com/bluekeyes/go-gitdiff v0.7.1
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/gobwas/httphead v0.1.0
@ -20,7 +21,6 @@ require (
require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/bluekeyes/go-gitdiff v0.7.1 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect

View File

@ -1,6 +1,11 @@
package nip34
import "github.com/nbd-wtf/go-nostr"
import (
"context"
"fmt"
"github.com/nbd-wtf/go-nostr"
)
type Repository struct {
nostr.Event
@ -40,3 +45,17 @@ func ParseRepository(event nostr.Event) Repository {
return repo
}
func (repo Repository) GetPatchesSync(ctx context.Context, s nostr.RelayStore) []Patch {
res, _ := s.QuerySync(ctx, nostr.Filter{
Kinds: []int{nostr.KindPatch},
Tags: nostr.TagMap{
"a": []string{fmt.Sprintf("%d:%s:%s", nostr.KindRepositoryAnnouncement, repo.Event.PubKey, repo.ID)},
},
})
patches := make([]Patch, len(res))
for i, evt := range res {
patches[i] = ParsePatch(*evt)
}
return patches
}