mirror of
https://github.com/aljazceru/satdress.git
synced 2025-12-17 13:34:21 +01:00
test invoice has pin in its description.
fixes https://github.com/fiatjaf/satdress/issues/12
This commit is contained in:
4
db.go
4
db.go
@@ -40,8 +40,10 @@ func SaveName(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params.Name = name
|
||||||
|
|
||||||
// check if the given data works
|
// check if the given data works
|
||||||
if inv, err = makeInvoice(params, 1000); err != nil {
|
if inv, err = makeInvoice(params, 1000, &pin); err != nil {
|
||||||
return "", "", fmt.Errorf("couldn't make an invoice with the given data: %w", err)
|
return "", "", fmt.Errorf("couldn't make an invoice with the given data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="kind"> Node Backend Type </label>
|
<label for="kind"> Node Backend Type </label>
|
||||||
<select name="kind" id="kind" id="kind" v-model="kind">
|
<select name="kind" id="kind" id="kind" v-model="kind">
|
||||||
|
<option disabled value="">Please select one:</option>
|
||||||
<option value="lnd">LND</option>
|
<option value="lnd">LND</option>
|
||||||
<option value="sparko">Sparko</option>
|
<option value="sparko">Sparko</option>
|
||||||
<option value="lnpay">LNPay</option>
|
<option value="lnpay">LNPay</option>
|
||||||
@@ -136,6 +137,10 @@
|
|||||||
isNew: true,
|
isNew: true,
|
||||||
...initial
|
...initial
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.kind = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
lnurl.go
2
lnurl.go
@@ -45,7 +45,7 @@ func handleLNURL(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bolt11, err := makeInvoice(params, msat)
|
bolt11, err := makeInvoice(params, msat, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
json.NewEncoder(w).Encode(
|
json.NewEncoder(w).Encode(
|
||||||
lnurl.ErrorResponse("failed to create invoice: " + err.Error()))
|
lnurl.ErrorResponse("failed to create invoice: " + err.Error()))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -22,10 +22,11 @@ func makeMetadata(params *Params) string {
|
|||||||
return metadata
|
return metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeInvoice(params *Params, msat int) (bolt11 string, err error) {
|
func makeInvoice(
|
||||||
// description_hash
|
params *Params,
|
||||||
h := sha256.Sum256([]byte(makeMetadata(params)))
|
msat int,
|
||||||
|
pin *string,
|
||||||
|
) (bolt11 string, err error) {
|
||||||
// prepare params
|
// prepare params
|
||||||
var backend makeinvoice.BackendParams
|
var backend makeinvoice.BackendParams
|
||||||
switch params.Kind {
|
switch params.Kind {
|
||||||
@@ -51,17 +52,29 @@ func makeInvoice(params *Params, msat int) (bolt11 string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Int("msatoshi", msat).
|
mip := makeinvoice.Params{
|
||||||
Interface("backend", backend).
|
Msatoshi: int64(msat),
|
||||||
Str("description_hash", hex.EncodeToString(h[:])).
|
Backend: backend,
|
||||||
Msg("generating invoice")
|
|
||||||
|
|
||||||
// actually generate the invoice
|
|
||||||
return makeinvoice.MakeInvoice(makeinvoice.Params{
|
|
||||||
Msatoshi: int64(msat),
|
|
||||||
DescriptionHash: h[:],
|
|
||||||
Backend: backend,
|
|
||||||
|
|
||||||
Label: s.Domain + "/" + strconv.FormatInt(time.Now().Unix(), 16),
|
Label: s.Domain + "/" + strconv.FormatInt(time.Now().Unix(), 16),
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if pin != nil {
|
||||||
|
// use this as the description
|
||||||
|
mip.Description = fmt.Sprintf("%s's PIN for '%s@%s' lightning address: %s", s.Domain, params.Name, s.Domain, *pin)
|
||||||
|
} else {
|
||||||
|
// make the lnurlpay description_hash
|
||||||
|
h := sha256.Sum256([]byte(makeMetadata(params)))
|
||||||
|
mip.DescriptionHash = h[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// actually generate the invoice
|
||||||
|
bolt11, err = makeinvoice.MakeInvoice(mip)
|
||||||
|
|
||||||
|
log.Debug().Int("msatoshi", msat).
|
||||||
|
Interface("backend", backend).
|
||||||
|
Str("bolt11", bolt11).Err(err).
|
||||||
|
Msg("invoice generation")
|
||||||
|
|
||||||
|
return bolt11, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ body {
|
|||||||
padding: 60px 20px 40px 20px;
|
padding: 60px 20px 40px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
|||||||
Reference in New Issue
Block a user