Skip to content

Commit

Permalink
support lnpay, check invoice before saving params.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Aug 14, 2021
1 parent 3bb1c40 commit 5826f5e
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 22 deletions.
10 changes: 10 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

type Params struct {
Name string
Kind string
Host string
Key string
Pak string
Waki string
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/cockroachdb/pebble v0.0.0-20210812144839-61318a019370
github.com/fiatjaf/go-lnurl v1.4.0
github.com/fiatjaf/makeinvoice v1.1.0
github.com/fiatjaf/makeinvoice v1.2.0
github.com/gorilla/mux v1.8.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.10.2
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/fiatjaf/lightningd-gjson-rpc v1.4.0 h1:Iv5tt4YuNoSMfR39wiV0tqnHYTJ85o
github.com/fiatjaf/lightningd-gjson-rpc v1.4.0/go.mod h1:SQGA0qcY2qypaMXDQlE5V5+2MnLZzQ7NzfRsScliFeE=
github.com/fiatjaf/ln-decodepay v1.0.0 h1:1YUMjvLock+BicMNwoZ/OA3oG2ZYEaJ8AzdS6EGVMTQ=
github.com/fiatjaf/ln-decodepay v1.0.0/go.mod h1:/LWK+ZUa3i8MqbRjIMAiVQS2+NbhwKWlwib2n446cMQ=
github.com/fiatjaf/makeinvoice v1.0.1 h1:tPGEBeAVU6hZWDf/nQRAMyDELWVRUJWbzJ4WiRh9Kpg=
github.com/fiatjaf/makeinvoice v1.0.1/go.mod h1:3BkUQoA+VZeR4qQbK3qN+KQrh96z5dMNBMuKfdxSBE0=
github.com/fiatjaf/makeinvoice v1.2.0 h1:lWvjFyMq3R9yzln/I67Ex2/c0cBUiuWS4WEc32AWuNc=
github.com/fiatjaf/makeinvoice v1.2.0/go.mod h1:R+p/0XfRNob2hu+nyIiC2xaSy/HcdQ21rbNNuUHRB70=
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -191,6 +191,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
github.com/imroc/req v0.3.0 h1:3EioagmlSG+z+KySToa+Ylo3pTFZs+jh3Brl7ngU12U=
github.com/imroc/req v0.3.0/go.mod h1:F+NZ+2EFSo6EFXdeIbpfE9hcC233id70kf0byW97Caw=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
Expand Down Expand Up @@ -259,6 +261,8 @@ github.com/lightningnetwork/lnd/queue v1.0.3 h1:5ufYVE7lh9GJnL1wOoeO3bZ3aAHWNnkN
github.com/lightningnetwork/lnd/queue v1.0.3/go.mod h1:YTkTVZCxz8tAYreH27EO3s8572ODumWrNdYW2E/YKxg=
github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU=
github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXjoksPNvGNYowB8aRbpX0=
github.com/lnpay/lnpay-go v1.1.0 h1:8nj5Nk42MNWE0PjeUnvBWqK9HP22khNOULljbD+N78g=
github.com/lnpay/lnpay-go v1.1.0/go.mod h1:9R+L95XntdDXkU59ZzAozn7K/1nKsRfnuzu8QsSSzM8=
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1sNPI5H8P3NkTFF4LuwMdPl2DodF60qAKqY=
github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
Expand Down
98 changes: 88 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,112 @@
<!doctype html>

<style>
main {
display: flex;
flex-wrap: wrap;
}
form {
display: block;
padding: 20px;
margin: 20px;
border: dotted 2px grey;
}
label {
display: block;
}
</style>

<form action="/grab" method="post">
<form action=/grab method=post>
<label>
kind
<input readonly name=kind value=lnd>
</label>

<label>
desired username
<input name=name>
</label>

<label>
host
<input name=host>
</label>

<label>
macaroon
<input name=key>
</label>

<button>submit</button>
</form>

<form action=/grab method=post>
<label>
kind
<input readonly name=kind value=sparko>
</label>

<label>
desired username
<input name="name">
<input name=name>
</label>

<label>
host
<input name=host>
</label>

<label>
key
<input name=key>
</label>

<button>submit</button>
</form>

<form action=/grab method=post>
<label>
kind
<select name="kind">
<option>lnd</option>
<option>sparko</option>
<option>lnbits</option>
</select>
<input readonly name=kind value=lnbits>
</label>

<label>
desired username
<input name=name>
</label>

<label>
host
<input name="host">
<input name=host>
</label>

<label>
key
<input name=key>
</label>

<button>submit</button>
</form>

<form action=/grab method=post>
<label>
kind
<input readonly name=kind value=lnpay>
</label>

<label>
desired username
<input name=name>
</label>

<label>
pak
<input name=pak>
</label>

<label>
key or macaroon
<input name="key">
waki
<input name=waki>
</label>

<button>submit</button>
Expand Down
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,23 @@ func main() {
closer.Close()
}

data, _ := json.Marshal(Params{
params := Params{
Kind: r.FormValue("kind"),
Host: r.FormValue("host"),
Key: r.FormValue("key"),
})
Pak: r.FormValue("pak"),
Waki: r.FormValue("waki"),
}

// check if the given data works
if _, err := makeInvoice(params, 1000); err != nil {
w.WriteHeader(400)
fmt.Fprint(w, "couldn't make an invoice with the given data: "+err.Error())
return
}

// save it
data, _ := json.Marshal(params)
if err := db.Set(name, data, pebble.Sync); err != nil {
w.WriteHeader(500)
fmt.Fprint(w, "error! "+err.Error())
Expand Down
12 changes: 5 additions & 7 deletions makeinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import (
"github.com/tidwall/sjson"
)

type Params struct {
Name string
Kind string
Host string
Key string
}

func makeMetadata(params Params) string {
metadata, _ := sjson.Set("[]", "0.0", "text/identifier")
metadata, _ = sjson.Set(metadata, "0.1", params.Name+"@"+s.Domain)
Expand Down Expand Up @@ -50,6 +43,11 @@ func makeInvoice(params Params, msat int) (bolt11 string, err error) {
Host: params.Host,
Key: params.Key,
}
case "lnpay":
backend = makeinvoice.LNPayParams{
PublicAccessKey: params.Pak,
WalletInvoiceKey: params.Waki,
}
}

// actually generate the invoice
Expand Down

0 comments on commit 5826f5e

Please sign in to comment.