mirror of
https://github.com/aljazceru/khatru.git
synced 2026-01-29 18:04:21 +01:00
fix expensive relay invoice handler
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func handleWebpage(w http.ResponseWriter, r *http.Request) {
|
||||
func handleWebpage(w http.ResponseWriter, rq *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`
|
||||
<meta charset=utf-8>
|
||||
@@ -53,9 +53,9 @@ body {
|
||||
`))
|
||||
}
|
||||
|
||||
func handleInvoice(w http.ResponseWriter, r *http.Request) {
|
||||
func handleInvoice(w http.ResponseWriter, rq *http.Request, r *Relay) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
invoice, err := generateInvoice(r.URL.Query().Get("pubkey"))
|
||||
invoice, err := generateInvoice(r, rq.URL.Query().Get("pubkey"))
|
||||
if err != nil {
|
||||
json.NewEncoder(w).Encode(struct {
|
||||
Error string `json:"error"`
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func generateLabel(pubkey string) string { return fmt.Sprintf("relayer-expensive:ticket:%s", pubkey) }
|
||||
|
||||
func generateInvoice(pubkey string) (string, error) {
|
||||
func generateInvoice(r *Relay, pubkey string) (string, error) {
|
||||
cln := lnsocket.LNSocket{}
|
||||
cln.GenKey()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
"net/http"
|
||||
|
||||
"github.com/fiatjaf/relayer"
|
||||
"github.com/fiatjaf/relayer/storage/postgresql"
|
||||
@@ -49,9 +50,13 @@ func (r *Relay) Init() error {
|
||||
func (r *Relay) OnInitialized(s *relayer.Server) {
|
||||
// special handlers
|
||||
s.Router().Path("/").HandlerFunc(handleWebpage)
|
||||
s.Router().Path("/invoice").HandlerFunc(handleInvoice)
|
||||
s.Router().Path("/invoice").HandlerFunc(func(w http.ResponseWriter, rq *http.Request) {
|
||||
handleInvoice(w, rq, r)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (r *Relay) AcceptEvent(evt *nostr.Event) bool {
|
||||
// only accept they have a good preimage for a paid invoice for their public key
|
||||
if !checkInvoicePaidOk(evt.PubKey) {
|
||||
|
||||
Reference in New Issue
Block a user