Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5/5]: lnwallet: extensions to aux leaf store to integrate custom channels #8641

Merged
merged 13 commits into from
May 27, 2024
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ issues:
- forbidigo
- godot

# Allow fmt.Printf() in lncli.
- path: cmd/lncli/*
# Allow fmt.Printf() in commands.
- path: cmd/commands/*
ffranr marked this conversation as resolved.
Show resolved Hide resolved
linters:
- forbidigo

Expand Down
2 changes: 2 additions & 0 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,8 @@ func (h *HTLC) Copy() HTLC {
copy(clone.Signature[:], h.Signature)
copy(clone.RHash[:], h.RHash[:])
copy(clone.ExtraData, h.ExtraData)
clone.BlindingPoint = h.BlindingPoint
clone.CustomRecords = h.CustomRecords.Copy()

return clone
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/lncli/arg_parse.go → cmd/commands/arg_parse.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"regexp"
Expand Down Expand Up @@ -42,7 +42,7 @@ func parseTime(s string, base time.Time) (uint64, error) {

var lightningPrefix = "lightning:"

// stripPrefix removes accidentally copied 'lightning:' prefix.
func stripPrefix(s string) string {
// StripPrefix removes accidentally copied 'lightning:' prefix.
func StripPrefix(s string) string {
return strings.TrimSpace(strings.TrimPrefix(s, lightningPrefix))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"testing"
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestStripPrefix(t *testing.T) {
t.Parallel()

for _, test := range stripPrefixTests {
actual := stripPrefix(test.in)
actual := StripPrefix(test.in)
require.Equal(t, test.expected, actual)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build autopilotrpc
// +build autopilotrpc

package main
package commands

import (
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build !autopilotrpc
// +build !autopilotrpc

package main
package commands

import "github.com/urfave/cli"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build chainrpc
// +build chainrpc

package main
package commands

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build !chainrpc
// +build !chainrpc

package main
package commands

import "github.com/urfave/cli"

Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/cmd_custom.go → cmd/commands/cmd_custom.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"encoding/hex"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/cmd_debug.go → cmd/commands/cmd_debug.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions cmd/lncli/cmd_invoice.go → cmd/commands/cmd_invoice.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"encoding/hex"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/urfave/cli"
)

var addInvoiceCommand = cli.Command{
var AddInvoiceCommand = cli.Command{
Name: "addinvoice",
Category: "Invoices",
Usage: "Add a new invoice.",
Expand Down Expand Up @@ -307,7 +307,7 @@ func decodePayReq(ctx *cli.Context) error {
}

resp, err := client.DecodePayReq(ctxc, &lnrpc.PayReqString{
PayReq: stripPrefix(payreq),
PayReq: StripPrefix(payreq),
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/cmd_macaroon.go → cmd/commands/cmd_macaroon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"fmt"
Expand Down Expand Up @@ -265,6 +265,7 @@ func setCfg(ctx *cli.Context) error {
Config: mcCfg.Config,
},
)

return err
}

Expand Down Expand Up @@ -366,5 +367,6 @@ func resetMissionControl(ctx *cli.Context) error {

req := &routerrpc.ResetMissionControlRequest{}
_, err := client.ResetMissionControl(ctxc, req)

return err
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"bytes"
Expand Down
38 changes: 19 additions & 19 deletions cmd/lncli/cmd_payments.go → cmd/commands/cmd_payments.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"bytes"
Expand Down Expand Up @@ -141,8 +141,8 @@ var (
}
)

// paymentFlags returns common flags for sendpayment and payinvoice.
func paymentFlags() []cli.Flag {
// PaymentFlags returns common flags for sendpayment and payinvoice.
func PaymentFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "pay_req",
Expand Down Expand Up @@ -190,7 +190,7 @@ func paymentFlags() []cli.Flag {
}
}

var sendPaymentCommand = cli.Command{
var SendPaymentCommand = cli.Command{
Name: "sendpayment",
Category: "Payments",
Usage: "Send a payment over lightning.",
Expand All @@ -214,7 +214,7 @@ var sendPaymentCommand = cli.Command{
`,
ArgsUsage: "dest amt payment_hash final_cltv_delta pay_addr | " +
"--pay_req=R [--pay_addr=H]",
Flags: append(paymentFlags(),
Flags: append(PaymentFlags(),
cli.StringFlag{
Name: "dest, d",
Usage: "the compressed identity pubkey of the " +
Expand All @@ -241,7 +241,7 @@ var sendPaymentCommand = cli.Command{
Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
},
),
Action: sendPayment,
Action: SendPayment,
}

// retrieveFeeLimit retrieves the fee limit based on the different fee limit
Expand Down Expand Up @@ -312,7 +312,7 @@ func parsePayAddr(ctx *cli.Context, args cli.Args) ([]byte, error) {
return payAddr, nil
}

func sendPayment(ctx *cli.Context) error {
func SendPayment(ctx *cli.Context) error {
// Show command help if no arguments provided
if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
_ = cli.ShowCommandHelp(ctx, "sendpayment")
Expand All @@ -325,7 +325,7 @@ func sendPayment(ctx *cli.Context) error {
// details of the payment are encoded within the request.
if ctx.IsSet("pay_req") {
req := &routerrpc.SendPaymentRequest{
PaymentRequest: stripPrefix(ctx.String("pay_req")),
PaymentRequest: StripPrefix(ctx.String("pay_req")),
Amt: ctx.Int64("amt"),
DestCustomRecords: make(map[uint64][]byte),
}
Expand All @@ -343,7 +343,7 @@ func sendPayment(ctx *cli.Context) error {

req.PaymentAddr = payAddr

return sendPaymentRequest(ctx, req)
return SendPaymentRequest(ctx, req)
}

var (
Expand Down Expand Up @@ -451,10 +451,10 @@ func sendPayment(ctx *cli.Context) error {

req.PaymentAddr = payAddr

return sendPaymentRequest(ctx, req)
return SendPaymentRequest(ctx, req)
}

func sendPaymentRequest(ctx *cli.Context,
func SendPaymentRequest(ctx *cli.Context,
req *routerrpc.SendPaymentRequest) error {

ctxc := getContext()
Expand Down Expand Up @@ -592,7 +592,7 @@ func sendPaymentRequest(ctx *cli.Context,
return err
}

finalState, err := printLivePayment(
finalState, err := PrintLivePayment(
ctxc, stream, client, printJSON,
)
if err != nil {
Expand Down Expand Up @@ -652,15 +652,15 @@ func trackPayment(ctx *cli.Context) error {
}

client := lnrpc.NewLightningClient(conn)
_, err = printLivePayment(ctxc, stream, client, ctx.Bool(jsonFlag.Name))
_, err = PrintLivePayment(ctxc, stream, client, ctx.Bool(jsonFlag.Name))
return err
}

// printLivePayment receives payment updates from the given stream and either
// PrintLivePayment receives payment updates from the given stream and either
// outputs them as json or as a more user-friendly formatted table. The table
// option uses terminal control codes to rewrite the output. This call
// terminates when the payment reaches a final state.
func printLivePayment(ctxc context.Context,
func PrintLivePayment(ctxc context.Context,
stream routerrpc.Router_TrackPaymentV2Client,
client lnrpc.LightningClient, json bool) (*lnrpc.Payment, error) {

Expand Down Expand Up @@ -859,7 +859,7 @@ var payInvoiceCommand = cli.Command{
This command is a shortcut for 'sendpayment --pay_req='.
`,
ArgsUsage: "pay_req",
Flags: append(paymentFlags(),
Flags: append(PaymentFlags(),
cli.Int64Flag{
Name: "amt",
Usage: "(optional) number of satoshis to fulfill the " +
Expand All @@ -883,12 +883,12 @@ func payInvoice(ctx *cli.Context) error {
}

req := &routerrpc.SendPaymentRequest{
PaymentRequest: stripPrefix(payReq),
PaymentRequest: StripPrefix(payReq),
Amt: ctx.Int64("amt"),
DestCustomRecords: make(map[uint64][]byte),
}

return sendPaymentRequest(ctx, req)
return SendPaymentRequest(ctx, req)
}

var sendToRouteCommand = cli.Command{
Expand Down Expand Up @@ -1870,7 +1870,7 @@ func estimateRouteFee(ctx *cli.Context) error {
req.AmtSat = amtSat

case ctx.IsSet("pay_req"):
req.PaymentRequest = stripPrefix(ctx.String("pay_req"))
req.PaymentRequest = StripPrefix(ctx.String("pay_req"))
if ctx.IsSet("timeout") {
req.Timeout = uint32(ctx.Duration("timeout").Seconds())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/cmd_profile.go → cmd/commands/cmd_profile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/cmd_state.go → cmd/commands/cmd_state.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/cmd_version.go → cmd/commands/cmd_version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package commands

import (
"bufio"
Expand Down