Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ListPeerChannels #314

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 66 additions & 67 deletions clightning/clightning_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ func (l *ListPeers) Call() (jrpc2.Result, error) {
if !l.cl.isReady {
return nil, ErrWaitingForReady
}

peers, err := l.cl.glightning.ListPeers()
res, err := l.cl.glightning.ListPeerChannels("")
if err != nil {
return nil, err
}
Expand All @@ -576,78 +575,78 @@ func (l *ListPeers) Call() (jrpc2.Result, error) {
}

peerSwappers := []*PeerSwapPeer{}
for _, peer := range peers {
if p, ok := polls[peer.Id]; ok {
swaps, err := l.cl.swaps.ListSwapsByPeer(peer.Id)
if err != nil {
return nil, err
}

var paidFees uint64
var ReceiverSwapsOut, ReceiverSwapsIn, ReceiverSatsOut, ReceiverSatsIn uint64
var SenderSwapsOut, SenderSwapsIn, SenderSatsOut, SenderSatsIn uint64
for _, s := range swaps {
// We only list successful swaps. They all end in an
// State_ClaimedPreimage state.
if s.Current == swap.State_ClaimedPreimage {
if s.Role == swap.SWAPROLE_SENDER {
paidFees += s.Data.OpeningTxFee
if s.Type == swap.SWAPTYPE_OUT {
SenderSwapsOut++
SenderSatsOut += s.Data.GetAmount()
} else {
SenderSwapsIn++
SenderSatsIn += s.Data.GetAmount()
}
for _, pc := range res.Channels {
p, ok := polls[pc.PeerId]
if !ok {
continue
}
swaps, err := l.cl.swaps.ListSwapsByPeer(pc.PeerId)
if err != nil {
return nil, err
}
var paidFees uint64
var ReceiverSwapsOut, ReceiverSwapsIn, ReceiverSatsOut, ReceiverSatsIn uint64
var SenderSwapsOut, SenderSwapsIn, SenderSatsOut, SenderSatsIn uint64
for _, s := range swaps {
// We only list successful swaps. They all end in an
// State_ClaimedPreimage state.
if s.Current == swap.State_ClaimedPreimage {
if s.Role == swap.SWAPROLE_SENDER {
paidFees += s.Data.OpeningTxFee
if s.Type == swap.SWAPTYPE_OUT {
SenderSwapsOut++
SenderSatsOut += s.Data.GetAmount()
} else {
SenderSwapsIn++
SenderSatsIn += s.Data.GetAmount()
}
} else {
if s.Type == swap.SWAPTYPE_OUT {
ReceiverSwapsOut++
ReceiverSatsOut += s.Data.GetAmount()
} else {
if s.Type == swap.SWAPTYPE_OUT {
ReceiverSwapsOut++
ReceiverSatsOut += s.Data.GetAmount()
} else {
ReceiverSwapsIn++
ReceiverSatsIn += s.Data.GetAmount()
}
ReceiverSwapsIn++
ReceiverSatsIn += s.Data.GetAmount()
}
}
}
}

peerSwapPeer := &PeerSwapPeer{
NodeId: peer.Id,
SwapsAllowed: p.PeerAllowed,
SupportedAssets: p.Assets,
AsSender: &SwapStats{
SwapsOut: SenderSwapsOut,
SwapsIn: SenderSwapsIn,
SatsOut: SenderSatsOut,
SatsIn: SenderSatsIn,
},
AsReceiver: &SwapStats{
SwapsOut: ReceiverSwapsOut,
SwapsIn: ReceiverSwapsIn,
SatsOut: ReceiverSatsOut,
SatsIn: ReceiverSatsIn,
},
PaidFee: paidFees,
}
channels, err := l.cl.glightning.ListChannelsBySource(peer.Id)
if err != nil {
return nil, err
}
peerSwapPeerChannels := []*PeerSwapPeerChannel{}
for _, channel := range channels {
if c, ok := fundingChannels[channel.ShortChannelId]; ok {
peerSwapPeerChannels = append(peerSwapPeerChannels, &PeerSwapPeerChannel{
ChannelId: c.ShortChannelId,
LocalBalance: c.OurAmountMilliSatoshi.MSat() / 1000,
RemoteBalance: (c.AmountMilliSatoshi.MSat() - c.OurAmountMilliSatoshi.MSat()) / 1000,
State: c.State,
})
}
peerSwapPeer := &PeerSwapPeer{
NodeId: pc.PeerId,
SwapsAllowed: p.PeerAllowed,
SupportedAssets: p.Assets,
AsSender: &SwapStats{
SwapsOut: SenderSwapsOut,
SwapsIn: SenderSwapsIn,
SatsOut: SenderSatsOut,
SatsIn: SenderSatsIn,
},
AsReceiver: &SwapStats{
SwapsOut: ReceiverSwapsOut,
SwapsIn: ReceiverSwapsIn,
SatsOut: ReceiverSatsOut,
SatsIn: ReceiverSatsIn,
},
PaidFee: paidFees,
}
channels, err := l.cl.glightning.ListChannelsBySource(pc.PeerId)
if err != nil {
return nil, err
}
peerSwapPeerChannels := []*PeerSwapPeerChannel{}
for _, channel := range channels {
if c, ok := fundingChannels[channel.ShortChannelId]; ok {
peerSwapPeerChannels = append(peerSwapPeerChannels, &PeerSwapPeerChannel{
ChannelId: c.ShortChannelId,
LocalBalance: c.OurAmountMilliSatoshi.MSat() / 1000,
RemoteBalance: (c.AmountMilliSatoshi.MSat() - c.OurAmountMilliSatoshi.MSat()) / 1000,
State: c.State,
})
}

peerSwapPeer.Channels = peerSwapPeerChannels
peerSwappers = append(peerSwappers, peerSwapPeer)
}
peerSwapPeer.Channels = peerSwapPeerChannels
peerSwappers = append(peerSwappers, peerSwapPeer)
}
return peerSwappers, nil
}
Expand Down
35 changes: 16 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,15 @@ module github.com/elementsproject/peerswap
go 1.18

require (
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.23.3
github.com/btcsuite/btcd/btcec/v2 v2.2.1
github.com/btcsuite/btcd/btcutil v1.1.2
github.com/btcsuite/btcd/btcutil/psbt v1.1.5
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
github.com/jessevdk/go-flags v1.5.0
github.com/lightningnetwork/lnd v0.15.4-beta
github.com/stretchr/testify v1.8.0
github.com/urfave/cli v1.22.9
github.com/vulpemventures/go-elements v0.4.0
github.com/ybbus/jsonrpc v2.1.2+incompatible
go.etcd.io/bbolt v1.3.6
google.golang.org/grpc v1.50.0
google.golang.org/protobuf v1.28.1
gopkg.in/macaroon.v2 v2.1.0
)

require (
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/btcwallet v0.16.1 // indirect
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 // indirect
Expand All @@ -49,6 +33,7 @@ require (
github.com/decred/dcrd/lru v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6 // indirect
github.com/elementsproject/glightning v0.0.0-20240910115322-5c07410a8494
github.com/fergusstrange/embedded-postgres v1.19.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
github.com/go-errors/errors v1.4.2 // indirect
Expand All @@ -60,8 +45,10 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
Expand All @@ -71,6 +58,7 @@ require (
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jessevdk/go-flags v1.5.0
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/jrick/logrotate v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -79,6 +67,7 @@ require (
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/lightninglabs/neutrino v0.14.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.0 // indirect
github.com/lightningnetwork/lnd v0.15.4-beta
github.com/lightningnetwork/lnd/tor v1.1.0 // indirect
github.com/ltcsuite/ltcd v0.22.1-beta // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
Expand All @@ -97,12 +86,17 @@ require (
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/testify v1.8.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect
github.com/urfave/cli v1.22.9
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 // indirect
github.com/vulpemventures/go-elements v0.4.0
github.com/vulpemventures/go-secp256k1-zkp v1.1.5 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/ybbus/jsonrpc v2.1.2+incompatible
go.etcd.io/bbolt v1.3.6
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
go.etcd.io/etcd/client/v2 v2.305.5 // indirect
Expand Down Expand Up @@ -131,8 +125,11 @@ require (
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/tools v0.2.0 // indirect
google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e // indirect
google.golang.org/grpc v1.50.0
google.golang.org/protobuf v1.28.1
gopkg.in/errgo.v1 v1.0.1 // indirect
gopkg.in/macaroon-bakery.v2 v2.3.0 // indirect
gopkg.in/macaroon.v2 v2.1.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6 h1:sE4tvxWw01v7K3MAHwKF2UF3xQbgy23PRURntuV1CkU=
github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a h1:xnVQmVqGmSs3m8zPQF4iYEYiUAmJx8MlT9vJ3lAaOjc=
github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/elementsproject/glightning v0.0.0-20240910115322-5c07410a8494 h1:BI49zLZEXWIvWO2E5Z4cP/TQRfJS6BZzamjT0fD8uEo=
github.com/elementsproject/glightning v0.0.0-20240910115322-5c07410a8494/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
Loading