89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
b64 "encoding/base64"
|
|
"encoding/hex"
|
|
"fmt"
|
|
|
|
"git.minhas.io/asara/well-goknown/config"
|
|
"git.minhas.io/asara/well-goknown/logger"
|
|
"git.minhas.io/asara/well-goknown/redis"
|
|
"github.com/davecgh/go-spew/spew"
|
|
"github.com/lightninglabs/lndclient"
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func main() {
|
|
var err error
|
|
ctx := context.TODO()
|
|
l := logger.Get()
|
|
redis.NostrRedisConn, err = redis.New("localhost:6379", "", redis.NostrKeyspace)
|
|
if err != nil {
|
|
l.Fatal().Msg("unable to connect to redis")
|
|
}
|
|
redis.LndRedisConn, err = redis.New("localhost:6379", "", redis.LndKeyspace)
|
|
if err != nil {
|
|
l.Fatal().Msg("unable to connect to redis")
|
|
}
|
|
/*
|
|
// Test to add requests directly to nostr for easy bootstrap/general laziness
|
|
nostrTest := nostr.NostrRequest{
|
|
Name: "asara",
|
|
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
|
|
Hostname: "devvul.com",
|
|
}
|
|
nostr.AddNostrAddr(nostrTest)
|
|
*/
|
|
|
|
macaroon := config.GetConfig().LndMacaroonHex
|
|
addr := config.GetConfig().LndAddr
|
|
dec, _ := b64.StdEncoding.DecodeString(config.GetConfig().LndCertB64)
|
|
lndCert := string(dec)
|
|
lndCli, err := lndclient.NewBasicClient(addr, "", "", "bitcoind", lndclient.MacaroonData(macaroon), lndclient.TLSData(lndCert))
|
|
if err != nil {
|
|
l.Fatal().Msg("unable to connect to lnd")
|
|
}
|
|
|
|
// get requested keys
|
|
lndRedisCli := redis.LndRedisConn.Client
|
|
//nostrRedisCli := redis.NostrRedisConn.Client
|
|
|
|
requestedKeys := lndRedisCli.Keys(ctx, "requested:*")
|
|
for _, key := range requestedKeys.Val() {
|
|
value, err := lndRedisCli.Get(ctx, key).Result()
|
|
if err != nil {
|
|
l.Error().Msg(fmt.Sprintf("%s: unable to get key", key))
|
|
}
|
|
rHash, err := hex.DecodeString(value)
|
|
if err != nil {
|
|
l.Error().Msg(fmt.Sprintf("%s: unable to decode hash for key", key))
|
|
}
|
|
|
|
invoice, err := lndCli.LookupInvoice(ctx, &lnrpc.PaymentHash{
|
|
RHash: rHash,
|
|
})
|
|
if err != nil {
|
|
switch status.Code(err) {
|
|
case codes.NotFound:
|
|
l.Error().Msg(fmt.Sprintf("%s: expired", key))
|
|
continue
|
|
default:
|
|
l.Error().Msg(fmt.Sprintf("%s: unknown error", key))
|
|
continue
|
|
}
|
|
}
|
|
|
|
if invoice.Settled {
|
|
// move requested to verified on nostr redis keyspace
|
|
// delete current key
|
|
continue
|
|
}
|
|
spew.Dump(invoice)
|
|
spew.Dump(key)
|
|
spew.Dump(value)
|
|
}
|
|
}
|