chore: remove json tags from lnclient models (#2375)

* chore: remove json tags from lnclient models

these should not be passed through the API directly

* fix: properly return not implemented errors

* fix: json tags on TLVRecord
This commit is contained in:
Roland 2026-05-25 21:56:07 +07:00 committed by GitHub
parent 4053a4a722
commit e3373474f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 386 additions and 217 deletions

View file

@ -834,12 +834,20 @@ func (api *api) Stop() error {
return nil
}
func (api *api) GetNodeConnectionInfo(ctx context.Context) (*lnclient.NodeConnectionInfo, error) {
func (api *api) GetNodeConnectionInfo(ctx context.Context) (*NodeConnectionInfo, error) {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return nil, ErrLNClientNotStarted
}
return lnClient.GetNodeConnectionInfo(ctx)
info, err := lnClient.GetNodeConnectionInfo(ctx)
if err != nil {
return nil, err
}
return &NodeConnectionInfo{
Pubkey: info.Pubkey,
Address: info.Address,
Port: info.Port,
}, nil
}
func (api *api) RefundSwap(refundSwapRequest *RefundSwapRequest) error {
@ -1127,20 +1135,47 @@ func (api *api) GetSwapMnemonic() string {
return api.keys.GetSwapMnemonic()
}
func (api *api) GetNodeStatus(ctx context.Context) (*lnclient.NodeStatus, error) {
func (api *api) GetNodeStatus(ctx context.Context) (*NodeStatus, error) {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return nil, ErrLNClientNotStarted
}
return lnClient.GetNodeStatus(ctx)
nodeStatus, err := lnClient.GetNodeStatus(ctx)
if err != nil {
return nil, err
}
if nodeStatus == nil {
return nil, nil
}
return toApiNodeStatus(nodeStatus), nil
}
func (api *api) ListPeers(ctx context.Context) ([]lnclient.PeerDetails, error) {
func toApiNodeStatus(nodeStatus *lnclient.NodeStatus) *NodeStatus {
return &NodeStatus{
IsReady: nodeStatus.IsReady,
InternalNodeStatus: nodeStatus.InternalNodeStatus,
}
}
func (api *api) ListPeers(ctx context.Context) ([]PeerDetails, error) {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return nil, ErrLNClientNotStarted
}
return lnClient.ListPeers(ctx)
peers, err := lnClient.ListPeers(ctx)
if err != nil {
return nil, err
}
apiPeers := make([]PeerDetails, 0, len(peers))
for _, peer := range peers {
apiPeers = append(apiPeers, PeerDetails{
NodeId: peer.NodeId,
Address: peer.Address,
IsPersisted: peer.IsPersisted,
IsConnected: peer.IsConnected,
})
}
return apiPeers, nil
}
func (api *api) ConnectPeer(ctx context.Context, connectPeerRequest *ConnectPeerRequest) error {
@ -1148,7 +1183,11 @@ func (api *api) ConnectPeer(ctx context.Context, connectPeerRequest *ConnectPeer
if lnClient == nil {
return ErrLNClientNotStarted
}
return lnClient.ConnectPeer(ctx, connectPeerRequest)
return lnClient.ConnectPeer(ctx, &lnclient.ConnectPeerRequest{
Pubkey: connectPeerRequest.Pubkey,
Address: connectPeerRequest.Address,
Port: connectPeerRequest.Port,
})
}
func (api *api) OpenChannel(ctx context.Context, openChannelRequest *OpenChannelRequest) (*OpenChannelResponse, error) {
@ -1156,7 +1195,17 @@ func (api *api) OpenChannel(ctx context.Context, openChannelRequest *OpenChannel
if lnClient == nil {
return nil, ErrLNClientNotStarted
}
return lnClient.OpenChannel(ctx, openChannelRequest)
resp, err := lnClient.OpenChannel(ctx, &lnclient.OpenChannelRequest{
Pubkey: openChannelRequest.Pubkey,
AmountSats: openChannelRequest.AmountSats,
Public: openChannelRequest.Public,
})
if err != nil {
return nil, err
}
return &OpenChannelResponse{
FundingTxId: resp.FundingTxId,
}, nil
}
func (api *api) DisconnectPeer(ctx context.Context, peerId string) error {
@ -1180,11 +1229,15 @@ func (api *api) CloseChannel(ctx context.Context, peerId, channelId string, forc
"channel_id": channelId,
"force": force,
}).Info("Closing channel")
return lnClient.CloseChannel(ctx, &lnclient.CloseChannelRequest{
err := lnClient.CloseChannel(ctx, &lnclient.CloseChannelRequest{
NodeId: peerId,
ChannelId: channelId,
Force: force,
})
if err != nil {
return nil, err
}
return &CloseChannelResponse{}, nil
}
func (api *api) UpdateChannel(ctx context.Context, updateChannelRequest *UpdateChannelRequest) error {
@ -1195,7 +1248,13 @@ func (api *api) UpdateChannel(ctx context.Context, updateChannelRequest *UpdateC
logger.Logger.WithFields(logrus.Fields{
"request": updateChannelRequest,
}).Info("updating channel")
return lnClient.UpdateChannel(ctx, updateChannelRequest)
return lnClient.UpdateChannel(ctx, &lnclient.UpdateChannelRequest{
ChannelId: updateChannelRequest.ChannelId,
NodeId: updateChannelRequest.NodeId,
ForwardingFeeBaseMsat: updateChannelRequest.ForwardingFeeBaseMsat,
ForwardingFeeProportionalMillionths: updateChannelRequest.ForwardingFeeProportionalMillionths,
MaxDustHtlcExposureFromFeeRateMultiplier: updateChannelRequest.MaxDustHtlcExposureFromFeeRateMultiplier,
})
}
func (api *api) MakeOffer(ctx context.Context, description string) (string, error) {
@ -1306,7 +1365,70 @@ func (api *api) GetBalances(ctx context.Context) (*BalancesResponse, error) {
if err != nil {
return nil, err
}
return balances, nil
return toApiBalances(balances), nil
}
func toApiBalances(balances *lnclient.BalancesResponse) *BalancesResponse {
totalSpendableMsat := balances.Lightning.TotalSpendableMsat
totalReceivableMsat := balances.Lightning.TotalReceivableMsat
nextMaxSpendableMsat := balances.Lightning.NextMaxSpendableMsat
nextMaxReceivableMsat := balances.Lightning.NextMaxReceivableMsat
nextMaxSpendableMPPMsat := balances.Lightning.NextMaxSpendableMPPMsat
nextMaxReceivableMPPMsat := balances.Lightning.NextMaxReceivableMPPMsat
return &BalancesResponse{
Onchain: OnchainBalanceResponse{
Spendable: balances.Onchain.SpendableSat,
SpendableSat: balances.Onchain.SpendableSat,
Total: balances.Onchain.TotalSat,
TotalSat: balances.Onchain.TotalSat,
Reserved: balances.Onchain.ReservedSat,
ReservedSat: balances.Onchain.ReservedSat,
PendingBalancesFromChannelClosures: balances.Onchain.PendingBalancesFromChannelClosuresSat,
PendingBalancesFromChannelClosuresSat: balances.Onchain.PendingBalancesFromChannelClosuresSat,
PendingBalancesDetails: toApiPendingBalanceDetails(balances.Onchain.PendingBalancesDetails),
PendingSweepBalancesDetails: toApiPendingBalanceDetails(balances.Onchain.PendingSweepBalancesDetails),
InternalBalances: balances.Onchain.InternalBalances,
},
Lightning: LightningBalanceResponse{
TotalSpendable: totalSpendableMsat,
TotalSpendableSat: totalSpendableMsat / 1000,
TotalSpendableMsat: totalSpendableMsat,
TotalReceivable: totalReceivableMsat,
TotalReceivableSat: totalReceivableMsat / 1000,
TotalReceivableMsat: totalReceivableMsat,
NextMaxSpendable: nextMaxSpendableMsat,
NextMaxSpendableSat: nextMaxSpendableMsat / 1000,
NextMaxSpendableMsat: nextMaxSpendableMsat,
NextMaxReceivable: nextMaxReceivableMsat,
NextMaxReceivableSat: nextMaxReceivableMsat / 1000,
NextMaxReceivableMsat: nextMaxReceivableMsat,
NextMaxSpendableMPP: nextMaxSpendableMPPMsat,
NextMaxSpendableMPPSat: nextMaxSpendableMPPMsat / 1000,
NextMaxSpendableMPPMsat: nextMaxSpendableMPPMsat,
NextMaxReceivableMPP: nextMaxReceivableMPPMsat,
NextMaxReceivableMPPSat: nextMaxReceivableMPPMsat / 1000,
NextMaxReceivableMPPMsat: nextMaxReceivableMPPMsat,
},
}
}
func toApiPendingBalanceDetails(details []lnclient.PendingBalanceDetails) []PendingBalanceDetails {
if details == nil {
return nil
}
apiDetails := make([]PendingBalanceDetails, 0, len(details))
for _, d := range details {
apiDetails = append(apiDetails, PendingBalanceDetails{
ChannelId: d.ChannelId,
NodeId: d.NodeId,
Amount: d.AmountSat,
AmountSat: d.AmountSat,
FundingTxId: d.FundingTxId,
FundingTxVout: d.FundingTxVout,
})
}
return apiDetails
}
// TODO: remove dependency on this endpoint
@ -1738,12 +1860,27 @@ func (api *api) SyncWallet() error {
lnClient.UpdateLastWalletSyncRequest()
return nil
}
func (api *api) ListOnchainTransactions(ctx context.Context) ([]lnclient.OnchainTransaction, error) {
func (api *api) ListOnchainTransactions(ctx context.Context) ([]OnchainTransaction, error) {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return nil, ErrLNClientNotStarted
}
return lnClient.ListOnchainTransactions(ctx)
transactions, err := lnClient.ListOnchainTransactions(ctx)
if err != nil {
return nil, err
}
apiTransactions := make([]OnchainTransaction, 0, len(transactions))
for _, t := range transactions {
apiTransactions = append(apiTransactions, OnchainTransaction{
AmountSat: t.AmountSat,
CreatedAt: t.CreatedAt,
State: t.State,
Type: t.Type,
NumConfirmations: t.NumConfirmations,
TxId: t.TxId,
})
}
return apiTransactions, nil
}
func (api *api) GetLogOutput(ctx context.Context, logType string, getLogRequest *GetLogOutputRequest) (*GetLogOutputResponse, error) {
@ -1819,7 +1956,11 @@ func (api *api) Health(ctx context.Context) (*HealthResponse, error) {
if lnClient != nil {
nodeStatus, _ := lnClient.GetNodeStatus(ctx)
if nodeStatus == nil || !nodeStatus.IsReady {
alarms = append(alarms, NewHealthAlarm(HealthAlarmKindNodeNotReady, nodeStatus))
var apiNodeStatus *NodeStatus
if nodeStatus != nil {
apiNodeStatus = toApiNodeStatus(nodeStatus)
}
alarms = append(alarms, NewHealthAlarm(HealthAlarmKindNodeNotReady, apiNodeStatus))
}
channels, err := lnClient.ListChannels(ctx)

View file

@ -8,7 +8,6 @@ import (
"github.com/getAlby/hub/alby"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/swaps"
)
@ -28,9 +27,9 @@ type API interface {
ChangeUnlockPassword(changeUnlockPasswordRequest *ChangeUnlockPasswordRequest) error
SetAutoUnlockPassword(unlockPassword string) error
Stop() error
GetNodeConnectionInfo(ctx context.Context) (*lnclient.NodeConnectionInfo, error)
GetNodeStatus(ctx context.Context) (*lnclient.NodeStatus, error)
ListPeers(ctx context.Context) ([]lnclient.PeerDetails, error)
GetNodeConnectionInfo(ctx context.Context) (*NodeConnectionInfo, error)
GetNodeStatus(ctx context.Context) (*NodeStatus, error)
ListPeers(ctx context.Context) ([]PeerDetails, error)
ConnectPeer(ctx context.Context, connectPeerRequest *ConnectPeerRequest) error
DisconnectPeer(ctx context.Context, peerId string) error
OpenChannel(ctx context.Context, openChannelRequest *OpenChannelRequest) (*OpenChannelResponse, error)
@ -44,7 +43,7 @@ type API interface {
RedeemOnchainFunds(ctx context.Context, toAddress string, amountSat uint64, feeRate *uint64, sendAll bool) (*RedeemOnchainFundsResponse, error)
GetBalances(ctx context.Context) (*BalancesResponse, error)
ListTransactions(ctx context.Context, appId *uint, limit uint64, offset uint64) (*ListTransactionsResponse, error)
ListOnchainTransactions(ctx context.Context) ([]lnclient.OnchainTransaction, error)
ListOnchainTransactions(ctx context.Context) ([]OnchainTransaction, error)
SendPayment(ctx context.Context, invoice string, amountMsat *uint64, metadata map[string]interface{}, fromAppId *uint) (*SendPaymentResponse, error)
CreateInvoice(ctx context.Context, amountMsat uint64, description string) (*MakeInvoiceResponse, error)
LookupInvoice(ctx context.Context, paymentHash string) (*LookupInvoiceResponse, error)
@ -361,11 +360,68 @@ type AutoUnlockRequest struct {
UnlockPassword string `json:"unlockPassword"`
}
type ConnectPeerRequest = lnclient.ConnectPeerRequest
type OpenChannelRequest = lnclient.OpenChannelRequest
type OpenChannelResponse = lnclient.OpenChannelResponse
type CloseChannelResponse = lnclient.CloseChannelResponse
type UpdateChannelRequest = lnclient.UpdateChannelRequest
type ConnectPeerRequest struct {
Pubkey string `json:"pubkey"`
Address string `json:"address"`
Port uint16 `json:"port"`
}
type OpenChannelRequest struct {
Pubkey string `json:"pubkey"`
AmountSats int64 `json:"amountSats"`
Public bool `json:"public"`
}
type OpenChannelResponse struct {
FundingTxId string `json:"fundingTxId"`
}
type CloseChannelResponse struct {
}
type UpdateChannelRequest struct {
ChannelId string `json:"channelId"`
NodeId string `json:"nodeId"`
ForwardingFeeBaseMsat uint32 `json:"forwardingFeeBaseMsat"`
ForwardingFeeProportionalMillionths uint32 `json:"forwardingFeeProportionalMillionths"`
MaxDustHtlcExposureFromFeeRateMultiplier uint64 `json:"maxDustHtlcExposureFromFeeRateMultiplier"`
}
type NodeConnectionInfo struct {
Pubkey string `json:"pubkey"`
Address string `json:"address"`
Port int `json:"port"`
}
type NodeStatus struct {
IsReady bool `json:"isReady"`
InternalNodeStatus interface{} `json:"internalNodeStatus"`
}
type PeerDetails struct {
NodeId string `json:"nodeId"`
Address string `json:"address"`
IsPersisted bool `json:"isPersisted"`
IsConnected bool `json:"isConnected"`
}
type OnchainTransaction struct {
AmountSat uint64 `json:"amountSat"`
CreatedAt uint64 `json:"createdAt"`
State string `json:"state"`
Type string `json:"type"`
NumConfirmations uint32 `json:"numConfirmations"`
TxId string `json:"txId"`
}
type PendingBalanceDetails struct {
ChannelId string `json:"channelId"`
NodeId string `json:"nodeId"`
Amount uint64 `json:"amount"` // deprecated
AmountSat uint64 `json:"amountSat"`
FundingTxId string `json:"fundingTxId"`
FundingTxVout uint32 `json:"fundingTxVout"`
}
type RebalanceChannelRequest struct {
ReceiveThroughNodePubkey string `json:"receiveThroughNodePubkey"`
@ -389,8 +445,45 @@ type RedeemOnchainFundsResponse struct {
TxId string `json:"txId"`
}
type OnchainBalanceResponse = lnclient.OnchainBalanceResponse
type BalancesResponse = lnclient.BalancesResponse
type OnchainBalanceResponse struct {
Spendable int64 `json:"spendable"` // deprecated
SpendableSat int64 `json:"spendableSat"`
Total int64 `json:"total"` // deprecated
TotalSat int64 `json:"totalSat"`
Reserved int64 `json:"reserved"` // deprecated
ReservedSat int64 `json:"reservedSat"`
PendingBalancesFromChannelClosures uint64 `json:"pendingBalancesFromChannelClosures"` // deprecated
PendingBalancesFromChannelClosuresSat uint64 `json:"pendingBalancesFromChannelClosuresSat"`
PendingBalancesDetails []PendingBalanceDetails `json:"pendingBalancesDetails"`
PendingSweepBalancesDetails []PendingBalanceDetails `json:"pendingSweepBalancesDetails"`
InternalBalances interface{} `json:"internalBalances"`
}
type LightningBalanceResponse struct {
TotalSpendable int64 `json:"totalSpendable"` // deprecated
TotalSpendableSat int64 `json:"totalSpendableSat"`
TotalSpendableMsat int64 `json:"totalSpendableMsat"`
TotalReceivable int64 `json:"totalReceivable"` // deprecated
TotalReceivableSat int64 `json:"totalReceivableSat"`
TotalReceivableMsat int64 `json:"totalReceivableMsat"`
NextMaxSpendable int64 `json:"nextMaxSpendable"` // deprecated
NextMaxSpendableSat int64 `json:"nextMaxSpendableSat"`
NextMaxSpendableMsat int64 `json:"nextMaxSpendableMsat"`
NextMaxReceivable int64 `json:"nextMaxReceivable"` // deprecated
NextMaxReceivableSat int64 `json:"nextMaxReceivableSat"`
NextMaxReceivableMsat int64 `json:"nextMaxReceivableMsat"`
NextMaxSpendableMPP int64 `json:"nextMaxSpendableMPP"` // deprecated
NextMaxSpendableMPPSat int64 `json:"nextMaxSpendableMPPSat"`
NextMaxSpendableMPPMsat int64 `json:"nextMaxSpendableMPPMsat"`
NextMaxReceivableMPP int64 `json:"nextMaxReceivableMPP"` // deprecated
NextMaxReceivableMPPSat int64 `json:"nextMaxReceivableMPPSat"`
NextMaxReceivableMPPMsat int64 `json:"nextMaxReceivableMPPMsat"`
}
type BalancesResponse struct {
Onchain OnchainBalanceResponse `json:"onchain"`
Lightning LightningBalanceResponse `json:"lightning"`
}
type SendPaymentResponse = Transaction
type MakeInvoiceResponse = Transaction
@ -503,7 +596,7 @@ type BasicRestoreWailsRequest struct {
UnlockPassword string `json:"unlockPassword"`
}
type NetworkGraphResponse = lnclient.NetworkGraphResponse
type NetworkGraphResponse = interface{}
type LSPOrderRequest struct {
Amount *uint64 `json:"amount"` // deprecated