@@ -35,6 +35,7 @@ import (
35
35
"github.com/lightningnetwork/lnd/invoices"
36
36
"github.com/lightningnetwork/lnd/lncfg"
37
37
"github.com/lightningnetwork/lnd/lnrpc"
38
+ "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
38
39
"github.com/lightningnetwork/lnd/lnwallet"
39
40
"github.com/lightningnetwork/lnd/lnwire"
40
41
"github.com/lightningnetwork/lnd/macaroons"
@@ -3332,111 +3333,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
3332
3333
}, nil
3333
3334
}
3334
3335
3335
- // createRPCInvoice creates an *lnrpc.Invoice from the *channeldb.Invoice.
3336
- func createRPCInvoice (invoice * channeldb.Invoice ) (* lnrpc.Invoice , error ) {
3337
- paymentRequest := string (invoice .PaymentRequest )
3338
- decoded , err := zpay32 .Decode (paymentRequest , activeNetParams .Params )
3339
- if err != nil {
3340
- return nil , fmt .Errorf ("unable to decode payment request: %v" ,
3341
- err )
3342
- }
3343
-
3344
- descHash := []byte ("" )
3345
- if decoded .DescriptionHash != nil {
3346
- descHash = decoded .DescriptionHash [:]
3347
- }
3348
-
3349
- fallbackAddr := ""
3350
- if decoded .FallbackAddr != nil {
3351
- fallbackAddr = decoded .FallbackAddr .String ()
3352
- }
3353
-
3354
- settleDate := int64 (0 )
3355
- if ! invoice .SettleDate .IsZero () {
3356
- settleDate = invoice .SettleDate .Unix ()
3357
- }
3358
-
3359
- // Expiry time will default to 3600 seconds if not specified
3360
- // explicitly.
3361
- expiry := int64 (decoded .Expiry ().Seconds ())
3362
-
3363
- // The expiry will default to 9 blocks if not specified explicitly.
3364
- cltvExpiry := decoded .MinFinalCLTVExpiry ()
3365
-
3366
- // Convert between the `lnrpc` and `routing` types.
3367
- routeHints := createRPCRouteHints (decoded .RouteHints )
3368
-
3369
- preimage := invoice .Terms .PaymentPreimage
3370
- satAmt := invoice .Terms .Value .ToSatoshis ()
3371
- satAmtPaid := invoice .AmtPaid .ToSatoshis ()
3372
-
3373
- isSettled := invoice .Terms .State == channeldb .ContractSettled
3374
-
3375
- var state lnrpc.Invoice_InvoiceState
3376
- switch invoice .Terms .State {
3377
- case channeldb .ContractOpen :
3378
- state = lnrpc .Invoice_OPEN
3379
- case channeldb .ContractSettled :
3380
- state = lnrpc .Invoice_SETTLED
3381
- default :
3382
- return nil , fmt .Errorf ("unknown invoice state" )
3383
- }
3384
-
3385
- return & lnrpc.Invoice {
3386
- Memo : string (invoice .Memo [:]),
3387
- Receipt : invoice .Receipt [:],
3388
- RHash : decoded .PaymentHash [:],
3389
- RPreimage : preimage [:],
3390
- Value : int64 (satAmt ),
3391
- CreationDate : invoice .CreationDate .Unix (),
3392
- SettleDate : settleDate ,
3393
- Settled : isSettled ,
3394
- PaymentRequest : paymentRequest ,
3395
- DescriptionHash : descHash ,
3396
- Expiry : expiry ,
3397
- CltvExpiry : cltvExpiry ,
3398
- FallbackAddr : fallbackAddr ,
3399
- RouteHints : routeHints ,
3400
- AddIndex : invoice .AddIndex ,
3401
- Private : len (routeHints ) > 0 ,
3402
- SettleIndex : invoice .SettleIndex ,
3403
- AmtPaidSat : int64 (satAmtPaid ),
3404
- AmtPaidMsat : int64 (invoice .AmtPaid ),
3405
- AmtPaid : int64 (invoice .AmtPaid ),
3406
- State : state ,
3407
- }, nil
3408
- }
3409
-
3410
- // createRPCRouteHints takes in the decoded form of an invoice's route hints
3411
- // and converts them into the lnrpc type.
3412
- func createRPCRouteHints (routeHints [][]routing.HopHint ) []* lnrpc.RouteHint {
3413
- var res []* lnrpc.RouteHint
3414
-
3415
- for _ , route := range routeHints {
3416
- hopHints := make ([]* lnrpc.HopHint , 0 , len (route ))
3417
- for _ , hop := range route {
3418
- pubKey := hex .EncodeToString (
3419
- hop .NodeID .SerializeCompressed (),
3420
- )
3421
-
3422
- hint := & lnrpc.HopHint {
3423
- NodeId : pubKey ,
3424
- ChanId : hop .ChannelID ,
3425
- FeeBaseMsat : hop .FeeBaseMSat ,
3426
- FeeProportionalMillionths : hop .FeeProportionalMillionths ,
3427
- CltvExpiryDelta : uint32 (hop .CLTVExpiryDelta ),
3428
- }
3429
-
3430
- hopHints = append (hopHints , hint )
3431
- }
3432
-
3433
- routeHint := & lnrpc.RouteHint {HopHints : hopHints }
3434
- res = append (res , routeHint )
3435
- }
3436
-
3437
- return res
3438
- }
3439
-
3440
3336
// LookupInvoice attempts to look up an invoice according to its payment hash.
3441
3337
// The passed payment hash *must* be exactly 32 bytes, if not an error is
3442
3338
// returned.
@@ -3479,7 +3375,9 @@ func (r *rpcServer) LookupInvoice(ctx context.Context,
3479
3375
return spew .Sdump (invoice )
3480
3376
}))
3481
3377
3482
- rpcInvoice , err := createRPCInvoice (& invoice )
3378
+ rpcInvoice , err := invoicesrpc .CreateRPCInvoice (
3379
+ & invoice , activeNetParams .Params ,
3380
+ )
3483
3381
if err != nil {
3484
3382
return nil , err
3485
3383
}
@@ -3519,7 +3417,9 @@ func (r *rpcServer) ListInvoices(ctx context.Context,
3519
3417
LastIndexOffset : invoiceSlice .LastIndexOffset ,
3520
3418
}
3521
3419
for i , invoice := range invoiceSlice .Invoices {
3522
- resp .Invoices [i ], err = createRPCInvoice (& invoice )
3420
+ resp .Invoices [i ], err = invoicesrpc .CreateRPCInvoice (
3421
+ & invoice , activeNetParams .Params ,
3422
+ )
3523
3423
if err != nil {
3524
3424
return nil , err
3525
3425
}
@@ -3541,7 +3441,9 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
3541
3441
for {
3542
3442
select {
3543
3443
case newInvoice := <- invoiceClient .NewInvoices :
3544
- rpcInvoice , err := createRPCInvoice (newInvoice )
3444
+ rpcInvoice , err := invoicesrpc .CreateRPCInvoice (
3445
+ newInvoice , activeNetParams .Params ,
3446
+ )
3545
3447
if err != nil {
3546
3448
return err
3547
3449
}
@@ -3551,7 +3453,9 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
3551
3453
}
3552
3454
3553
3455
case settledInvoice := <- invoiceClient .SettledInvoices :
3554
- rpcInvoice , err := createRPCInvoice (settledInvoice )
3456
+ rpcInvoice , err := invoicesrpc .CreateRPCInvoice (
3457
+ settledInvoice , activeNetParams .Params ,
3458
+ )
3555
3459
if err != nil {
3556
3460
return err
3557
3461
}
@@ -4455,7 +4359,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
4455
4359
expiry := int64 (payReq .Expiry ().Seconds ())
4456
4360
4457
4361
// Convert between the `lnrpc` and `routing` types.
4458
- routeHints := createRPCRouteHints (payReq .RouteHints )
4362
+ routeHints := invoicesrpc . CreateRPCRouteHints (payReq .RouteHints )
4459
4363
4460
4364
amt := int64 (0 )
4461
4365
if payReq .MilliSat != nil {
0 commit comments