mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-11 05:13:47 +02:00
nip60: expose GetSatoshisAmountFromBolt11() helper.
This commit is contained in:
@@ -200,7 +200,7 @@ func parseKeysetKeys(keys nut01.KeysMap) (map[uint64]*btcec.PublicKey, error) {
|
|||||||
return parsedKeys, nil
|
return parsedKeys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSatoshisAmountFromBolt11(bolt11 string) (uint64, error) {
|
func GetSatoshisAmountFromBolt11(bolt11 string) (uint64, error) {
|
||||||
if len(bolt11) < 50 {
|
if len(bolt11) < 50 {
|
||||||
return 0, fmt.Errorf("invalid invoice, too short")
|
return 0, fmt.Errorf("invalid invoice, too short")
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ func TestBolt11Parsing(t *testing.T) {
|
|||||||
{"lnbc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 0, false},
|
{"lnbc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 0, false},
|
||||||
} {
|
} {
|
||||||
t.Run(fmt.Sprintf("%d = %s", tc.sats, tc.bolt11), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d = %s", tc.sats, tc.bolt11), func(t *testing.T) {
|
||||||
sats, err := getSatoshisAmountFromBolt11(tc.bolt11)
|
sats, err := GetSatoshisAmountFromBolt11(tc.bolt11)
|
||||||
if tc.hasError {
|
if tc.hasError {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -21,7 +21,7 @@ func (w *Wallet) PayBolt11(ctx context.Context, invoice string, opts ...SendOpti
|
|||||||
opt(ss)
|
opt(ss)
|
||||||
}
|
}
|
||||||
|
|
||||||
invoiceAmount, err := getSatoshisAmountFromBolt11(invoice)
|
invoiceAmount, err := GetSatoshisAmountFromBolt11(invoice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user