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

Commit

Permalink
Implemented RedeemOnchainFunds() for LDK and Greenlight.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmitr committed Mar 18, 2024
1 parent b0e292b commit 2046146
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 13 additions & 2 deletions greenlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,19 @@ func (gs *GreenlightService) GetOnchainBalance(ctx context.Context) (int64, erro

return balance / 1000, nil
}
func (gs *GreenlightService) RedeemOnchainFunds(ctx context.Context, toAddress string) (txId string, err error) {
return "", nil

func (gs *GreenlightService) RedeemOnchainFunds(ctx context.Context, toAddress string) (string, error) {
amountAll := glalby.AmountOrAll(glalby.AmountOrAllAll{})

Check failure on line 479 in greenlight.go

View workflow job for this annotation

GitHub Actions / build

undefined: glalby.AmountOrAll

Check failure on line 479 in greenlight.go

View workflow job for this annotation

GitHub Actions / build

undefined: glalby.AmountOrAllAll
txId, err := gs.client.Withdraw(glalby.WithdrawRequest{

Check failure on line 480 in greenlight.go

View workflow job for this annotation

GitHub Actions / build

gs.client.Withdraw undefined (type *glalby.BlockingGreenlightAlbyClient has no field or method Withdraw)

Check failure on line 480 in greenlight.go

View workflow job for this annotation

GitHub Actions / build

undefined: glalby.WithdrawRequest
Destination: toAddress,
Amount: &amountAll,
})
if err != nil {
gs.svc.Logger.Errorf("Withdraw failed: %v", err)
return "", err
}

return txId.Txid, nil
}

func (gs *GreenlightService) greenlightInvoiceToTransaction(invoice *glalby.ListInvoicesInvoice) (*Nip47Transaction, error) {
Expand Down
12 changes: 9 additions & 3 deletions ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
"time"

"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"

"github.com/getAlby/nostr-wallet-connect/models/lnclient"
)

type LDKService struct {
Expand Down Expand Up @@ -474,8 +475,13 @@ func (gs *LDKService) GetOnchainBalance(ctx context.Context) (int64, error) {
return int64(balances.SpendableOnchainBalanceSats), nil
}

func (gs *LDKService) RedeemOnchainFunds(ctx context.Context, toAddress string) (txId string, err error) {
return "", nil
func (gs *LDKService) RedeemOnchainFunds(ctx context.Context, toAddress string) (string, error) {
txId, err := gs.node.SendAllToOnchainAddress(toAddress)
if err != nil {
gs.svc.Logger.Errorf("SendAllToOnchainAddress failed: %v", err)
return "", err
}
return txId, nil
}

func (gs *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails) (*Nip47Transaction, error) {
Expand Down

0 comments on commit 2046146

Please sign in to comment.