Release v0.3.0

This commit is contained in:
Manu Herrera
2020-11-09 10:05:29 -03:00
parent 4e9aa7a3c5
commit 8107c4478b
1265 changed files with 440488 additions and 107809 deletions

View File

@@ -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
}