nip61, and related modifications to nip60.

This commit is contained in:
fiatjaf
2025-02-02 18:16:46 -03:00
parent c9f670d700
commit d0f53b3b7a
11 changed files with 327 additions and 59 deletions

36
nip60/send-external.go Normal file
View File

@@ -0,0 +1,36 @@
package nip60
import (
"context"
"fmt"
"github.com/elnosh/gonuts/cashu"
"github.com/elnosh/gonuts/cashu/nuts/nut04"
"github.com/nbd-wtf/go-nostr/nip60/client"
)
func (w *Wallet) SendExternal(
ctx context.Context,
mint string,
targetAmount uint64,
opts ...SendOption,
) (cashu.Proofs, error) {
if w.wl.PublishUpdate == nil {
return nil, fmt.Errorf("can't do write operations: missing PublishUpdate function")
}
// get the invoice from target mint
mintResp, err := client.PostMintQuoteBolt11(ctx, mint, nut04.PostMintQuoteBolt11Request{
Unit: cashu.Sat.String(),
Amount: targetAmount,
})
if err != nil {
return nil, fmt.Errorf("failed to generate mint quote: %w", err)
}
if _, err := w.PayBolt11(ctx, mintResp.Request, opts...); err != nil {
return nil, err
}
return redeemMinted(ctx, mint, mintResp.Quote, targetAmount)
}