Skip to content

Commit

Permalink
base58 bad-coding session.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Aug 12, 2022
1 parent 396ca4d commit eee9952
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion expensive/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
13 changes: 10 additions & 3 deletions expensive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{}
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Log = log
type Relay interface {
Name() string
Init() error
OnInitialized()
AcceptEvent(*nostr.Event) bool
Storage() Storage
}
Expand Down
8 changes: 5 additions & 3 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))

Expand All @@ -58,6 +58,8 @@ func Start(relay Relay) {
}()
}

relay.OnInitialized()

// start http server
srv := &http.Server{
Handler: cors.Default().Handler(Router),
Expand Down

0 comments on commit eee9952

Please sign in to comment.