mirror of
https://github.com/aljazceru/lspd.git
synced 2026-01-19 22:14:30 +01:00
Add field last_update to channels
This commit is contained in:
11
db.go
11
db.go
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgtype"
|
||||
"github.com/jackc/pgx/v4"
|
||||
@@ -70,13 +71,13 @@ func registerPayment(destination, paymentHash, paymentSecret []byte, incomingAmo
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertChannel(chanID uint64, channelPoint string, nodeID []byte) error {
|
||||
func insertChannel(chanID uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error {
|
||||
_, err := pgxPool.Exec(context.Background(),
|
||||
`INSERT INTO
|
||||
channels (chanid, channel_point, nodeid)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (chanid) DO NOTHING`,
|
||||
chanID, channelPoint, nodeID)
|
||||
channels (chanid, channel_point, nodeid, last_update)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (chanid) DO UPDATE SET last_update=$4`,
|
||||
chanID, channelPoint, nodeID, lastUpdate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("insertChannel(%v, %s, %x) error: %w",
|
||||
chanID, channelPoint, nodeID, err)
|
||||
|
||||
@@ -53,13 +53,14 @@ func channelsSynchronizeOnce() error {
|
||||
return fmt.Errorf("client.ListChannels() error: %w", err)
|
||||
}
|
||||
log.Printf("channelsSynchronizeOnce - received channels")
|
||||
lastUpdate := time.Now()
|
||||
for _, c := range channels.Channels {
|
||||
nodeID, err := hex.DecodeString(c.RemotePubkey)
|
||||
if err != nil {
|
||||
log.Printf("hex.DecodeString in channelsSynchronizeOnce error: %v", err)
|
||||
continue
|
||||
}
|
||||
err = insertChannel(c.ChanId, c.ChannelPoint, nodeID)
|
||||
err = insertChannel(c.ChanId, c.ChannelPoint, nodeID, lastUpdate)
|
||||
if err != nil {
|
||||
log.Printf("insertChannel(%v, %v, %x) in channelsSynchronizeOnce error: %v", c.ChanId, c.ChannelPoint, nodeID, err)
|
||||
continue
|
||||
|
||||
@@ -243,7 +243,7 @@ func resumeOrCancel(
|
||||
OutgoingRequestedChanId: chanID,
|
||||
OnionBlob: onionBlob,
|
||||
})
|
||||
err := insertChannel(chanID, channelPoint, destination)
|
||||
err := insertChannel(chanID, channelPoint, destination, time.Now())
|
||||
if err != nil {
|
||||
log.Printf("insertChannel error: %v", err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE public.channels DROP COLUMN last_update;
|
||||
1
postgresql/migrations/000007_channels_last_update.up.sql
Normal file
1
postgresql/migrations/000007_channels_last_update.up.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE public.channels ADD COLUMN last_update TIMESTAMP;
|
||||
Reference in New Issue
Block a user