mirror of
https://github.com/muun/recovery.git
synced 2025-11-11 22:40:16 -05:00
Release v0.3.0
This commit is contained in:
30
vendor/github.com/muun/libwallet/invoice.go
generated
vendored
30
vendor/github.com/muun/libwallet/invoice.go
generated
vendored
@@ -1,8 +1,7 @@
|
||||
package libwallet
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
"github.com/pkg/errors"
|
||||
@@ -18,16 +17,29 @@ type Invoice struct {
|
||||
PaymentHash []byte
|
||||
Expiry int64
|
||||
Description string
|
||||
Sats int64
|
||||
}
|
||||
|
||||
const lightningScheme = "lightning:"
|
||||
|
||||
// ParseInvoice parses an Invoice from an invoice string and a network
|
||||
func ParseInvoice(invoice string, network *Network) (*Invoice, error) {
|
||||
func ParseInvoice(rawInput string, network *Network) (*Invoice, error) {
|
||||
|
||||
if strings.HasPrefix(strings.ToLower(invoice), lightningScheme) {
|
||||
// Remove lightning scheme from rawInvoice
|
||||
invoice = invoice[len(lightningScheme):]
|
||||
_, components := buildUriFromString(rawInput, lightningScheme)
|
||||
if components == nil {
|
||||
return nil, errors.Errorf("failed to parse uri %v", rawInput)
|
||||
}
|
||||
|
||||
if components.Scheme != "lightning" {
|
||||
return nil, errors.Errorf("invalid scheme %v", components.Scheme)
|
||||
}
|
||||
|
||||
invoice := components.Opaque
|
||||
|
||||
// When URIs are scheme:// the address comes in host
|
||||
// this happens in iOS that mostly ignores scheme: format
|
||||
if len(invoice) == 0 {
|
||||
invoice = components.Host
|
||||
}
|
||||
|
||||
parsedInvoice, err := zpay32.Decode(invoice, network.network)
|
||||
@@ -50,8 +62,11 @@ func ParseInvoice(invoice string, network *Network) (*Invoice, error) {
|
||||
}
|
||||
|
||||
var milliSats string
|
||||
var sats int64
|
||||
if parsedInvoice.MilliSat != nil {
|
||||
milliSats = fmt.Sprintf("%v", uint64(*parsedInvoice.MilliSat))
|
||||
milliSat := uint64(*parsedInvoice.MilliSat)
|
||||
milliSats = fmt.Sprintf("%v", milliSat)
|
||||
sats = int64(milliSat / 1000)
|
||||
}
|
||||
|
||||
return &Invoice{
|
||||
@@ -63,5 +78,6 @@ func ParseInvoice(invoice string, network *Network) (*Invoice, error) {
|
||||
PaymentHash: parsedInvoice.PaymentHash[:],
|
||||
Expiry: parsedInvoice.Timestamp.Unix() + int64(parsedInvoice.Expiry().Seconds()),
|
||||
Description: description,
|
||||
Sats: sats,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user