new packages
This commit is contained in:
parent
aa5ccaded0
commit
4f4e320999
8 changed files with 83 additions and 70 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/aead/cmac"
|
"github.com/aead/cmac"
|
||||||
)
|
)
|
||||||
|
|
||||||
func create_k1() (string, error) {
|
func Create_k1() (string, error) {
|
||||||
|
|
||||||
// 16 bytes = 128 bits
|
// 16 bytes = 128 bits
|
||||||
b := make([]byte, 16)
|
b := make([]byte, 16)
|
||||||
|
|
@ -24,7 +24,7 @@ func create_k1() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrypt p with aes_dec
|
// decrypt p with aes_dec
|
||||||
func crypto_aes_decrypt(key_sdm_file_read []byte, ba_p []byte) ([]byte, error) {
|
func Aes_decrypt(key_sdm_file_read []byte, ba_p []byte) ([]byte, error) {
|
||||||
|
|
||||||
dec_p := make([]byte, 16)
|
dec_p := make([]byte, 16)
|
||||||
iv := make([]byte, 16)
|
iv := make([]byte, 16)
|
||||||
|
|
@ -38,7 +38,7 @@ func crypto_aes_decrypt(key_sdm_file_read []byte, ba_p []byte) ([]byte, error) {
|
||||||
return dec_p, nil
|
return dec_p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func crypto_aes_cmac(key_sdm_file_read_mac []byte, sv2 []byte, ba_c []byte) (bool, error) {
|
func Aes_cmac(key_sdm_file_read_mac []byte, sv2 []byte, ba_c []byte) (bool, error) {
|
||||||
|
|
||||||
c2, err := aes.NewCipher(key_sdm_file_read_mac)
|
c2, err := aes.NewCipher(key_sdm_file_read_mac)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package lnurlp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
@ -8,9 +8,10 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"github.com/boltcard/boltcard/lnd"
|
"github.com/boltcard/boltcard/lnd"
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
)
|
)
|
||||||
|
|
||||||
func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
func Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
if db.Get_setting("FUNCTION_LNURLP") != "ENABLE" {
|
if db.Get_setting("FUNCTION_LNURLP") != "ENABLE" {
|
||||||
log.Debug("LNURLp function is not enabled")
|
log.Debug("LNURLp function is not enabled")
|
||||||
return
|
return
|
||||||
|
|
@ -22,7 +23,7 @@ func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
||||||
card_id, err := db.Get_card_id_for_name(name)
|
card_id, err := db.Get_card_id_for_name(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("card name not found")
|
log.Info("card name not found")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,14 +39,14 @@ func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
||||||
domain := db.Get_setting("HOST_DOMAIN")
|
domain := db.Get_setting("HOST_DOMAIN")
|
||||||
if r.Host != domain {
|
if r.Host != domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_msat, err := strconv.ParseInt(amount, 10, 64)
|
amount_msat, err := strconv.ParseInt(amount, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("amount is not a valid integer")
|
log.Warn("amount is not a valid integer")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,14 +56,14 @@ func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
||||||
pr, r_hash, err := lnd.Add_invoice(amount_sat, metadata)
|
pr, r_hash, err := lnd.Add_invoice(amount_sat, metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("could not add_invoice")
|
log.Warn("could not add_invoice")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.Insert_receipt(card_id, pr, hex.EncodeToString(r_hash), amount_msat)
|
err = db.Insert_receipt(card_id, pr, hex.EncodeToString(r_hash), amount_msat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err)
|
log.Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
package main
|
package lnurlp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
)
|
)
|
||||||
|
|
||||||
func lnurlp_response(w http.ResponseWriter, r *http.Request) {
|
func Response(w http.ResponseWriter, r *http.Request) {
|
||||||
if db.Get_setting("FUNCTION_LNURLP") != "ENABLE" {
|
if db.Get_setting("FUNCTION_LNURLP") != "ENABLE" {
|
||||||
log.Debug("LNURLp function is not enabled")
|
log.Debug("LNURLp function is not enabled")
|
||||||
return
|
return
|
||||||
|
|
@ -27,7 +28,7 @@ func lnurlp_response(w http.ResponseWriter, r *http.Request) {
|
||||||
domain := db.Get_setting("HOST_DOMAIN")
|
domain := db.Get_setting("HOST_DOMAIN")
|
||||||
if r.Host != domain {
|
if r.Host != domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,13 +37,13 @@ func lnurlp_response(w http.ResponseWriter, r *http.Request) {
|
||||||
card_count, err := db.Get_card_count_for_name_lnurlp(name)
|
card_count, err := db.Get_card_count_for_name_lnurlp(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("could not get card count for name")
|
log.Warn("could not get card count for name")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if card_count != 1 {
|
if card_count != 1 {
|
||||||
log.Info("not one enabled card with that name")
|
log.Info("not one enabled card with that name")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package lnurlw
|
||||||
|
|
||||||
import (
|
import (
|
||||||
decodepay "github.com/fiatjaf/ln-decodepay"
|
decodepay "github.com/fiatjaf/ln-decodepay"
|
||||||
|
|
@ -6,14 +6,15 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
"github.com/boltcard/boltcard/lnd"
|
"github.com/boltcard/boltcard/lnd"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
)
|
)
|
||||||
|
|
||||||
func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
func Callback(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
env_host_domain := db.Get_setting("HOST_DOMAIN")
|
env_host_domain := db.Get_setting("HOST_DOMAIN")
|
||||||
if req.Host != env_host_domain {
|
if req.Host != env_host_domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +26,7 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if !ok || len(params_k1[0]) < 1 {
|
if !ok || len(params_k1[0]) < 1 {
|
||||||
log.WithFields(log.Fields{"url": url}).Debug("k1 not found")
|
log.WithFields(log.Fields{"url": url}).Debug("k1 not found")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,14 +35,14 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
p, err := db.Get_payment_k1(param_k1)
|
p, err := db.Get_payment_k1(param_k1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"url": url, "k1": param_k1}).Warn(err)
|
log.WithFields(log.Fields{"url": url, "k1": param_k1}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that payment has not been made
|
// check that payment has not been made
|
||||||
if p.Paid_flag != "N" {
|
if p.Paid_flag != "N" {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("payment already made")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("payment already made")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,19 +50,19 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
lnurlw_timeout, err := db.Check_lnurlw_timeout(p.Card_payment_id)
|
lnurlw_timeout, err := db.Check_lnurlw_timeout(p.Card_payment_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if lnurlw_timeout == true {
|
if lnurlw_timeout == true {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("lnurlw request has timed out")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("lnurlw request has timed out")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
params_pr, ok := req.URL.Query()["pr"]
|
params_pr, ok := req.URL.Query()["pr"]
|
||||||
if !ok || len(params_pr[0]) < 1 {
|
if !ok || len(params_pr[0]) < 1 {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn("pr field not found")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn("pr field not found")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +73,7 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
err = db.Update_payment_invoice(p.Card_payment_id, param_pr, bolt11.MSatoshi)
|
err = db.Update_payment_invoice(p.Card_payment_id, param_pr, bolt11.MSatoshi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +83,7 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
testnode := db.Get_setting("LN_TESTNODE")
|
testnode := db.Get_setting("LN_TESTNODE")
|
||||||
if testnode != "" && bolt11.Payee != testnode {
|
if testnode != "" && bolt11.Payee != testnode {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("rejected as not the defined test node")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("rejected as not the defined test node")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,14 +94,14 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
day_total_sats, err := db.Get_card_totals(p.Card_id)
|
day_total_sats, err := db.Get_card_totals(p.Card_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := db.Get_card_from_card_id(p.Card_id)
|
c, err := db.Get_card_from_card_id(p.Card_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +109,7 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("invoice_sats: ", invoice_sats)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("invoice_sats: ", invoice_sats)
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("tx_limit_sats: ", c.Tx_limit_sats)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("tx_limit_sats: ", c.Tx_limit_sats)
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("over tx_limit_sats!")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("over tx_limit_sats!")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +118,7 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("day_total_sats: ", day_total_sats)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("day_total_sats: ", day_total_sats)
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("day_limit_sats: ", c.Day_limit_sats)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("day_limit_sats: ", c.Day_limit_sats)
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("over day_limit_sats!")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("over day_limit_sats!")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,13 +129,13 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
card_total, err := db.Get_card_total_sats(p.Card_id)
|
card_total, err := db.Get_card_total_sats(p.Card_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if card_total-invoice_sats < 0 {
|
if card_total-invoice_sats < 0 {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn("not enough balance")
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn("not enough balance")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +146,7 @@ func lnurlw_callback(w http.ResponseWriter, req *http.Request) {
|
||||||
err = db.Update_payment_paid(p.Card_payment_id)
|
err = db.Update_payment_paid(p.Card_payment_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package lnurlw
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
@ -10,9 +10,11 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/crypto"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type ResponseData struct {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Callback string `json:"callback"`
|
Callback string `json:"callback"`
|
||||||
LnurlwK1 string `json:"k1"`
|
LnurlwK1 string `json:"k1"`
|
||||||
|
|
@ -61,7 +63,7 @@ func check_cmac(uid []byte, ctr []byte, k2_cmac_key []byte, cmac []byte) (bool,
|
||||||
sv2[14] = ctr[1]
|
sv2[14] = ctr[1]
|
||||||
sv2[15] = ctr[2]
|
sv2[15] = ctr[2]
|
||||||
|
|
||||||
cmac_verified, err := crypto_aes_cmac(k2_cmac_key, sv2, cmac)
|
cmac_verified, err := crypto.Aes_cmac(k2_cmac_key, sv2, cmac)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
@ -159,7 +161,7 @@ func parse_request(req *http.Request) (int, error) {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dec_p, err := crypto_aes_decrypt(key_sdm_file_read, ba_p)
|
dec_p, err := crypto.Aes_decrypt(key_sdm_file_read, ba_p)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
@ -245,12 +247,12 @@ func parse_request(req *http.Request) (int, error) {
|
||||||
return c.Card_id, nil
|
return c.Card_id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lnurlw_response(w http.ResponseWriter, req *http.Request) {
|
func Response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
env_host_domain := db.Get_setting("HOST_DOMAIN")
|
env_host_domain := db.Get_setting("HOST_DOMAIN")
|
||||||
if req.Host != env_host_domain {
|
if req.Host != env_host_domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,15 +260,15 @@ func lnurlw_response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug(err.Error())
|
log.Debug(err.Error())
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lnurlw_k1, err := create_k1()
|
lnurlw_k1, err := crypto.Create_k1()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,7 +278,7 @@ func lnurlw_response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,7 +294,7 @@ func lnurlw_response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,11 +303,11 @@ func lnurlw_response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response := Response{}
|
response := ResponseData{}
|
||||||
response.Tag = "withdrawRequest"
|
response.Tag = "withdrawRequest"
|
||||||
response.Callback = lnurlw_cb_url
|
response.Callback = lnurlw_cb_url
|
||||||
response.LnurlwK1 = lnurlw_k1
|
response.LnurlwK1 = lnurlw_k1
|
||||||
|
|
@ -317,7 +319,7 @@ func lnurlw_response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err)
|
log.Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
24
main.go
24
main.go
|
|
@ -6,24 +6,12 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/lnurlw"
|
||||||
|
"github.com/boltcard/boltcard/lnurlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var router = mux.NewRouter()
|
var router = mux.NewRouter()
|
||||||
|
|
||||||
func write_error(w http.ResponseWriter) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
jsonData := []byte(`{"status":"ERROR","reason":"bad request"}`)
|
|
||||||
w.Write(jsonData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func write_error_message(w http.ResponseWriter, message string) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
jsonData := []byte(`{"status":"ERROR","reason":"` + message + `"}`)
|
|
||||||
w.Write(jsonData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log_level := db.Get_setting("LOG_LEVEL")
|
log_level := db.Get_setting("LOG_LEVEL")
|
||||||
|
|
||||||
|
|
@ -45,11 +33,11 @@ func main() {
|
||||||
// createboltcard
|
// createboltcard
|
||||||
router.Path("/new").Methods("GET").HandlerFunc(new_card_request)
|
router.Path("/new").Methods("GET").HandlerFunc(new_card_request)
|
||||||
// lnurlw for pos
|
// lnurlw for pos
|
||||||
router.Path("/ln").Methods("GET").HandlerFunc(lnurlw_response)
|
router.Path("/ln").Methods("GET").HandlerFunc(lnurlw.Response)
|
||||||
router.Path("/cb").Methods("GET").HandlerFunc(lnurlw_callback)
|
router.Path("/cb").Methods("GET").HandlerFunc(lnurlw.Callback)
|
||||||
// lnurlp for lightning address
|
// lnurlp for lightning address
|
||||||
router.Path("/.well-known/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp_response)
|
router.Path("/.well-known/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp.Response)
|
||||||
router.Path("/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp_callback)
|
router.Path("/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp.Callback)
|
||||||
|
|
||||||
port := db.Get_setting("HOST_PORT")
|
port := db.Get_setting("HOST_PORT")
|
||||||
if port == "" {
|
if port == "" {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -48,7 +49,7 @@ func new_card_request(w http.ResponseWriter, req *http.Request) {
|
||||||
params_a, ok := req.URL.Query()["a"]
|
params_a, ok := req.URL.Query()["a"]
|
||||||
if !ok || len(params_a[0]) < 1 {
|
if !ok || len(params_a[0]) < 1 {
|
||||||
log.Debug("a not found")
|
log.Debug("a not found")
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,13 +61,13 @@ func new_card_request(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
write_error_message(w, "one time code was used or card was wiped or card does not exist")
|
resp_err.Write_message(w, "one time code was used or card was wiped or card does not exist")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err)
|
log.Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +91,7 @@ func new_card_request(w http.ResponseWriter, req *http.Request) {
|
||||||
jsonData, err := json.Marshal(response)
|
jsonData, err := json.Marshal(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err)
|
log.Warn(err)
|
||||||
write_error(w)
|
resp_err.Write(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
19
resp_err/resp_err.go
Normal file
19
resp_err/resp_err.go
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package resp_err
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Write(w http.ResponseWriter) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
jsonData := []byte(`{"status":"ERROR","reason":"bad request"}`)
|
||||||
|
w.Write(jsonData)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Write_message(w http.ResponseWriter, message string) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
jsonData := []byte(`{"status":"ERROR","reason":"` + message + `"}`)
|
||||||
|
w.Write(jsonData)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue