From 856c4b5a1d7e1452fcbc8018d82dd4eac633b5bf Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Fri, 4 Feb 2022 11:00:26 +0100 Subject: [PATCH] add invoice handling --- lnd/c-lightning.go | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/lnd/c-lightning.go b/lnd/c-lightning.go index df2156e..d71de38 100644 --- a/lnd/c-lightning.go +++ b/lnd/c-lightning.go @@ -43,12 +43,42 @@ func NewCLNClient(options CLNClientOptions) (*CLNClient, error) { }, nil } +//todo handle errors? func (cln *CLNClient) Recv() (invoice *lnrpc.Invoice, err error) { - return nil, nil + return <-cln.handler.invoiceChan, nil } -func (handler *InvoiceHandler) Handle(gjson.Result) { - invoice := &lnrpc.Invoice{} +func (handler *InvoiceHandler) Handle(res gjson.Result) { + //todo missing or wrong fields + invoice := &lnrpc.Invoice{ + Memo: res.Get("description").String(), + RPreimage: []byte(res.Get("payment_preimage").String()), + RHash: []byte(res.Get("payment_hash").String()), + Value: res.Get("amount_msat").Int() / MSAT_PER_SAT, + ValueMsat: res.Get("amount_msat").Int(), + Settled: true, + CreationDate: 0, + SettleDate: res.Get("paid_at").Int(), + PaymentRequest: res.Get("bolt11").String(), + DescriptionHash: []byte{}, + Expiry: 0, + FallbackAddr: "", + CltvExpiry: 0, + RouteHints: []*lnrpc.RouteHint{}, + Private: false, + AddIndex: 0, + SettleIndex: 0, + AmtPaid: res.Get("amount_msat").Int() / MSAT_PER_SAT, + AmtPaidSat: res.Get("amount_msat").Int() / MSAT_PER_SAT, + AmtPaidMsat: res.Get("amount_msat").Int(), + State: lnrpc.Invoice_SETTLED, + Htlcs: []*lnrpc.InvoiceHTLC{}, + Features: map[uint32]*lnrpc.Feature{}, + IsKeysend: false, + PaymentAddr: []byte{}, + IsAmp: false, + AmpInvoiceState: map[string]*lnrpc.AMPInvoiceState{}, + } handler.invoiceChan <- invoice }