more cleanup
This commit is contained in:
parent
03da6cf23d
commit
f014dffad9
3 changed files with 30 additions and 11 deletions
|
@ -3,7 +3,6 @@ package lnd
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
func Request(request []byte) (string, int, error) {
|
func Request(request []byte) (string, int, error) {
|
||||||
// https://bitcoin.stackexchange.com/questions/73869/rpc-call-to-lnd
|
|
||||||
spew.Dump(request)
|
spew.Dump(request)
|
||||||
return "x", 1, nil
|
return "x", 1, nil
|
||||||
}
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -14,8 +14,8 @@ func main() {
|
||||||
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
|
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
|
||||||
Hostname: "devvul.com",
|
Hostname: "devvul.com",
|
||||||
}
|
}
|
||||||
|
nostr.AddNostrAddr(nostrTest)
|
||||||
*/
|
*/
|
||||||
nostr.AddNostrAddr(nostrTest)
|
|
||||||
// matrix endpoints
|
// matrix endpoints
|
||||||
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
||||||
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
|
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
|
||||||
|
|
|
@ -31,14 +31,28 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "nostr/form.html")
|
http.ServeFile(w, r, "nostr/form.html")
|
||||||
case "POST":
|
case "POST":
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
relays := make(map[string][]string)
|
rKey := getRkey(r.FormValue("Name"), getHostname(r.Host))
|
||||||
npub := r.FormValue("Key")
|
// check if the user already exists
|
||||||
// convert npub to hex
|
redis, err := redis.New("localhost:6379", "", redis.NostrDb)
|
||||||
hexKey, err := convertNpubToHex(npub)
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
exists := redis.Client.Exists(rKey)
|
||||||
|
if exists.Val() == 1 {
|
||||||
|
w.WriteHeader(http.StatusConflict)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the hexkey
|
||||||
|
hexKey, err := convertNpubToHex(r.FormValue("Key"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create the struct
|
||||||
|
relays := make(map[string][]string)
|
||||||
names := map[string]string{r.FormValue("Name"): hexKey}
|
names := map[string]string{r.FormValue("Name"): hexKey}
|
||||||
user := nostrWellKnown{}
|
user := nostrWellKnown{}
|
||||||
if r.FormValue("Relays") != "" {
|
if r.FormValue("Relays") != "" {
|
||||||
|
@ -50,6 +64,8 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
user = nostrWellKnown{Names: names}
|
user = nostrWellKnown{Names: names}
|
||||||
}
|
}
|
||||||
jsonUser, _ := json.Marshal(user)
|
jsonUser, _ := json.Marshal(user)
|
||||||
|
|
||||||
|
// generate the payment request
|
||||||
paymentReq, exp, err := lnd.Request(jsonUser)
|
paymentReq, exp, err := lnd.Request(jsonUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
@ -74,7 +90,7 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
requestedName := r.FormValue("name")
|
requestedName := r.FormValue("name")
|
||||||
// search for user@domain
|
// search for user@domain
|
||||||
search := fmt.Sprintf("%s@%s", requestedName, getHostname(r.Host))
|
search := getRkey(requestedName, getHostname(r.Host))
|
||||||
addr, err := redis.Client.Get(search).Result()
|
addr, err := redis.Client.Get(search).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
@ -108,7 +124,7 @@ func AddNostrAddr(n NostrRequest) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("FAILED")
|
fmt.Println("FAILED")
|
||||||
}
|
}
|
||||||
nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname)
|
nameKey := getRkey(n.Name, n.Hostname)
|
||||||
err = r.Client.Set(nameKey, jsonUser, redis.NostrDb).Err()
|
err = r.Client.Set(nameKey, jsonUser, redis.NostrDb).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("FAILED")
|
fmt.Println("FAILED")
|
||||||
|
@ -117,9 +133,6 @@ func AddNostrAddr(n NostrRequest) {
|
||||||
|
|
||||||
func getHostname(hostname string) string {
|
func getHostname(hostname string) string {
|
||||||
// remove port for local testing
|
// remove port for local testing
|
||||||
if strings.Contains(hostname, ":") {
|
|
||||||
hostname = strings.Split(hostname, ":")[0]
|
|
||||||
}
|
|
||||||
return hostname
|
return hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,3 +148,10 @@ func convertNpubToHex(npub string) (string, error) {
|
||||||
return hex.(string), nil
|
return hex.(string), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRkey(user string, hostname string) string {
|
||||||
|
if strings.Contains(hostname, ":") {
|
||||||
|
hostname = strings.Split(hostname, ":")[0]
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s@%s", user, hostname)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue