mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-18 14:24:21 +01:00
move basetypes into lightning
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@@ -136,7 +135,7 @@ func (c *ClnClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelPoint, err := basetypes.NewOutPoint(fundingTxId[:], uint32(fundResult.FundingTxOutputNum))
|
||||
channelPoint, err := lightning.NewOutPoint(fundingTxId[:], uint32(fundResult.FundingTxOutputNum))
|
||||
if err != nil {
|
||||
log.Printf("CLN: NewOutPoint(%s, %d) error: %v", fundingTxId.String(), fundResult.FundingTxOutputNum, err)
|
||||
return nil, err
|
||||
@@ -157,12 +156,12 @@ func (c *ClnClient) GetChannel(peerID []byte, channelPoint wire.OutPoint) (*ligh
|
||||
for _, c := range peer.Channels {
|
||||
log.Printf("getChannel destination: %s, Short channel id: %v, local alias: %v , FundingTxID:%v, State:%v ", pubkey, c.ShortChannelId, c.Alias.Local, c.FundingTxId, c.State)
|
||||
if slices.Contains(OPEN_STATUSES, c.State) && c.FundingTxId == fundingTxID {
|
||||
confirmedChanID, err := basetypes.NewShortChannelIDFromString(c.ShortChannelId)
|
||||
confirmedChanID, err := lightning.NewShortChannelIDFromString(c.ShortChannelId)
|
||||
if err != nil {
|
||||
fmt.Printf("NewShortChannelIDFromString %v error: %v", c.ShortChannelId, err)
|
||||
return nil, err
|
||||
}
|
||||
initialChanID, err := basetypes.NewShortChannelIDFromString(c.Alias.Local)
|
||||
initialChanID, err := lightning.NewShortChannelIDFromString(c.Alias.Local)
|
||||
if err != nil {
|
||||
fmt.Printf("NewShortChannelIDFromString %v error: %v", c.Alias.Local, err)
|
||||
return nil, err
|
||||
@@ -213,7 +212,7 @@ func (c *ClnClient) GetClosedChannels(nodeID string, channelPoints map[string]ui
|
||||
lookup := make(map[string]uint64)
|
||||
for _, c := range peer.Channels {
|
||||
if slices.Contains(CLOSING_STATUSES, c.State) {
|
||||
cid, err := basetypes.NewShortChannelIDFromString(c.ShortChannelId)
|
||||
cid, err := lightning.NewShortChannelIDFromString(c.ShortChannelId)
|
||||
if err != nil {
|
||||
log.Printf("CLN: GetClosedChannels NewShortChannelIDFromString(%v) error: %v", c.ShortChannelId, err)
|
||||
continue
|
||||
@@ -234,7 +233,7 @@ func (c *ClnClient) GetClosedChannels(nodeID string, channelPoints map[string]ui
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (c *ClnClient) GetPeerId(scid *basetypes.ShortChannelID) ([]byte, error) {
|
||||
func (c *ClnClient) GetPeerId(scid *lightning.ShortChannelID) ([]byte, error) {
|
||||
scidStr := scid.ToString()
|
||||
peers, err := c.client.ListPeers()
|
||||
if err != nil {
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/cln_plugin/proto"
|
||||
"github.com/breez/lspd/config"
|
||||
"github.com/breez/lspd/interceptor"
|
||||
"github.com/breez/lspd/lightning"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
@@ -140,7 +140,7 @@ func (i *ClnHtlcInterceptor) intercept() error {
|
||||
return
|
||||
}
|
||||
|
||||
scid, err := basetypes.NewShortChannelIDFromString(request.Onion.ShortChannelId)
|
||||
scid, err := lightning.NewShortChannelIDFromString(request.Onion.ShortChannelId)
|
||||
if err != nil {
|
||||
interceptorClient.Send(i.defaultResolution(request))
|
||||
i.doneWg.Done()
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/chain"
|
||||
"github.com/breez/lspd/config"
|
||||
"github.com/breez/lspd/lightning"
|
||||
@@ -80,7 +79,7 @@ func NewInterceptor(
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Interceptor) Intercept(scid *basetypes.ShortChannelID, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) InterceptResult {
|
||||
func (i *Interceptor) Intercept(scid *lightning.ShortChannelID, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) InterceptResult {
|
||||
reqPaymentHashStr := hex.EncodeToString(reqPaymentHash)
|
||||
log.Printf("Intercept: scid: %s, paymentHash: %s, outgoindAmount: %v, outgoingExpiry: %v, incomingExpiry: %v", scid.ToString(), reqPaymentHashStr, reqOutgoingAmountMsat, reqOutgoingExpiry, reqIncomingExpiry)
|
||||
resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package lightning
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
@@ -13,8 +12,8 @@ type GetInfoResult struct {
|
||||
}
|
||||
|
||||
type GetChannelResult struct {
|
||||
InitialChannelID basetypes.ShortChannelID
|
||||
ConfirmedChannelID basetypes.ShortChannelID
|
||||
InitialChannelID ShortChannelID
|
||||
ConfirmedChannelID ShortChannelID
|
||||
HtlcMinimumMsat uint64
|
||||
}
|
||||
|
||||
@@ -34,7 +33,7 @@ type Client interface {
|
||||
IsConnected(destination []byte) (bool, error)
|
||||
OpenChannel(req *OpenChannelRequest) (*wire.OutPoint, error)
|
||||
GetChannel(peerID []byte, channelPoint wire.OutPoint) (*GetChannelResult, error)
|
||||
GetPeerId(scid *basetypes.ShortChannelID) ([]byte, error)
|
||||
GetPeerId(scid *ShortChannelID) ([]byte, error)
|
||||
GetNodeChannelCount(nodeID []byte) (int, error)
|
||||
GetClosedChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error)
|
||||
WaitOnline(peerID []byte, deadline time.Time) error
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package basetypes
|
||||
package lightning
|
||||
|
||||
import (
|
||||
"log"
|
||||
@@ -1,4 +1,4 @@
|
||||
package basetypes
|
||||
package lightning
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/config"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
@@ -275,7 +274,7 @@ func (c *LndClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoi
|
||||
return nil, fmt.Errorf("LND: OpenChannel() error: %w", err)
|
||||
}
|
||||
|
||||
result, err := basetypes.NewOutPoint(channelPoint.GetFundingTxidBytes(), channelPoint.OutputIndex)
|
||||
result, err := lightning.NewOutPoint(channelPoint.GetFundingTxidBytes(), channelPoint.OutputIndex)
|
||||
if err != nil {
|
||||
log.Printf("LND: OpenChannel returned invalid outpoint. error: %v", err)
|
||||
return nil, err
|
||||
@@ -307,8 +306,8 @@ func (c *LndClient) GetChannel(peerID []byte, channelPoint wire.OutPoint) (*ligh
|
||||
}
|
||||
}
|
||||
return &lightning.GetChannelResult{
|
||||
InitialChannelID: basetypes.ShortChannelID(c.ChanId),
|
||||
ConfirmedChannelID: basetypes.ShortChannelID(confirmedChanId),
|
||||
InitialChannelID: lightning.ShortChannelID(c.ChanId),
|
||||
ConfirmedChannelID: lightning.ShortChannelID(confirmedChanId),
|
||||
HtlcMinimumMsat: c.LocalConstraints.MinHtlcMsat,
|
||||
}, nil
|
||||
}
|
||||
@@ -380,7 +379,7 @@ func (c *LndClient) getWaitingCloseChannels(nodeID string) ([]*lnrpc.PendingChan
|
||||
return waitingCloseChannels, nil
|
||||
}
|
||||
|
||||
func (c *LndClient) GetPeerId(scid *basetypes.ShortChannelID) ([]byte, error) {
|
||||
func (c *LndClient) GetPeerId(scid *lightning.ShortChannelID) ([]byte, error) {
|
||||
scidu64 := uint64(*scid)
|
||||
peer, err := c.client.GetPeerIdByScid(context.Background(), &lnrpc.GetPeerIdByScidRequest{
|
||||
Scid: scidu64,
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/config"
|
||||
"github.com/breez/lspd/interceptor"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
@@ -135,7 +135,7 @@ func (i *LndHtlcInterceptor) intercept() error {
|
||||
|
||||
i.doneWg.Add(1)
|
||||
go func() {
|
||||
scid := basetypes.ShortChannelID(request.OutgoingRequestedChanId)
|
||||
scid := lightning.ShortChannelID(request.OutgoingRequestedChanId)
|
||||
interceptResult := i.interceptor.Intercept(&scid, request.PaymentHash, request.OutgoingAmountMsat, request.OutgoingExpiry, request.IncomingExpiry)
|
||||
switch interceptResult.Action {
|
||||
case interceptor.INTERCEPT_RESUME_WITH_ONION:
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/chain"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/breez/lspd/shared"
|
||||
@@ -61,7 +60,7 @@ func (s *mockLsps2Store) RegisterBuy(ctx context.Context, req *RegisterBuy) erro
|
||||
return s.err
|
||||
}
|
||||
|
||||
func (s *mockLsps2Store) GetBuyRegistration(ctx context.Context, scid basetypes.ShortChannelID) (*BuyRegistration, error) {
|
||||
func (s *mockLsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error) {
|
||||
if s.delay.Nanoseconds() != 0 {
|
||||
<-time.After(s.delay)
|
||||
}
|
||||
@@ -119,7 +118,7 @@ func (c *mockLightningClient) GetChannel(peerID []byte, channelPoint wire.OutPoi
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *mockLightningClient) GetPeerId(scid *basetypes.ShortChannelID) ([]byte, error) {
|
||||
func (c *mockLightningClient) GetPeerId(scid *lightning.ShortChannelID) ([]byte, error) {
|
||||
return nil, ErrNotImplemented
|
||||
}
|
||||
func (c *mockLightningClient) GetNodeChannelCount(nodeID []byte) (int, error) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/lightning"
|
||||
)
|
||||
|
||||
var one = big.NewInt(1)
|
||||
@@ -13,12 +13,12 @@ var sixtyfour = big.NewInt(64)
|
||||
var twoPowSixtyfour = two.Exp(two, sixtyfour, nil)
|
||||
var maxUint64 = twoPowSixtyfour.Sub(twoPowSixtyfour, one)
|
||||
|
||||
func newScid() (*basetypes.ShortChannelID, error) {
|
||||
func newScid() (*lightning.ShortChannelID, error) {
|
||||
s, err := rand.Int(rand.Reader, maxUint64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
scid := basetypes.ShortChannelID(s.Uint64())
|
||||
scid := lightning.ShortChannelID(s.Uint64())
|
||||
return &scid, nil
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/breez/lspd/lsps0"
|
||||
"github.com/breez/lspd/shared"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
type RegisterBuy struct {
|
||||
LspId string
|
||||
PeerId string
|
||||
Scid basetypes.ShortChannelID
|
||||
Scid lightning.ShortChannelID
|
||||
OpeningFeeParams shared.OpeningFeeParams
|
||||
PaymentSizeMsat *uint64
|
||||
Mode OpeningMode
|
||||
@@ -25,7 +25,7 @@ type BuyRegistration struct {
|
||||
Id uint64
|
||||
LspId string
|
||||
PeerId string // TODO: Make peerId in the registration a byte array.
|
||||
Scid basetypes.ShortChannelID
|
||||
Scid lightning.ShortChannelID
|
||||
OpeningFeeParams shared.OpeningFeeParams
|
||||
PaymentSizeMsat *uint64
|
||||
Mode OpeningMode
|
||||
@@ -59,7 +59,7 @@ var ErrNotFound = errors.New("not found")
|
||||
|
||||
type Lsps2Store interface {
|
||||
RegisterBuy(ctx context.Context, req *RegisterBuy) error
|
||||
GetBuyRegistration(ctx context.Context, scid basetypes.ShortChannelID) (*BuyRegistration, error)
|
||||
GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error)
|
||||
SetChannelOpened(ctx context.Context, channelOpened *ChannelOpened) error
|
||||
SetCompleted(ctx context.Context, registrationId uint64) error
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/breez/lspd/shared"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/jackc/pgtype"
|
||||
@@ -45,7 +45,7 @@ func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *s
|
||||
|
||||
var cp *wire.OutPoint
|
||||
if fundingTxID != nil {
|
||||
cp, err = basetypes.NewOutPoint(fundingTxID, uint32(fundingTxOutnum.Int))
|
||||
cp, err = lightning.NewOutPoint(fundingTxID, uint32(fundingTxOutnum.Int))
|
||||
if err != nil {
|
||||
log.Printf("invalid funding txid in database %x", fundingTxID)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/lightning"
|
||||
"github.com/breez/lspd/lsps2"
|
||||
"github.com/breez/lspd/shared"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@@ -64,7 +64,7 @@ func (s *Lsps2Store) RegisterBuy(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid basetypes.ShortChannelID) (*lsps2.BuyRegistration, error) {
|
||||
func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*lsps2.BuyRegistration, error) {
|
||||
row := s.pool.QueryRow(
|
||||
ctx,
|
||||
`SELECT r.id
|
||||
@@ -133,7 +133,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid basetypes.Shor
|
||||
|
||||
var cp *wire.OutPoint
|
||||
if db_funding_tx_id != nil {
|
||||
cp, err = basetypes.NewOutPoint(db_funding_tx_id, db_funding_tx_outnum)
|
||||
cp, err = lightning.NewOutPoint(db_funding_tx_id, db_funding_tx_outnum)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid funding tx id in db: %x", db_funding_tx_id)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid basetypes.Shor
|
||||
Id: db_id,
|
||||
LspId: db_lsp_id,
|
||||
PeerId: db_peer_id,
|
||||
Scid: basetypes.ShortChannelID(uint64(db_scid)),
|
||||
Scid: lightning.ShortChannelID(uint64(db_scid)),
|
||||
OpeningFeeParams: shared.OpeningFeeParams{
|
||||
MinFeeMsat: uint64(db_params_min_fee_msat),
|
||||
Proportional: db_params_proportional,
|
||||
|
||||
Reference in New Issue
Block a user