Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #66 from getAlby/chore/ldk-node-go
Browse files Browse the repository at this point in the history
chore: use ldk-node-go library
  • Loading branch information
rolznz authored Feb 28, 2024
2 parents d0bb63a + 81732cf commit a786632
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 5,441 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build -o main .

RUN cp `find /go/pkg/mod/github.com/breez/ |grep linux-amd64 |grep libbreez_sdk_bindings.so` ./
RUN cp `find /go/pkg/mod/github.com/get\!alby/ | grep libglalby_bindings.so` ./
RUN cp `find /go/pkg/mod/github.com/get\!alby/ | grep libldk_node.so` ./

# Start a new, final image to reduce size.
FROM debian as final
Expand All @@ -47,9 +48,7 @@ ENV LD_LIBRARY_PATH=/usr/lib/nwc
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/libbreez_sdk_bindings.so /usr/lib/nwc/
COPY --from=builder /build/libglalby_bindings.so /usr/lib/nwc/
COPY --from=builder /build/libldk_node.so /usr/lib/nwc/
COPY --from=builder /build/main /bin/

# Temporary LDK bindings
COPY ldk_node ./ldk_node

ENTRYPOINT [ "/bin/main" ]
6 changes: 0 additions & 6 deletions cgo.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/breez/breez-sdk-go v0.2.14
github.com/davrux/echo-logrus/v4 v4.0.3
github.com/getAlby/glalby v0.0.0-20240226164227-cfe1edfbd521
github.com/getAlby/ldk-node-go v0.0.0-20240228063727-c5d07042affd
github.com/go-gormigrate/gormigrate/v2 v2.1.1
github.com/gorilla/sessions v1.2.1
github.com/labstack/echo-contrib v0.14.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/getAlby/glalby v0.0.0-20240226164227-cfe1edfbd521 h1:qJC4Xifpye6JmHNRacLX8DU61nroRfPmgEg1IseF2fI=
github.com/getAlby/glalby v0.0.0-20240226164227-cfe1edfbd521/go.mod h1:JiWFguAzff5K771myoDISYOjRB6uRoA+DI0+pJkksno=
github.com/getAlby/ldk-node-go v0.0.0-20240228063727-c5d07042affd h1:3vC2qdqlf+T6u14fMGzgIP1dX6nRIyy3tB3PQw0guZ4=
github.com/getAlby/ldk-node-go v0.0.0-20240228063727-c5d07042affd/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
19 changes: 9 additions & 10 deletions ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

"github.com/getAlby/nostr-wallet-connect/ldk_node" // TODO: include this from an external library
"github.com/getAlby/ldk-node-go/ldk_node"
"github.com/getAlby/nostr-wallet-connect/models/lnclient"
decodepay "github.com/nbd-wtf/ln-decodepay"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -214,7 +214,7 @@ func (gs *LDKService) GetBalance(ctx context.Context) (balance int64, err error)

balance = 0
for _, channel := range channels {
balance += int64(channel.BalanceMsat)
balance += int64(channel.OutboundCapacityMsat)
}

return balance, nil
Expand Down Expand Up @@ -368,12 +368,15 @@ func (gs *LDKService) OpenChannel(ctx context.Context, openChannelRequest *lncli
}

gs.svc.Logger.Infof("Opening channel with: %v", foundPeer.NodeId)
err := gs.node.ConnectOpenChannel(foundPeer.NodeId, foundPeer.Address, uint64(openChannelRequest.Amount), nil, nil, openChannelRequest.Public)
userChannelId, err := gs.node.ConnectOpenChannel(foundPeer.NodeId, foundPeer.Address, uint64(openChannelRequest.Amount), nil, nil, openChannelRequest.Public)
if err != nil {
gs.svc.Logger.Errorf("OpenChannel failed: %v", err)
return nil, err
}

// userChannelId allows to locally keep track of the channel
gs.svc.Logger.Infof("Funded channel: %v", userChannelId)

eventListener := gs.subscribeLdkEvents()
defer gs.unsubscribeLdkEvents(eventListener)
for start := time.Now(); time.Since(start) < time.Second*60; {
Expand Down Expand Up @@ -403,13 +406,9 @@ func (gs *LDKService) GetNewOnchainAddress(ctx context.Context) (string, error)
}

func (gs *LDKService) GetOnchainBalance(ctx context.Context) (int64, error) {
balance, err := gs.node.SpendableOnchainBalanceSats()
gs.svc.Logger.Infof("SpendableOnchainBalanceSats: %v", balance)
if err != nil {
gs.svc.Logger.Errorf("SpendableOnchainBalanceSats failed: %v", err)
return 0, err
}
return int64(balance), nil
balances := gs.node.ListBalances()
gs.svc.Logger.Infof("SpendableOnchainBalanceSats: %v", balances.SpendableOnchainBalanceSats)
return int64(balances.SpendableOnchainBalanceSats), nil
}

func ldkPaymentToTransaction(payment *ldk_node.PaymentDetails) *Nip47Transaction {
Expand Down
3 changes: 0 additions & 3 deletions ldk_node/TODO.txt

This file was deleted.

8 changes: 0 additions & 8 deletions ldk_node/ldk_node.c

This file was deleted.

Loading

0 comments on commit a786632

Please sign in to comment.