1
0
mirror of https://github.com/fiatjaf/nak.git synced 2025-07-28 07:58:29 -04:00
Files
.github
.gitignore
LICENSE
README.md
bunker.go
count.go
curl.go
decode.go
encode.go
encrypt_decrypt.go
event.go
example_test.go
fetch.go
flags.go
go.mod
go.sum
helpers.go
helpers_key.go
key.go
main.go
mcp.go
musig2.go
outbox.go
relay.go
req.go
serve.go
verify.go
wallet.go
zapstore.yaml
nak/outbox.go

69 lines
1.7 KiB
Go

package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/urfave/cli/v3"
"github.com/nbd-wtf/go-nostr"
)
var outbox = &cli.Command{
Name: "outbox",
Usage: "manage outbox relay hints database",
DisableSliceFlagSeparator: true,
Commands: []*cli.Command{
{
Name: "init",
Usage: "initialize the outbox hints database",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error {
if hintsFileExists {
return nil
}
if hintsFilePath == "" {
return fmt.Errorf("couldn't find a place to store the hints, pass --config-path to fix.")
}
if err := os.MkdirAll(filepath.Dir(hintsFilePath), 0777); err == nil {
if err := os.WriteFile(hintsFilePath, []byte("{}"), 0644); err != nil {
return fmt.Errorf("failed to create hints database: %w", err)
}
}
log("initialized hints database at %s\n", hintsFilePath)
return nil
},
},
{
Name: "list",
Usage: "list outbox relays for a given pubkey",
ArgsUsage: "<pubkey>",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error {
if !hintsFileExists {
log("running with temporary fragile data.\n")
log("call `nak outbox init` to setup persistence.\n")
}
if c.Args().Len() != 1 {
return fmt.Errorf("expected exactly one argument (pubkey)")
}
pubkey := c.Args().First()
if !nostr.IsValidPublicKey(pubkey) {
return fmt.Errorf("invalid public key: %s", pubkey)
}
for _, relay := range sys.FetchOutboxRelays(ctx, pubkey, 6) {
stdout(relay)
}
return nil
},
},
},
}