Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/api/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (s Service) GetTransactionAnalytics(w http.ResponseWriter, r *http.Request)
Fee: payment.Fee,
FeeSats: payment.Fee / 1000,
Memo: payment.Memo,
Time: payment.Time,
Time: int(payment.Time),
Timestamp: paymentTime.Format(time.RFC3339),
PaymentType: paymentType,
Bolt11: payment.Bolt11,
Expand Down Expand Up @@ -443,7 +443,7 @@ func (s Service) GetUserTransactionHistory(w http.ResponseWriter, r *http.Reques
Fee: payment.Fee,
FeeSats: payment.Fee / 1000,
Memo: payment.Memo,
Time: payment.Time,
Time: int(payment.Time),
Timestamp: paymentTime.Format(time.RFC3339),
PaymentType: paymentType,
Bolt11: payment.Bolt11,
Expand Down
34 changes: 33 additions & 1 deletion internal/lnbits/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lnbits
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -142,13 +143,44 @@ type Wallet struct {
User string `json:"user"`
}

// UnixTime is a payment timestamp in unix seconds. lnbits 0.x serialises
// `time` as a number, 1.x as an RFC3339 string, so decoding accepts either and
// normalises to seconds. Encoding always emits the number, keeping the API
// responses this type is serialised into unchanged.
type UnixTime int64

func (t *UnixTime) UnmarshalJSON(b []byte) error {
s := string(b)
if s == "null" || s == `""` {
return nil
}
if b[0] != '"' {
var n int64
if err := json.Unmarshal(b, &n); err != nil {
return err
}
*t = UnixTime(n)
return nil
}
var str string
if err := json.Unmarshal(b, &str); err != nil {
return err
}
parsed, err := time.Parse(time.RFC3339, str)
if err != nil {
return fmt.Errorf("lnbits: unrecognised payment time %q: %w", str, err)
}
*t = UnixTime(parsed.Unix())
return nil
}

type Payment struct {
CheckingID string `json:"checking_id"`
Pending bool `json:"pending"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
Memo string `json:"memo"`
Time int `json:"time"`
Time UnixTime `json:"time"`
Bolt11 string `json:"bolt11"`
Preimage string `json:"preimage"`
PaymentHash string `json:"payment_hash"`
Expand Down
26 changes: 13 additions & 13 deletions internal/lnbits/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ type Server struct {
}

type Webhook struct {
CheckingID string `json:"checking_id"`
Pending bool `json:"pending"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
Memo string `json:"memo"`
Time int64 `json:"time"`
Bolt11 string `json:"bolt11"`
Preimage string `json:"preimage"`
PaymentHash string `json:"payment_hash"`
Extra struct{} `json:"extra"`
WalletID string `json:"wallet_id"`
Webhook string `json:"webhook"`
WebhookStatus interface{} `json:"webhook_status"`
CheckingID string `json:"checking_id"`
Pending bool `json:"pending"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
Memo string `json:"memo"`
Time lnbits.UnixTime `json:"time"`
Bolt11 string `json:"bolt11"`
Preimage string `json:"preimage"`
PaymentHash string `json:"payment_hash"`
Extra struct{} `json:"extra"`
WalletID string `json:"wallet_id"`
Webhook string `json:"webhook"`
WebhookStatus interface{} `json:"webhook_status"`
}

func NewServer(bot *telegram.TipBot) *Server {
Expand Down
Loading