mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-24 01:04:21 +01:00
Use new zeroconf mechanism from lnd 15.1
This commit is contained in:
34
db.go
34
db.go
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/jackc/pgtype"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -74,17 +73,23 @@ func registerPayment(destination, paymentHash, paymentSecret []byte, incomingAmo
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertChannel(chanID uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error {
|
||||
_, err := pgxPool.Exec(context.Background(),
|
||||
`INSERT INTO
|
||||
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)
|
||||
func insertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error {
|
||||
|
||||
query := `INSERT INTO
|
||||
channels (initial_chanid, confirmed_chanid, channel_point, nodeid, last_update)
|
||||
VALUES ($1, NULLIF($2, 0), $3, $4, $5)
|
||||
ON CONFLICT (channel_point) DO UPDATE SET confirmed_chanid=NULLIF($2,0), last_update=$4`
|
||||
|
||||
c, err := pgxPool.Exec(context.Background(),
|
||||
query, int64(initialChanID), int64(confirmedChanId), channelPoint, nodeID, lastUpdate)
|
||||
if err != nil {
|
||||
log.Printf("insertChannel(%v, %v, %s, %x) error: %v",
|
||||
initialChanID, confirmedChanId, channelPoint, nodeID, err)
|
||||
return fmt.Errorf("insertChannel(%v, %s, %x) error: %w",
|
||||
chanID, channelPoint, nodeID, err)
|
||||
initialChanID, confirmedChanId, nodeID, err)
|
||||
}
|
||||
log.Printf("insertChannel(%v, %s, %x) result: %v",
|
||||
initialChanID, confirmedChanId, nodeID, c.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -94,9 +99,9 @@ func confirmedChannels(sNodeID string) (map[string]uint64, error) {
|
||||
return nil, fmt.Errorf("hex.DecodeString(%v) error: %w", sNodeID, err)
|
||||
}
|
||||
rows, err := pgxPool.Query(context.Background(),
|
||||
`SELECT chanid, channel_point
|
||||
`SELECT confirmed_chanid, channel_point
|
||||
FROM channels
|
||||
WHERE nodeid=$1`,
|
||||
WHERE nodeid=$1 AND confirmed_chanid IS NOT NULL`,
|
||||
nodeID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("channels(%x) error: %w", nodeID, err)
|
||||
@@ -105,17 +110,14 @@ func confirmedChannels(sNodeID string) (map[string]uint64, error) {
|
||||
chans := make(map[string]uint64)
|
||||
for rows.Next() {
|
||||
var (
|
||||
chanID uint64
|
||||
chanID int64
|
||||
channelPoint string
|
||||
)
|
||||
err = rows.Scan(&chanID, &channelPoint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("channels(%x) rows.Scan error: %w", nodeID, err)
|
||||
}
|
||||
sid := lnwire.NewShortChanIDFromInt(chanID)
|
||||
if !sid.IsFake() {
|
||||
chans[channelPoint] = chanID
|
||||
}
|
||||
chans[channelPoint] = uint64(chanID)
|
||||
}
|
||||
return chans, rows.Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user