mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-04-04 01:48:18 +02:00
base58 bad-coding session.
This commit is contained in:
parent
396ca4d3a0
commit
eee9952fac
@ -74,5 +74,5 @@ func checkInvoicePaidOk(pubkey string) bool {
|
||||
})
|
||||
result, _ := cln.Rpc(r.CLNRune, "listinvoices", string(jparams))
|
||||
|
||||
return gjson.Get(result, "invoices.0.paid").String() == "paid"
|
||||
return gjson.Get(result, "result.invoices.0.status").String() == "paid"
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/fiatjaf/relayer"
|
||||
"github.com/fiatjaf/relayer/storage/postgresql"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type Relay struct {
|
||||
@ -17,6 +18,8 @@ type Relay struct {
|
||||
CLNHost string `envconfig:"CLN_HOST"`
|
||||
CLNRune string `envconfig:"CLN_RUNE"`
|
||||
TicketPriceSats int64 `envconfig:"TICKET_PRICE_SATS"`
|
||||
|
||||
db *postgresql.PostgresBackend
|
||||
}
|
||||
|
||||
var r = &Relay{}
|
||||
@ -26,7 +29,7 @@ func (r *Relay) Name() string {
|
||||
}
|
||||
|
||||
func (r *Relay) Storage() relayer.Storage {
|
||||
return &postgresql.PostgresBackend{DatabaseURL: r.PostgresDatabase}
|
||||
return r.db
|
||||
}
|
||||
|
||||
func (r *Relay) Init() error {
|
||||
@ -35,6 +38,8 @@ func (r *Relay) Init() error {
|
||||
return fmt.Errorf("couldn't process envconfig: %w", err)
|
||||
}
|
||||
|
||||
r.db = &postgresql.PostgresBackend{DatabaseURL: r.PostgresDatabase}
|
||||
|
||||
// every hour, delete all very old events
|
||||
go func() {
|
||||
db := r.Storage().(*postgresql.PostgresBackend)
|
||||
@ -45,11 +50,13 @@ func (r *Relay) Init() error {
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Relay) OnInitialized() {
|
||||
// special handlers
|
||||
relayer.Router.Path("/").HandlerFunc(handleWebpage)
|
||||
relayer.Router.Path("/invoice").HandlerFunc(handleInvoice)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Relay) AcceptEvent(evt *nostr.Event) bool {
|
||||
|
1
go.mod
1
go.mod
@ -12,6 +12,7 @@ require (
|
||||
github.com/jb55/lnsocket/go v0.0.0-20220725174341-b98b5cd37bb6
|
||||
github.com/jmoiron/sqlx v1.3.1
|
||||
github.com/kelseyhightower/envconfig v1.4.0
|
||||
github.com/lib/pq v1.10.3
|
||||
github.com/mmcdole/gofeed v1.1.3
|
||||
github.com/rif/cache2go v1.0.0
|
||||
github.com/rs/cors v1.7.0
|
||||
|
1
go.sum
1
go.sum
@ -270,6 +270,7 @@ github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvf
|
||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
|
||||
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc=
|
||||
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk=
|
||||
github.com/lightninglabs/neutrino v0.14.2 h1:yrnZUCYMZ5ECtXhgDrzqPq2oX8awoAN2D/cgCewJcCo=
|
||||
|
@ -10,6 +10,7 @@ var Log = log
|
||||
type Relay interface {
|
||||
Name() string
|
||||
Init() error
|
||||
OnInitialized()
|
||||
AcceptEvent(*nostr.Event) bool
|
||||
Storage() Storage
|
||||
}
|
||||
|
8
start.go
8
start.go
@ -29,9 +29,6 @@ func Start(relay Relay) {
|
||||
log.Panic().Err(err).Msg("couldn't process envconfig")
|
||||
}
|
||||
|
||||
// expose this Log instance so implementations can use it
|
||||
Log = log.With().Str("name", relay.Name()).Logger()
|
||||
|
||||
// allow implementations to do initialization stuff
|
||||
if err := relay.Init(); err != nil {
|
||||
Log.Fatal().Err(err).Msg("failed to start")
|
||||
@ -43,6 +40,9 @@ func Start(relay Relay) {
|
||||
return
|
||||
}
|
||||
|
||||
// expose this Log instance so implementations can use it
|
||||
Log = log.With().Str("name", relay.Name()).Logger()
|
||||
|
||||
// catch the websocket call before anything else
|
||||
Router.Path("/").Headers("Upgrade", "websocket").HandlerFunc(handleWebsocket(relay))
|
||||
|
||||
@ -58,6 +58,8 @@ func Start(relay Relay) {
|
||||
}()
|
||||
}
|
||||
|
||||
relay.OnInitialized()
|
||||
|
||||
// start http server
|
||||
srv := &http.Server{
|
||||
Handler: cors.Default().Handler(Router),
|
||||
|
Loading…
x
Reference in New Issue
Block a user