sdk: beginnings of basic wot helpers.

This commit is contained in:
fiatjaf
2025-03-28 21:49:26 -03:00
parent 6fc68dc039
commit 0d5daf66bf
3 changed files with 50 additions and 0 deletions

44
sdk/wot.go Normal file
View 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)))
}