Skip to content

Commit

Permalink
feat: add lnd implementation of lookup_invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Aug 29, 2023
1 parent 820e3ef commit 730caaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ func (svc *LNDService) MakeInvoice(ctx context.Context, senderPubkey string, amo
}

func (svc *LNDService) LookupInvoice(ctx context.Context, senderPubkey string, paymentHash string) (invoice string, paid bool, err error) {
return "", false, fmt.Errorf("not implemented")
paymentHashBytes, err := hex.DecodeString(paymentHash)

if err != nil || len(paymentHashBytes) != 32 {
svc.Logger.WithFields(logrus.Fields{
"paymentHash": paymentHash,
}).Errorf("Invalid payment hash")
return "", false, errors.New("Payment hash must be 32 bytes hex")
}

lndInvoice, err := svc.client.LookupInvoice(ctx, &lnrpc.PaymentHash{ RHash: paymentHashBytes })
if err != nil {
return "", false, err
}

return lndInvoice.PaymentRequest, lndInvoice.State == *lnrpc.Invoice_SETTLED.Enum(), nil;
}

func (svc *LNDService) SendPaymentSync(ctx context.Context, senderPubkey, payReq string) (preimage string, err error) {
Expand Down
1 change: 1 addition & 0 deletions lnd/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type LightningClientWrapper interface {
AddInvoice(ctx context.Context, req *lnrpc.Invoice, options ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error)
SubscribeInvoices(ctx context.Context, req *lnrpc.InvoiceSubscription, options ...grpc.CallOption) (SubscribeInvoicesWrapper, error)
SubscribePayment(ctx context.Context, req *routerrpc.TrackPaymentRequest, options ...grpc.CallOption) (SubscribePaymentWrapper, error)
LookupInvoice(ctx context.Context, req *lnrpc.PaymentHash, options ...grpc.CallOption) (*lnrpc.Invoice, error)
GetInfo(ctx context.Context, req *lnrpc.GetInfoRequest, options ...grpc.CallOption) (*lnrpc.GetInfoResponse, error)
DecodeBolt11(ctx context.Context, bolt11 string, options ...grpc.CallOption) (*lnrpc.PayReq, error)
IsIdentityPubkey(pubkey string) (isOurPubkey bool)
Expand Down
4 changes: 4 additions & 0 deletions lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (wrapper *LNDWrapper) SubscribeInvoices(ctx context.Context, req *lnrpc.Inv
return wrapper.client.SubscribeInvoices(ctx, req, options...)
}

func (wrapper *LNDWrapper) LookupInvoice(ctx context.Context, req *lnrpc.PaymentHash, options ...grpc.CallOption) (*lnrpc.Invoice, error) {
return wrapper.client.LookupInvoice(ctx, req, options...)
}

func (wrapper *LNDWrapper) GetInfo(ctx context.Context, req *lnrpc.GetInfoRequest, options ...grpc.CallOption) (*lnrpc.GetInfoResponse, error) {
return wrapper.client.GetInfo(ctx, req, options...)
}
Expand Down

0 comments on commit 730caaa

Please sign in to comment.