mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-11 05:13:47 +02:00
nip61, and related modifications to nip60.
This commit is contained in:
36
nip60/send-external.go
Normal file
36
nip60/send-external.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user