diff --git a/internalapi/createboltcard.go b/internalapi/createboltcard.go index e0e1eb3..a8aa8f3 100644 --- a/internalapi/createboltcard.go +++ b/internalapi/createboltcard.go @@ -1,12 +1,13 @@ package internalapi import ( - "github.com/boltcard/boltcard/db" - "github.com/boltcard/boltcard/resp_err" - log "github.com/sirupsen/logrus" "net/http" "strconv" "strings" + + "github.com/boltcard/boltcard/db" + "github.com/boltcard/boltcard/resp_err" + log "github.com/sirupsen/logrus" ) // random_hex() from Createboltcardwithpin used here @@ -100,11 +101,16 @@ func Createboltcard(w http.ResponseWriter, r *http.Request) { // return the URI + one_time_code hostdomain := db.Get_setting("HOST_DOMAIN") + hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT") + hostdomainsuffix := "" + if hostdomainPort != "" { + hostdomainsuffix = ":" + hostdomainPort + } url := "" if strings.HasSuffix(hostdomain, ".onion") { - url = "http://" + hostdomain + "/new?a=" + one_time_code + url = "http://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code } else { - url = "https://" + hostdomain + "/new?a=" + one_time_code + url = "https://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code } // log the response diff --git a/internalapi/createboltcardwithpin.go b/internalapi/createboltcardwithpin.go index 64d9efd..a7e8cd8 100644 --- a/internalapi/createboltcardwithpin.go +++ b/internalapi/createboltcardwithpin.go @@ -3,12 +3,13 @@ package internalapi import ( "crypto/rand" "encoding/hex" - "github.com/boltcard/boltcard/db" - "github.com/boltcard/boltcard/resp_err" - log "github.com/sirupsen/logrus" "net/http" "strconv" "strings" + + "github.com/boltcard/boltcard/db" + "github.com/boltcard/boltcard/resp_err" + log "github.com/sirupsen/logrus" ) func random_hex() string { @@ -132,11 +133,16 @@ func Createboltcardwithpin(w http.ResponseWriter, r *http.Request) { // return the URI + one_time_code hostdomain := db.Get_setting("HOST_DOMAIN") + hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT") + hostdomainsuffix := "" + if hostdomainPort != "" { + hostdomainsuffix = ":" + hostdomainPort + } url := "" if strings.HasSuffix(hostdomain, ".onion") { - url = "http://" + hostdomain + "/new?a=" + one_time_code + url = "http://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code } else { - url = "https://" + hostdomain + "/new?a=" + one_time_code + url = "https://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code } // log the response diff --git a/lnurlp/lnurlp_callback.go b/lnurlp/lnurlp_callback.go index 1984e8c..7d02eaf 100644 --- a/lnurlp/lnurlp_callback.go +++ b/lnurlp/lnurlp_callback.go @@ -2,13 +2,14 @@ package lnurlp import ( "encoding/hex" + "net/http" + "strconv" + "github.com/boltcard/boltcard/db" "github.com/boltcard/boltcard/lnd" "github.com/boltcard/boltcard/resp_err" "github.com/gorilla/mux" log "github.com/sirupsen/logrus" - "net/http" - "strconv" ) func Callback(w http.ResponseWriter, r *http.Request) { @@ -37,6 +38,11 @@ func Callback(w http.ResponseWriter, r *http.Request) { }).Info("lnurlp_callback") domain := db.Get_setting("HOST_DOMAIN") + hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT") + hostdomainsuffix := "" + if hostdomainPort != "" { + hostdomainsuffix = ":" + hostdomainPort + } if r.Host != domain { log.Warn("wrong host domain") resp_err.Write(w) @@ -52,7 +58,7 @@ func Callback(w http.ResponseWriter, r *http.Request) { amount_sat := amount_msat / 1000 - metadata := "[[\"text/identifier\",\"" + name + "@" + domain + "\"],[\"text/plain\",\"bolt card deposit\"]]" + metadata := "[[\"text/identifier\",\"" + name + "@" + domain + hostdomainsuffix + "\"],[\"text/plain\",\"bolt card deposit\"]]" pr, r_hash, err := lnd.Add_invoice(amount_sat, metadata) if err != nil { log.Warn("could not add_invoice") diff --git a/lnurlp/lnurlp_request.go b/lnurlp/lnurlp_request.go index 6483388..853614d 100644 --- a/lnurlp/lnurlp_request.go +++ b/lnurlp/lnurlp_request.go @@ -1,11 +1,12 @@ package lnurlp import ( + "net/http" + "github.com/boltcard/boltcard/db" "github.com/boltcard/boltcard/resp_err" "github.com/gorilla/mux" log "github.com/sirupsen/logrus" - "net/http" ) func Response(w http.ResponseWriter, r *http.Request) { @@ -26,6 +27,11 @@ func Response(w http.ResponseWriter, r *http.Request) { // look up domain setting (HOST_DOMAIN) domain := db.Get_setting("HOST_DOMAIN") + hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT") + hostdomainsuffix := "" + if hostdomainPort != "" { + hostdomainsuffix = ":" + hostdomainPort + } if r.Host != domain { log.Warn("wrong host domain") resp_err.Write(w) @@ -47,10 +53,10 @@ func Response(w http.ResponseWriter, r *http.Request) { return } - metadata := "[[\\\"text/identifier\\\",\\\"" + name + "@" + domain + "\\\"],[\\\"text/plain\\\",\\\"bolt card deposit\\\"]]" + metadata := "[[\\\"text/identifier\\\",\\\"" + name + "@" + domain + hostdomainsuffix + "\\\"],[\\\"text/plain\\\",\\\"bolt card deposit\\\"]]" jsonData := []byte(`{"status":"OK",` + - `"callback":"https://` + domain + `/lnurlp/` + name + `",` + + `"callback":"https://` + domain + hostdomainsuffix + `/lnurlp/` + name + `",` + `"tag":"payRequest",` + `"maxSendable":1000000000,` + `"minSendable":1000,` + diff --git a/lnurlw/lnurlw_request.go b/lnurlw/lnurlw_request.go index eb0b15f..ad392a9 100644 --- a/lnurlw/lnurlw_request.go +++ b/lnurlw/lnurlw_request.go @@ -4,14 +4,15 @@ import ( "encoding/hex" "encoding/json" "errors" - "github.com/boltcard/boltcard/crypto" - "github.com/boltcard/boltcard/db" - "github.com/boltcard/boltcard/resp_err" - log "github.com/sirupsen/logrus" "net/http" "os" "strconv" "strings" + + "github.com/boltcard/boltcard/crypto" + "github.com/boltcard/boltcard/db" + "github.com/boltcard/boltcard/resp_err" + log "github.com/sirupsen/logrus" ) func get_p_c(req *http.Request, p_name string, c_name string) (p string, c string) { @@ -246,6 +247,11 @@ func parse_request(req *http.Request) (int, error) { func Response(w http.ResponseWriter, req *http.Request) { env_host_domain := db.Get_setting("HOST_DOMAIN") + hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT") + hostdomainsuffix := "" + if hostdomainPort != "" { + hostdomainsuffix = ":" + hostdomainPort + } if req.Host != env_host_domain { log.Warn("wrong host domain") @@ -280,10 +286,10 @@ func Response(w http.ResponseWriter, req *http.Request) { } lnurlw_cb_url := "" - if strings.HasSuffix(req.Host, ".onion") { - lnurlw_cb_url = "http://" + req.Host + "/cb" + if strings.HasSuffix(env_host_domain, ".onion") { + lnurlw_cb_url = "http://" + env_host_domain + hostdomainsuffix + "/cb" } else { - lnurlw_cb_url = "https://" + req.Host + "/cb" + lnurlw_cb_url = "https://" + env_host_domain + hostdomainsuffix + "/cb" } min_withdraw_sats_str := db.Get_setting("MIN_WITHDRAW_SATS") diff --git a/new_card_request.go b/new_card_request.go index c35bd43..1512e4f 100644 --- a/new_card_request.go +++ b/new_card_request.go @@ -3,10 +3,11 @@ package main import ( "database/sql" "encoding/json" + "net/http" + "github.com/boltcard/boltcard/db" "github.com/boltcard/boltcard/resp_err" log "github.com/sirupsen/logrus" - "net/http" ) /** @@ -55,7 +56,12 @@ func new_card_request(w http.ResponseWriter, req *http.Request) { a := params_a[0] - lnurlw_base := "lnurlw://" + db.Get_setting("HOST_DOMAIN") + "/ln" + hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT") + hostdomainsuffix := "" + if hostdomainPort != "" { + hostdomainsuffix = ":" + hostdomainPort + } + lnurlw_base := "lnurlw://" + db.Get_setting("HOST_DOMAIN") + hostdomainsuffix + "/ln" c, err := db.Get_new_card(a)