mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-25 16:21:00 +02:00
sdk: beginnings of basic wot helpers.
This commit is contained in:
parent
6fc68dc039
commit
0d5daf66bf
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module github.com/nbd-wtf/go-nostr
|
||||
go 1.24.1
|
||||
|
||||
require (
|
||||
github.com/FastFilter/xorfilter v0.2.1
|
||||
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3
|
||||
github.com/PowerDNS/lmdb-go v1.9.3
|
||||
github.com/bluekeyes/go-gitdiff v0.7.1
|
||||
@ -33,6 +34,7 @@ require (
|
||||
golang.org/x/crypto v0.36.0
|
||||
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
|
||||
golang.org/x/net v0.37.0
|
||||
golang.org/x/sync v0.12.0
|
||||
golang.org/x/text v0.23.0
|
||||
modernc.org/sqlite v1.33.1
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -8,6 +8,8 @@ github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25Yn
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/FastFilter/xorfilter v0.2.1 h1:lbdeLG9BdpquK64ZsleBS8B4xO/QW1IM0gMzF7KaBKc=
|
||||
github.com/FastFilter/xorfilter v0.2.1/go.mod h1:aumvdkhscz6YBZF9ZA/6O4fIoNod4YR50kIVGGZ7l9I=
|
||||
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3 h1:ClzzXMDDuUbWfNNZqGeYq4PnYOlwlOVIvSyNaIy0ykg=
|
||||
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3/go.mod h1:we0YA5CsBbH5+/NUzC/AlMmxaDtWlXeNsqrwXjTzmzA=
|
||||
github.com/PowerDNS/lmdb-go v1.9.3 h1:AUMY2pZT8WRpkEv39I9Id3MuoHd+NZbTVpNhruVkPTg=
|
||||
@ -55,6 +57,8 @@ github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4
|
||||
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
||||
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
|
44
sdk/wot.go
Normal file
44
sdk/wot.go
Normal file
@ -0,0 +1,44 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"maps"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/FastFilter/xorfilter"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (sys *System) GetWoT(ctx context.Context, pubkey string) (map[uint64]struct{}, error) {
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
res := make(chan uint64)
|
||||
for _, f := range sys.FetchFollowList(ctx, pubkey).Items {
|
||||
g.Go(func() error {
|
||||
for _, f2 := range sys.FetchFollowList(ctx, f.Pubkey).Items {
|
||||
shid, _ := strconv.ParseUint(f2.Pubkey[32:48], 16, 64)
|
||||
res <- shid
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
result := make(map[uint64]struct{})
|
||||
go func() {
|
||||
for shid := range res {
|
||||
result[shid] = struct{}{}
|
||||
}
|
||||
}()
|
||||
|
||||
return result, g.Wait()
|
||||
}
|
||||
|
||||
func (sys *System) GetWoTFilter(ctx context.Context, pubkey string) (*xorfilter.Xor8, error) {
|
||||
m, err := sys.GetWoT(ctx, pubkey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return xorfilter.Populate(slices.Collect(maps.Keys(m)))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user