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
|
package internalapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/boltcard/boltcard/db"
|
|
||||||
"github.com/boltcard/boltcard/resp_err"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// random_hex() from Createboltcardwithpin used here
|
// random_hex() from Createboltcardwithpin used here
|
||||||
|
|
@ -100,11 +101,16 @@ func Createboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
// return the URI + one_time_code
|
// return the URI + one_time_code
|
||||||
|
|
||||||
hostdomain := db.Get_setting("HOST_DOMAIN")
|
hostdomain := db.Get_setting("HOST_DOMAIN")
|
||||||
|
hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT")
|
||||||
|
hostdomainsuffix := ""
|
||||||
|
if hostdomainPort != "" {
|
||||||
|
hostdomainsuffix = ":" + hostdomainPort
|
||||||
|
}
|
||||||
url := ""
|
url := ""
|
||||||
if strings.HasSuffix(hostdomain, ".onion") {
|
if strings.HasSuffix(hostdomain, ".onion") {
|
||||||
url = "http://" + hostdomain + "/new?a=" + one_time_code
|
url = "http://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code
|
||||||
} else {
|
} else {
|
||||||
url = "https://" + hostdomain + "/new?a=" + one_time_code
|
url = "https://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code
|
||||||
}
|
}
|
||||||
|
|
||||||
// log the response
|
// log the response
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@ package internalapi
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/boltcard/boltcard/db"
|
|
||||||
"github.com/boltcard/boltcard/resp_err"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func random_hex() string {
|
func random_hex() string {
|
||||||
|
|
@ -132,11 +133,16 @@ func Createboltcardwithpin(w http.ResponseWriter, r *http.Request) {
|
||||||
// return the URI + one_time_code
|
// return the URI + one_time_code
|
||||||
|
|
||||||
hostdomain := db.Get_setting("HOST_DOMAIN")
|
hostdomain := db.Get_setting("HOST_DOMAIN")
|
||||||
|
hostdomainPort := db.Get_setting("HOST_DOMAIN_PORT")
|
||||||
|
hostdomainsuffix := ""
|
||||||
|
if hostdomainPort != "" {
|
||||||
|
hostdomainsuffix = ":" + hostdomainPort
|
||||||
|
}
|
||||||
url := ""
|
url := ""
|
||||||
if strings.HasSuffix(hostdomain, ".onion") {
|
if strings.HasSuffix(hostdomain, ".onion") {
|
||||||
url = "http://" + hostdomain + "/new?a=" + one_time_code
|
url = "http://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code
|
||||||
} else {
|
} else {
|
||||||
url = "https://" + hostdomain + "/new?a=" + one_time_code
|
url = "https://" + hostdomain + hostdomainsuffix + "/new?a=" + one_time_code
|
||||||
}
|
}
|
||||||
|
|
||||||
// log the response
|
// log the response
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,14 @@ package lnurlp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"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"
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Callback(w http.ResponseWriter, r *http.Request) {
|
func Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -37,6 +38,11 @@ func Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
}).Info("lnurlp_callback")
|
}).Info("lnurlp_callback")
|
||||||
|
|
||||||
domain := db.Get_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 {
|
if r.Host != domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
resp_err.Write(w)
|
resp_err.Write(w)
|
||||||
|
|
@ -52,7 +58,7 @@ func Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
amount_sat := amount_msat / 1000
|
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)
|
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")
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
package lnurlp
|
package lnurlp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
"github.com/boltcard/boltcard/resp_err"
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Response(w http.ResponseWriter, r *http.Request) {
|
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)
|
// look up domain setting (HOST_DOMAIN)
|
||||||
|
|
||||||
domain := db.Get_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 {
|
if r.Host != domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
resp_err.Write(w)
|
resp_err.Write(w)
|
||||||
|
|
@ -47,10 +53,10 @@ func Response(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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",` +
|
jsonData := []byte(`{"status":"OK",` +
|
||||||
`"callback":"https://` + domain + `/lnurlp/` + name + `",` +
|
`"callback":"https://` + domain + hostdomainsuffix + `/lnurlp/` + name + `",` +
|
||||||
`"tag":"payRequest",` +
|
`"tag":"payRequest",` +
|
||||||
`"maxSendable":1000000000,` +
|
`"maxSendable":1000000000,` +
|
||||||
`"minSendable":1000,` +
|
`"minSendable":1000,` +
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,15 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/boltcard/boltcard/crypto"
|
|
||||||
"github.com/boltcard/boltcard/db"
|
|
||||||
"github.com/boltcard/boltcard/resp_err"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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) {
|
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) {
|
func Response(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
env_host_domain := db.Get_setting("HOST_DOMAIN")
|
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 {
|
if req.Host != env_host_domain {
|
||||||
log.Warn("wrong host domain")
|
log.Warn("wrong host domain")
|
||||||
|
|
@ -280,10 +286,10 @@ func Response(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lnurlw_cb_url := ""
|
lnurlw_cb_url := ""
|
||||||
if strings.HasSuffix(req.Host, ".onion") {
|
if strings.HasSuffix(env_host_domain, ".onion") {
|
||||||
lnurlw_cb_url = "http://" + req.Host + "/cb"
|
lnurlw_cb_url = "http://" + env_host_domain + hostdomainsuffix + "/cb"
|
||||||
} else {
|
} 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")
|
min_withdraw_sats_str := db.Get_setting("MIN_WITHDRAW_SATS")
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ package main
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/boltcard/boltcard/db"
|
"github.com/boltcard/boltcard/db"
|
||||||
"github.com/boltcard/boltcard/resp_err"
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
log "github.com/sirupsen/logrus"
|
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]
|
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)
|
c, err := db.Get_new_card(a)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue