add option to have external port
This commit is contained in:
parent
3a2096345d
commit
6ef61fe1af
6 changed files with 61 additions and 25 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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,` +
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue