reformat with gofmt
This commit is contained in:
parent
d82c17e0a1
commit
7816566d59
9 changed files with 221 additions and 216 deletions
|
|
@ -27,7 +27,7 @@ func db_open() (*sql.DB, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func db_get_setting(setting_name string) (string) {
|
||||
func db_get_setting(setting_name string) string {
|
||||
|
||||
setting_value := ""
|
||||
|
||||
|
|
@ -74,13 +74,19 @@ func db_insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string
|
|||
allow_neg_bal_ptr bool) error {
|
||||
|
||||
lnurlw_enable_yn := "N"
|
||||
if lnurlw_enable { lnurlw_enable_yn = "Y" }
|
||||
if lnurlw_enable {
|
||||
lnurlw_enable_yn = "Y"
|
||||
}
|
||||
|
||||
uid_privacy_yn := "N"
|
||||
if uid_privacy { uid_privacy_yn = "Y" }
|
||||
if uid_privacy {
|
||||
uid_privacy_yn = "Y"
|
||||
}
|
||||
|
||||
allow_neg_bal_yn := "N"
|
||||
if allow_neg_bal_ptr { allow_neg_bal_yn = "Y" }
|
||||
if allow_neg_bal_ptr {
|
||||
allow_neg_bal_yn = "Y"
|
||||
}
|
||||
|
||||
db, err := db_open()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func db_open() (*sql.DB, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func db_get_setting(setting_name string) (string) {
|
||||
func db_get_setting(setting_name string) string {
|
||||
|
||||
setting_value := ""
|
||||
|
||||
|
|
|
|||
14
lightning.go
14
lightning.go
|
|
@ -2,14 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
"time"
|
||||
"crypto/sha256"
|
||||
|
||||
decodepay "github.com/fiatjaf/ln-decodepay"
|
||||
lnrpc "github.com/lightningnetwork/lnd/lnrpc"
|
||||
|
|
@ -92,7 +92,7 @@ func add_invoice(amount_sat int64, metadata string) (payment_request string, r_h
|
|||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := l_client.AddInvoice(ctx, &lnrpc.Invoice {
|
||||
result, err := l_client.AddInvoice(ctx, &lnrpc.Invoice{
|
||||
Value: amount_sat,
|
||||
DescriptionHash: dh[:],
|
||||
})
|
||||
|
|
@ -106,7 +106,7 @@ func add_invoice(amount_sat int64, metadata string) (payment_request string, r_h
|
|||
|
||||
// https://api.lightning.community/?shell#subscribesingleinvoice
|
||||
|
||||
func monitor_invoice_state(r_hash []byte) () {
|
||||
func monitor_invoice_state(r_hash []byte) {
|
||||
|
||||
// SubscribeSingleInvoice
|
||||
|
||||
|
|
@ -154,14 +154,14 @@ func monitor_invoice_state(r_hash []byte) () {
|
|||
log.Fields{
|
||||
"r_hash": hex.EncodeToString(r_hash),
|
||||
"invoice_state": invoice_state,
|
||||
},).Info("invoice state updated")
|
||||
}).Info("invoice state updated")
|
||||
|
||||
db_update_receipt_state(hex.EncodeToString(r_hash), invoice_state)
|
||||
}
|
||||
|
||||
connection.Close()
|
||||
|
||||
// send email
|
||||
// send email
|
||||
|
||||
card_id, err := db_get_card_id_for_r_hash(hex.EncodeToString(r_hash))
|
||||
if err != nil {
|
||||
|
|
@ -269,7 +269,7 @@ func pay_invoice(card_payment_id int, invoice string) {
|
|||
|
||||
connection.Close()
|
||||
|
||||
// send email
|
||||
// send email
|
||||
|
||||
card_id, err := db_get_card_id_for_card_payment_id(card_payment_id)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"encoding/hex"
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -31,7 +31,7 @@ func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
|||
"card_id": card_id,
|
||||
"amount": amount,
|
||||
"req.Host": r.Host,
|
||||
},).Info("lnurlp_callback")
|
||||
}).Info("lnurlp_callback")
|
||||
|
||||
domain := db_get_setting("HOST_DOMAIN")
|
||||
if r.Host != domain {
|
||||
|
|
@ -47,7 +47,7 @@ func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
amount_sat := amount_msat / 1000;
|
||||
amount_sat := amount_msat / 1000
|
||||
|
||||
metadata := "[[\"text/identifier\",\"" + name + "@" + domain + "\"],[\"text/plain\",\"bolt card deposit\"]]"
|
||||
pr, r_hash, err := add_invoice(amount_sat, metadata)
|
||||
|
|
@ -66,7 +66,7 @@ func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
go monitor_invoice_state(r_hash)
|
||||
|
||||
log.Debug("sending 'status OK' response");
|
||||
log.Debug("sending 'status OK' response")
|
||||
|
||||
jsonData := []byte(`{` +
|
||||
`"status":"OK",` +
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
|
@ -19,9 +19,9 @@ func lnurlp_response(w http.ResponseWriter, r *http.Request) {
|
|||
"url_path": r.URL.Path,
|
||||
"name": name,
|
||||
"r.Host": r.Host,
|
||||
},).Info("lnurlp_response")
|
||||
}).Info("lnurlp_response")
|
||||
|
||||
// look up domain setting (HOST_DOMAIN)
|
||||
// look up domain setting (HOST_DOMAIN)
|
||||
|
||||
domain := db_get_setting("HOST_DOMAIN")
|
||||
if r.Host != domain {
|
||||
|
|
@ -30,7 +30,7 @@ func lnurlp_response(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// look up name in database (table cards, field card_name)
|
||||
// look up name in database (table cards, field card_name)
|
||||
|
||||
card_count, err := db_get_card_count_for_name_lnurlp(name)
|
||||
if err != nil {
|
||||
|
|
|
|||
10
main.go
10
main.go
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -41,12 +41,12 @@ func main() {
|
|||
DisableHTMLEscape: true,
|
||||
})
|
||||
|
||||
// createboltcard
|
||||
// createboltcard
|
||||
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("/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("/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp_callback)
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ func main() {
|
|||
port = "9000"
|
||||
}
|
||||
|
||||
srv := &http.Server {
|
||||
srv := &http.Server{
|
||||
Handler: router,
|
||||
Addr: ":" + port, // consider adding host
|
||||
WriteTimeout: 30 * time.Second,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func db_open() (*sql.DB, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func db_get_setting(setting_name string) (string) {
|
||||
func db_get_setting(setting_name string) string {
|
||||
|
||||
setting_value := ""
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"strconv"
|
||||
log "github.com/sirupsen/logrus"
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type card_wipe_info struct {
|
||||
|
|
@ -29,7 +29,6 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
// check if card_name exists
|
||||
|
||||
card_count, err := db_get_card_name_count(*card_name_ptr)
|
||||
|
|
@ -63,7 +62,7 @@ func main() {
|
|||
`"k4": "` + card_wipe_info_values.k4 + `",` +
|
||||
`"uid": "` + card_wipe_info_values.uid + `",` +
|
||||
`"version": 1` +
|
||||
`}`;
|
||||
`}`
|
||||
|
||||
fmt.Println()
|
||||
q, err := qrcode.New(qr, qrcode.Medium)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue