Skip to content

fix: accept lnbits 1.x RFC3339 payment timestamps - #67

Closed
xbuddhi wants to merge 1 commit into
mainfrom
fix/lnbits-v1-payment-time
Closed

xbuddhi wants to merge 1 commit into
mainfrom
fix/lnbits-v1-payment-time

Conversation

@xbuddhi

@xbuddhi xbuddhi commented Sep 13, 2026

Copy link
Copy Markdown

Summary

Migrating the backend from Voltage (lnbits 0.x) to Railway (lnbits 1.x) broke the bot's transaction history:

[transactions] Error: json: cannot unmarshal string into Go struct field Payment.time of type int

lnbits 0.x serialises a payment's time as unix seconds; 1.x serialises it as an RFC3339 string. The Go structs decoding those payloads declared time as an integer.

  • Adds lnbits.UnixTime, which decodes either form and normalises to unix seconds. Marshalling still emits the number, so the API responses these types are serialised into are unchanged.
  • Applies it to Payment.Time and webhook.Webhook.Time.

The webhook payload carries the same field. Nothing had failed there yet only because no deposit had arrived since the migration — a decode error on that path drops the incoming payment notification, so it is worth fixing in the same change.

InvoiceStream also declares time as an int but is never unmarshalled into (the handler proxies raw SSE bytes), so it is left alone.

Test plan

  • go build ./...
  • go test ./internal/lnbits/...
  • Decoding verified against the live instance's real response shape:
    • "2026-09-13T11:42:41.293908+00:00" (1.x, fractional seconds) → 1789299761
    • "2026-09-13T11:42:41Z" → 1789299761
    • 1702411690 (0.x, as in the Voltage export) → unchanged
    • null / "" → 0, no error
    • marshal round-trip still emits a number
  • Confirm /transactions renders in Telegram after deploy
  • Confirm an incoming deposit notification fires

Note: internal/telegram tests fail at init on a missing config.yaml; this is pre-existing and reproduces identically on a clean main.

🤖 Generated with Claude Code

lnbits 0.x serialises a payment's `time` as unix seconds and 1.x as an
RFC3339 string, so moving the backend to 1.x broke transaction history
with "cannot unmarshal string into Go struct field Payment.time of type
int".

Decode into a UnixTime that takes either form and normalises to seconds.
Marshalling still emits the number, so the API responses these types are
serialised into are unchanged.

The webhook payload carries the same field. Nothing had failed there yet
only because no deposit had arrived since the migration - a decode error
on that path drops the incoming payment notification.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 6814c53f-4b52-40bc-8229-99211b22c810


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@xbuddhi xbuddhi closed this Sep 22, 2026
@xbuddhi
xbuddhi deleted the fix/lnbits-v1-payment-time branch September 22, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant