lncli: cancel RPC context on OS interrupts

This commit is contained in:
whythat 2020-07-18 18:46:16 +03:00 committed by Elle Mouton
parent fa4155c126
commit 54c93b1b86
19 changed files with 211 additions and 181 deletions

@ -3,8 +3,6 @@
package main package main
import ( import (
"context"
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc" "github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -27,13 +25,13 @@ var getStatusCommand = cli.Command{
} }
func getStatus(ctx *cli.Context) error { func getStatus(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getAutopilotClient(ctx) client, cleanUp := getAutopilotClient(ctx)
defer cleanUp() defer cleanUp()
req := &autopilotrpc.StatusRequest{} req := &autopilotrpc.StatusRequest{}
resp, err := client.Status(ctxb, req) resp, err := client.Status(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -57,7 +55,7 @@ var disableCommand = cli.Command{
} }
func enable(ctx *cli.Context) error { func enable(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getAutopilotClient(ctx) client, cleanUp := getAutopilotClient(ctx)
defer cleanUp() defer cleanUp()
@ -66,7 +64,7 @@ func enable(ctx *cli.Context) error {
Enable: true, Enable: true,
} }
resp, err := client.ModifyStatus(ctxb, req) resp, err := client.ModifyStatus(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -76,7 +74,7 @@ func enable(ctx *cli.Context) error {
} }
func disable(ctx *cli.Context) error { func disable(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getAutopilotClient(ctx) client, cleanUp := getAutopilotClient(ctx)
defer cleanUp() defer cleanUp()
@ -85,7 +83,7 @@ func disable(ctx *cli.Context) error {
Enable: false, Enable: false,
} }
resp, err := client.ModifyStatus(ctxb, req) resp, err := client.ModifyStatus(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -110,7 +108,7 @@ var queryScoresCommand = cli.Command{
} }
func queryScores(ctx *cli.Context) error { func queryScores(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getAutopilotClient(ctx) client, cleanUp := getAutopilotClient(ctx)
defer cleanUp() defer cleanUp()
@ -134,7 +132,7 @@ loop:
IgnoreLocalState: ctx.Bool("ignorelocalstate"), IgnoreLocalState: ctx.Bool("ignorelocalstate"),
} }
resp, err := client.QueryScores(ctxb, req) resp, err := client.QueryScores(ctxc, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
@ -43,6 +42,7 @@ var buildRouteCommand = cli.Command{
} }
func buildRoute(ctx *cli.Context) error { func buildRoute(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
@ -80,8 +80,7 @@ func buildRoute(ctx *cli.Context) error {
OutgoingChanId: ctx.Uint64("outgoing_chan_id"), OutgoingChanId: ctx.Uint64("outgoing_chan_id"),
} }
rpcCtx := context.Background() route, err := client.BuildRoute(ctxc, req)
route, err := client.BuildRoute(rpcCtx, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"strconv" "strconv"
@ -74,7 +73,7 @@ func addInvoice(ctx *cli.Context) error {
amt int64 amt int64
err error err error
) )
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -117,7 +116,7 @@ func addInvoice(ctx *cli.Context) error {
Private: ctx.Bool("private"), Private: ctx.Bool("private"),
} }
resp, err := client.AddInvoice(context.Background(), invoice) resp, err := client.AddInvoice(ctxc, invoice)
if err != nil { if err != nil {
return err return err
} }
@ -143,6 +142,7 @@ var lookupInvoiceCommand = cli.Command{
} }
func lookupInvoice(ctx *cli.Context) error { func lookupInvoice(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -168,7 +168,7 @@ func lookupInvoice(ctx *cli.Context) error {
RHash: rHash, RHash: rHash,
} }
invoice, err := client.LookupInvoice(context.Background(), req) invoice, err := client.LookupInvoice(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -225,6 +225,7 @@ var listInvoicesCommand = cli.Command{
} }
func listInvoices(ctx *cli.Context) error { func listInvoices(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -235,7 +236,7 @@ func listInvoices(ctx *cli.Context) error {
Reversed: !ctx.Bool("paginate-forwards"), Reversed: !ctx.Bool("paginate-forwards"),
} }
invoices, err := client.ListInvoices(context.Background(), req) invoices, err := client.ListInvoices(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -261,7 +262,7 @@ var decodePayReqCommand = cli.Command{
} }
func decodePayReq(ctx *cli.Context) error { func decodePayReq(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -276,7 +277,7 @@ func decodePayReq(ctx *cli.Context) error {
return fmt.Errorf("pay_req argument missing") return fmt.Errorf("pay_req argument missing")
} }
resp, err := client.DecodePayReq(ctxb, &lnrpc.PayReqString{ resp, err := client.DecodePayReq(ctxc, &lnrpc.PayReqString{
PayReq: payreq, PayReq: payreq,
}) })
if err != nil { if err != nil {

@ -2,7 +2,6 @@ package main
import ( import (
"bytes" "bytes"
"context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -75,6 +74,7 @@ var bakeMacaroonCommand = cli.Command{
} }
func bakeMacaroon(ctx *cli.Context) error { func bakeMacaroon(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -151,7 +151,7 @@ func bakeMacaroon(ctx *cli.Context) error {
Permissions: parsedPermissions, Permissions: parsedPermissions,
RootKeyId: rootKeyID, RootKeyId: rootKeyID,
} }
resp, err := client.BakeMacaroon(context.Background(), req) resp, err := client.BakeMacaroon(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -217,11 +217,12 @@ var listMacaroonIDsCommand = cli.Command{
} }
func listMacaroonIDs(ctx *cli.Context) error { func listMacaroonIDs(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.ListMacaroonIDsRequest{} req := &lnrpc.ListMacaroonIDsRequest{}
resp, err := client.ListMacaroonIDs(context.Background(), req) resp, err := client.ListMacaroonIDs(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -250,6 +251,7 @@ var deleteMacaroonIDCommand = cli.Command{
} }
func deleteMacaroonID(ctx *cli.Context) error { func deleteMacaroonID(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -277,7 +279,7 @@ func deleteMacaroonID(ctx *cli.Context) error {
req := &lnrpc.DeleteMacaroonIDRequest{ req := &lnrpc.DeleteMacaroonIDRequest{
RootKeyId: rootKeyID, RootKeyId: rootKeyID,
} }
resp, err := client.DeleteMacaroonID(context.Background(), req) resp, err := client.DeleteMacaroonID(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -295,11 +297,12 @@ var listPermissionsCommand = cli.Command{
} }
func listPermissions(ctx *cli.Context) error { func listPermissions(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
request := &lnrpc.ListPermissionsRequest{} request := &lnrpc.ListPermissionsRequest{}
response, err := client.ListPermissions(context.Background(), request) response, err := client.ListPermissions(ctxc, request)
if err != nil { if err != nil {
return err return err
} }

@ -1,8 +1,6 @@
package main package main
import ( import (
"context"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -17,14 +15,14 @@ var getCfgCommand = cli.Command{
} }
func getCfg(ctx *cli.Context) error { func getCfg(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
client := routerrpc.NewRouterClient(conn) client := routerrpc.NewRouterClient(conn)
ctxb := context.Background()
resp, err := client.GetMissionControlConfig( resp, err := client.GetMissionControlConfig(
ctxb, &routerrpc.GetMissionControlConfigRequest{}, ctxc, &routerrpc.GetMissionControlConfigRequest{},
) )
if err != nil { if err != nil {
return err return err

@ -1,8 +1,6 @@
package main package main
import ( import (
"context"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -45,14 +43,14 @@ var setCfgCommand = cli.Command{
} }
func setCfg(ctx *cli.Context) error { func setCfg(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
client := routerrpc.NewRouterClient(conn) client := routerrpc.NewRouterClient(conn)
ctxb := context.Background()
resp, err := client.GetMissionControlConfig( resp, err := client.GetMissionControlConfig(
ctxb, &routerrpc.GetMissionControlConfigRequest{}, ctxc, &routerrpc.GetMissionControlConfigRequest{},
) )
if err != nil { if err != nil {
return err return err
@ -94,7 +92,7 @@ func setCfg(ctx *cli.Context) error {
} }
_, err = client.SetMissionControlConfig( _, err = client.SetMissionControlConfig(
ctxb, &routerrpc.SetMissionControlConfigRequest{ ctxc, &routerrpc.SetMissionControlConfigRequest{
Config: resp.Config, Config: resp.Config,
}, },
) )

@ -202,7 +202,7 @@ var openChannelCommand = cli.Command{
func openChannel(ctx *cli.Context) error { func openChannel(ctx *cli.Context) error {
// TODO(roasbeef): add deadline to context // TODO(roasbeef): add deadline to context
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -263,7 +263,7 @@ func openChannel(ctx *cli.Context) error {
// Check if connecting to the node was successful. // Check if connecting to the node was successful.
// We discard the peer id returned as it is not needed. // We discard the peer id returned as it is not needed.
_, err := client.ConnectPeer(ctxb, req) _, err := client.ConnectPeer(ctxc, req)
if err != nil && if err != nil &&
!strings.Contains(err.Error(), "already connected") { !strings.Contains(err.Error(), "already connected") {
return err return err
@ -297,14 +297,14 @@ func openChannel(ctx *cli.Context) error {
// PSBT funding is a more involved, interactive process that is too // PSBT funding is a more involved, interactive process that is too
// large to also fit into this already long function. // large to also fit into this already long function.
if ctx.Bool("psbt") { if ctx.Bool("psbt") {
return openChannelPsbt(ctx, client, req) return openChannelPsbt(ctxc, ctx, client, req)
} }
if !ctx.Bool("psbt") && ctx.Bool("no_publish") { if !ctx.Bool("psbt") && ctx.Bool("no_publish") {
return fmt.Errorf("the --no_publish flag can only be used in " + return fmt.Errorf("the --no_publish flag can only be used in " +
"combination with the --psbt flag") "combination with the --psbt flag")
} }
stream, err := client.OpenChannel(ctxb, req) stream, err := client.OpenChannel(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -348,7 +348,8 @@ func openChannel(ctx *cli.Context) error {
// | |-------channel pending------->| | // | |-------channel pending------->| |
// | |-------channel open------------->| // | |-------channel open------------->|
// | | // | |
func openChannelPsbt(ctx *cli.Context, client lnrpc.LightningClient, func openChannelPsbt(rpcCtx context.Context, ctx *cli.Context,
client lnrpc.LightningClient,
req *lnrpc.OpenChannelRequest) error { req *lnrpc.OpenChannelRequest) error {
var ( var (
@ -358,7 +359,7 @@ func openChannelPsbt(ctx *cli.Context, client lnrpc.LightningClient,
quit = make(chan struct{}) quit = make(chan struct{})
srvMsg = make(chan *lnrpc.OpenStatusUpdate, 1) srvMsg = make(chan *lnrpc.OpenStatusUpdate, 1)
srvErr = make(chan error, 1) srvErr = make(chan error, 1)
ctxc, cancel = context.WithCancel(context.Background()) ctxc, cancel = context.WithCancel(rpcCtx)
) )
defer cancel() defer cancel()

@ -338,6 +338,7 @@ func sendPayment(ctx *cli.Context) error {
func sendPaymentRequest(ctx *cli.Context, func sendPaymentRequest(ctx *cli.Context,
req *routerrpc.SendPaymentRequest) error { req *routerrpc.SendPaymentRequest) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
@ -419,9 +420,7 @@ func sendPaymentRequest(ctx *cli.Context,
if req.PaymentRequest != "" { if req.PaymentRequest != "" {
// Decode payment request to find out the amount. // Decode payment request to find out the amount.
decodeReq := &lnrpc.PayReqString{PayReq: req.PaymentRequest} decodeReq := &lnrpc.PayReqString{PayReq: req.PaymentRequest}
decodeResp, err := client.DecodePayReq( decodeResp, err := client.DecodePayReq(ctxc, decodeReq)
context.Background(), decodeReq,
)
if err != nil { if err != nil {
return err return err
} }
@ -462,13 +461,13 @@ func sendPaymentRequest(ctx *cli.Context,
printJSON := ctx.Bool(jsonFlag.Name) printJSON := ctx.Bool(jsonFlag.Name)
req.NoInflightUpdates = !ctx.Bool(inflightUpdatesFlag.Name) && printJSON req.NoInflightUpdates = !ctx.Bool(inflightUpdatesFlag.Name) && printJSON
stream, err := routerClient.SendPaymentV2(context.Background(), req) stream, err := routerClient.SendPaymentV2(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
finalState, err := printLivePayment( finalState, err := printLivePayment(
stream, client, printJSON, ctxc, stream, client, printJSON,
) )
if err != nil { if err != nil {
return err return err
@ -497,6 +496,7 @@ var trackPaymentCommand = cli.Command{
} }
func trackPayment(ctx *cli.Context) error { func trackPayment(ctx *cli.Context) error {
ctxc := getContext()
args := ctx.Args() args := ctx.Args()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
@ -517,13 +517,13 @@ func trackPayment(ctx *cli.Context) error {
PaymentHash: hash, PaymentHash: hash,
} }
stream, err := routerClient.TrackPaymentV2(context.Background(), req) stream, err := routerClient.TrackPaymentV2(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
client := lnrpc.NewLightningClient(conn) client := lnrpc.NewLightningClient(conn)
_, err = printLivePayment(stream, client, ctx.Bool(jsonFlag.Name)) _, err = printLivePayment(ctxc, stream, client, ctx.Bool(jsonFlag.Name))
return err return err
} }
@ -531,7 +531,8 @@ func trackPayment(ctx *cli.Context) error {
// outputs them as json or as a more user-friendly formatted table. The table // 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 // option uses terminal control codes to rewrite the output. This call
// terminates when the payment reaches a final state. // terminates when the payment reaches a final state.
func printLivePayment(stream routerrpc.Router_TrackPaymentV2Client, func printLivePayment(ctxc context.Context,
stream routerrpc.Router_TrackPaymentV2Client,
client lnrpc.LightningClient, json bool) (*lnrpc.Payment, error) { client lnrpc.LightningClient, json bool) (*lnrpc.Payment, error) {
// Terminal escape codes aren't supported on Windows, fall back to json. // Terminal escape codes aren't supported on Windows, fall back to json.
@ -561,7 +562,7 @@ func printLivePayment(stream routerrpc.Router_TrackPaymentV2Client,
// Write raw json to stdout. // Write raw json to stdout.
printRespJSON(payment) printRespJSON(payment)
} else { } else {
table := formatPayment(payment, aliases) table := formatPayment(ctxc, payment, aliases)
// Clear all previously written lines and print the // Clear all previously written lines and print the
// updated table. // updated table.
@ -599,7 +600,7 @@ func newAliasCache(client lnrpc.LightningClient) *aliasCache {
} }
// get returns a node alias either from cache or freshly requested from lnd. // get returns a node alias either from cache or freshly requested from lnd.
func (a *aliasCache) get(pubkey string) string { func (a *aliasCache) get(ctxc context.Context, pubkey string) string {
alias, ok := a.cache[pubkey] alias, ok := a.cache[pubkey]
if ok { if ok {
return alias return alias
@ -607,7 +608,7 @@ func (a *aliasCache) get(pubkey string) string {
// Request node info. // Request node info.
resp, err := a.client.GetNodeInfo( resp, err := a.client.GetNodeInfo(
context.Background(), ctxc,
&lnrpc.NodeInfoRequest{ &lnrpc.NodeInfoRequest{
PubKey: pubkey, PubKey: pubkey,
}, },
@ -630,7 +631,8 @@ func formatMsat(amt int64) string {
} }
// formatPayment formats the payment state as an ascii table. // formatPayment formats the payment state as an ascii table.
func formatPayment(payment *lnrpc.Payment, aliases *aliasCache) string { func formatPayment(ctxc context.Context, payment *lnrpc.Payment,
aliases *aliasCache) string {
t := table.NewWriter() t := table.NewWriter()
// Build table header. // Build table header.
@ -669,7 +671,7 @@ func formatPayment(payment *lnrpc.Payment, aliases *aliasCache) string {
hops := []string{} hops := []string{}
for _, h := range route.Hops { for _, h := range route.Hops {
alias := aliases.get(h.PubKey) alias := aliases.get(ctxc, h.PubKey)
hops = append(hops, alias) hops = append(hops, alias)
} }
@ -891,12 +893,13 @@ func sendToRoute(ctx *cli.Context) error {
} }
func sendToRouteRequest(ctx *cli.Context, req *routerrpc.SendToRouteRequest) error { func sendToRouteRequest(ctx *cli.Context, req *routerrpc.SendToRouteRequest) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
client := routerrpc.NewRouterClient(conn) client := routerrpc.NewRouterClient(conn)
resp, err := client.SendToRouteV2(context.Background(), req) resp, err := client.SendToRouteV2(ctxc, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,8 +1,6 @@
package main package main
import ( import (
"context"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -16,14 +14,14 @@ var queryMissionControlCommand = cli.Command{
} }
func queryMissionControl(ctx *cli.Context) error { func queryMissionControl(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
client := routerrpc.NewRouterClient(conn) client := routerrpc.NewRouterClient(conn)
req := &routerrpc.QueryMissionControlRequest{} req := &routerrpc.QueryMissionControlRequest{}
rpcCtx := context.Background() snapshot, err := client.QueryMissionControl(ctxc, req)
snapshot, err := client.QueryMissionControl(rpcCtx, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"strconv" "strconv"
@ -21,6 +20,7 @@ var queryProbCommand = cli.Command{
} }
func queryProb(ctx *cli.Context) error { func queryProb(ctx *cli.Context) error {
ctxc := getContext()
args := ctx.Args() args := ctx.Args()
if len(args) != 3 { if len(args) != 3 {
@ -56,8 +56,8 @@ func queryProb(ctx *cli.Context) error {
ToNode: toNode[:], ToNode: toNode[:],
AmtMsat: int64(amtMsat), AmtMsat: int64(amtMsat),
} }
rpcCtx := context.Background()
response, err := client.QueryProbability(rpcCtx, req) response, err := client.QueryProbability(ctxc, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,8 +1,6 @@
package main package main
import ( import (
"context"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -16,13 +14,13 @@ var resetMissionControlCommand = cli.Command{
} }
func resetMissionControl(ctx *cli.Context) error { func resetMissionControl(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
client := routerrpc.NewRouterClient(conn) client := routerrpc.NewRouterClient(conn)
req := &routerrpc.ResetMissionControlRequest{} req := &routerrpc.ResetMissionControlRequest{}
rpcCtx := context.Background() _, err := client.ResetMissionControl(ctxc, req)
_, err := client.ResetMissionControl(rpcCtx, req)
return err return err
} }

@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"errors" "errors"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -51,6 +50,7 @@ var updateChanStatusCommand = cli.Command{
} }
func updateChanStatus(ctx *cli.Context) error { func updateChanStatus(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
@ -82,8 +82,7 @@ func updateChanStatus(ctx *cli.Context) error {
} }
client := routerrpc.NewRouterClient(conn) client := routerrpc.NewRouterClient(conn)
ctxb := context.Background() resp, err := client.UpdateChanStatus(ctxc, req)
resp, err := client.UpdateChanStatus(ctxb, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/build"
@ -21,6 +20,7 @@ var versionCommand = cli.Command{
} }
func version(ctx *cli.Context) error { func version(ctx *cli.Context) error {
ctxc := getContext()
conn := getClientConn(ctx, false) conn := getClientConn(ctx, false)
defer conn.Close() defer conn.Close()
@ -40,8 +40,7 @@ func version(ctx *cli.Context) error {
client := verrpc.NewVersionerClient(conn) client := verrpc.NewVersionerClient(conn)
ctxb := context.Background() lndVersion, err := client.GetVersion(ctxc, &verrpc.VersionRequest{})
lndVersion, err := client.GetVersion(ctxb, &verrpc.VersionRequest{})
if err != nil { if err != nil {
printRespJSON(versions) printRespJSON(versions)
return fmt.Errorf("unable fetch version from lnd: %v", err) return fmt.Errorf("unable fetch version from lnd: %v", err)

@ -3,7 +3,6 @@ package main
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -115,7 +114,7 @@ func monowidthColumns(words []string, ncols int) []string {
} }
func create(ctx *cli.Context) error { func create(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getWalletUnlockerClient(ctx) client, cleanUp := getWalletUnlockerClient(ctx)
defer cleanUp() defer cleanUp()
@ -343,7 +342,7 @@ mnemonicCheck:
genSeedReq := &lnrpc.GenSeedRequest{ genSeedReq := &lnrpc.GenSeedRequest{
AezeedPassphrase: aezeedPass, AezeedPassphrase: aezeedPass,
} }
seedResp, err := client.GenSeed(ctxb, genSeedReq) seedResp, err := client.GenSeed(ctxc, genSeedReq)
if err != nil { if err != nil {
return fmt.Errorf("unable to generate seed: %v", err) return fmt.Errorf("unable to generate seed: %v", err)
} }
@ -384,7 +383,7 @@ mnemonicCheck:
ChannelBackups: chanBackups, ChannelBackups: chanBackups,
StatelessInit: statelessInit, StatelessInit: statelessInit,
} }
response, err := client.InitWallet(ctxb, req) response, err := client.InitWallet(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -481,7 +480,7 @@ var unlockCommand = cli.Command{
} }
func unlock(ctx *cli.Context) error { func unlock(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getWalletUnlockerClient(ctx) client, cleanUp := getWalletUnlockerClient(ctx)
defer cleanUp() defer cleanUp()
@ -533,7 +532,7 @@ func unlock(ctx *cli.Context) error {
RecoveryWindow: recoveryWindow, RecoveryWindow: recoveryWindow,
StatelessInit: ctx.Bool(statelessInitFlag.Name), StatelessInit: ctx.Bool(statelessInitFlag.Name),
} }
_, err = client.UnlockWallet(ctxb, req) _, err = client.UnlockWallet(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -591,7 +590,7 @@ var changePasswordCommand = cli.Command{
} }
func changePassword(ctx *cli.Context) error { func changePassword(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getWalletUnlockerClient(ctx) client, cleanUp := getWalletUnlockerClient(ctx)
defer cleanUp() defer cleanUp()
@ -630,7 +629,7 @@ func changePassword(ctx *cli.Context) error {
NewMacaroonRootKey: ctx.Bool("new_mac_root_key"), NewMacaroonRootKey: ctx.Bool("new_mac_root_key"),
} }
response, err := client.ChangePassword(ctxb, req) response, err := client.ChangePassword(ctxc, req)
if err != nil { if err != nil {
return err return err
} }

@ -23,6 +23,7 @@ import (
"github.com/lightninglabs/protobuf-hex-display/proto" "github.com/lightninglabs/protobuf-hex-display/proto"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/signal"
"github.com/urfave/cli" "github.com/urfave/cli"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -39,6 +40,15 @@ const (
defaultUtxoMinConf = 1 defaultUtxoMinConf = 1
) )
func getContext() context.Context {
ctxc, cancel := context.WithCancel(context.Background())
go func() {
<-signal.ShutdownChannel()
cancel()
}()
return ctxc
}
func printJSON(resp interface{}) { func printJSON(resp interface{}) {
b, err := json.Marshal(resp) b, err := json.Marshal(resp)
if err != nil { if err != nil {
@ -119,6 +129,7 @@ var newAddressCommand = cli.Command{
} }
func newAddress(ctx *cli.Context) error { func newAddress(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -137,8 +148,7 @@ func newAddress(ctx *cli.Context) error {
"are: p2wkh and np2wkh", stringAddrType) "are: p2wkh and np2wkh", stringAddrType)
} }
ctxb := context.Background() addr, err := client.NewAddress(ctxc, &lnrpc.NewAddressRequest{
addr, err := client.NewAddress(ctxb, &lnrpc.NewAddressRequest{
Type: addrType, Type: addrType,
}) })
if err != nil { if err != nil {
@ -172,6 +182,7 @@ var estimateFeeCommand = cli.Command{
} }
func estimateFees(ctx *cli.Context) error { func estimateFees(ctx *cli.Context) error {
ctxc := getContext()
var amountToAddr map[string]int64 var amountToAddr map[string]int64
jsonMap := ctx.Args().First() jsonMap := ctx.Args().First()
@ -179,11 +190,10 @@ func estimateFees(ctx *cli.Context) error {
return err return err
} }
ctxb := context.Background()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
resp, err := client.EstimateFee(ctxb, &lnrpc.EstimateFeeRequest{ resp, err := client.EstimateFee(ctxc, &lnrpc.EstimateFeeRequest{
AddrToAmount: amountToAddr, AddrToAmount: amountToAddr,
TargetConf: int32(ctx.Int64("conf_target")), TargetConf: int32(ctx.Int64("conf_target")),
}) })
@ -260,6 +270,7 @@ func sendCoins(ctx *cli.Context) error {
amt int64 amt int64
err error err error
) )
ctxc := getContext()
args := ctx.Args() args := ctx.Args()
if ctx.NArg() == 0 && ctx.NumFlags() == 0 { if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
@ -299,7 +310,6 @@ func sendCoins(ctx *cli.Context) error {
"sweep all coins out of the wallet") "sweep all coins out of the wallet")
} }
ctxb := context.Background()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -314,7 +324,7 @@ func sendCoins(ctx *cli.Context) error {
MinConfs: minConfs, MinConfs: minConfs,
SpendUnconfirmed: minConfs == 0, SpendUnconfirmed: minConfs == 0,
} }
txid, err := client.SendCoins(ctxb, req) txid, err := client.SendCoins(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -367,6 +377,7 @@ func listUnspent(ctx *cli.Context) error {
maxConfirms int64 maxConfirms int64
err error err error
) )
ctxc := getContext()
args := ctx.Args() args := ctx.Args()
if ctx.IsSet("max_confs") && !ctx.IsSet("min_confs") { if ctx.IsSet("max_confs") && !ctx.IsSet("min_confs") {
@ -413,7 +424,6 @@ func listUnspent(ctx *cli.Context) error {
maxConfirms = math.MaxInt32 maxConfirms = math.MaxInt32
} }
ctxb := context.Background()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -421,7 +431,7 @@ func listUnspent(ctx *cli.Context) error {
MinConfs: int32(minConfirms), MinConfs: int32(minConfirms),
MaxConfs: int32(maxConfirms), MaxConfs: int32(maxConfirms),
} }
resp, err := client.ListUnspent(ctxb, req) resp, err := client.ListUnspent(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -481,6 +491,7 @@ var sendManyCommand = cli.Command{
} }
func sendMany(ctx *cli.Context) error { func sendMany(ctx *cli.Context) error {
ctxc := getContext()
var amountToAddr map[string]int64 var amountToAddr map[string]int64
jsonMap := ctx.Args().First() jsonMap := ctx.Args().First()
@ -493,12 +504,11 @@ func sendMany(ctx *cli.Context) error {
"set, but not both") "set, but not both")
} }
ctxb := context.Background()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
minConfs := int32(ctx.Uint64("min_confs")) minConfs := int32(ctx.Uint64("min_confs"))
txid, err := client.SendMany(ctxb, &lnrpc.SendManyRequest{ txid, err := client.SendMany(ctxc, &lnrpc.SendManyRequest{
AddrToAmount: amountToAddr, AddrToAmount: amountToAddr,
TargetConf: int32(ctx.Int64("conf_target")), TargetConf: int32(ctx.Int64("conf_target")),
SatPerByte: ctx.Int64("sat_per_byte"), SatPerByte: ctx.Int64("sat_per_byte"),
@ -546,7 +556,7 @@ var connectCommand = cli.Command{
} }
func connectPeer(ctx *cli.Context) error { func connectPeer(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -567,7 +577,7 @@ func connectPeer(ctx *cli.Context) error {
Timeout: uint64(ctx.Duration("timeout").Seconds()), Timeout: uint64(ctx.Duration("timeout").Seconds()),
} }
lnid, err := client.ConnectPeer(ctxb, req) lnid, err := client.ConnectPeer(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -592,7 +602,7 @@ var disconnectCommand = cli.Command{
} }
func disconnectPeer(ctx *cli.Context) error { func disconnectPeer(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -610,7 +620,7 @@ func disconnectPeer(ctx *cli.Context) error {
PubKey: pubKey, PubKey: pubKey,
} }
lnid, err := client.DisconnectPeer(ctxb, req) lnid, err := client.DisconnectPeer(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -689,6 +699,7 @@ var closeChannelCommand = cli.Command{
} }
func closeChannel(ctx *cli.Context) error { func closeChannel(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -731,7 +742,7 @@ func closeChannel(ctx *cli.Context) error {
}) })
}() }()
err = executeChannelClose(client, req, txidChan, ctx.Bool("block")) err = executeChannelClose(ctxc, client, req, txidChan, ctx.Bool("block"))
if err != nil { if err != nil {
return err return err
} }
@ -748,10 +759,10 @@ func closeChannel(ctx *cli.Context) error {
// transaction ID is sent through `txidChan` as soon as it is broadcasted to the // transaction ID is sent through `txidChan` as soon as it is broadcasted to the
// network. The block boolean is used to determine if we should block until the // network. The block boolean is used to determine if we should block until the
// closing transaction receives all of its required confirmations. // closing transaction receives all of its required confirmations.
func executeChannelClose(client lnrpc.LightningClient, req *lnrpc.CloseChannelRequest, func executeChannelClose(ctxc context.Context, client lnrpc.LightningClient,
txidChan chan<- string, block bool) error { req *lnrpc.CloseChannelRequest, txidChan chan<- string, block bool) error {
stream, err := client.CloseChannel(context.Background(), req) stream, err := client.CloseChannel(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -834,11 +845,12 @@ var closeAllChannelsCommand = cli.Command{
} }
func closeAllChannels(ctx *cli.Context) error { func closeAllChannels(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
listReq := &lnrpc.ListChannelsRequest{} listReq := &lnrpc.ListChannelsRequest{}
openChannels, err := client.ListChannels(context.Background(), listReq) openChannels, err := client.ListChannels(ctxc, listReq)
if err != nil { if err != nil {
return fmt.Errorf("unable to fetch open channels: %v", err) return fmt.Errorf("unable to fetch open channels: %v", err)
} }
@ -969,7 +981,7 @@ func closeAllChannels(ctx *cli.Context) error {
} }
txidChan := make(chan string, 1) txidChan := make(chan string, 1)
err = executeChannelClose(client, req, txidChan, false) err = executeChannelClose(ctxc, client, req, txidChan, false)
if err != nil { if err != nil {
res.FailErr = fmt.Sprintf("unable to close "+ res.FailErr = fmt.Sprintf("unable to close "+
"channel: %v", err) "channel: %v", err)
@ -1044,8 +1056,7 @@ var abandonChannelCommand = cli.Command{
} }
func abandonChannel(ctx *cli.Context) error { func abandonChannel(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1064,7 +1075,7 @@ func abandonChannel(ctx *cli.Context) error {
ChannelPoint: channelPoint, ChannelPoint: channelPoint,
} }
resp, err := client.AbandonChannel(ctxb, req) resp, err := client.AbandonChannel(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1124,7 +1135,7 @@ var listPeersCommand = cli.Command{
} }
func listPeers(ctx *cli.Context) error { func listPeers(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1133,7 +1144,7 @@ func listPeers(ctx *cli.Context) error {
req := &lnrpc.ListPeersRequest{ req := &lnrpc.ListPeersRequest{
LatestError: !ctx.IsSet("list_errors"), LatestError: !ctx.IsSet("list_errors"),
} }
resp, err := client.ListPeers(ctxb, req) resp, err := client.ListPeers(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1150,12 +1161,12 @@ var walletBalanceCommand = cli.Command{
} }
func walletBalance(ctx *cli.Context) error { func walletBalance(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.WalletBalanceRequest{} req := &lnrpc.WalletBalanceRequest{}
resp, err := client.WalletBalance(ctxb, req) resp, err := client.WalletBalance(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1173,12 +1184,12 @@ var channelBalanceCommand = cli.Command{
} }
func channelBalance(ctx *cli.Context) error { func channelBalance(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.ChannelBalanceRequest{} req := &lnrpc.ChannelBalanceRequest{}
resp, err := client.ChannelBalance(ctxb, req) resp, err := client.ChannelBalance(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1194,12 +1205,12 @@ var getInfoCommand = cli.Command{
} }
func getInfo(ctx *cli.Context) error { func getInfo(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.GetInfoRequest{} req := &lnrpc.GetInfoRequest{}
resp, err := client.GetInfo(ctxb, req) resp, err := client.GetInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1215,12 +1226,12 @@ var getRecoveryInfoCommand = cli.Command{
} }
func getRecoveryInfo(ctx *cli.Context) error { func getRecoveryInfo(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.GetRecoveryInfoRequest{} req := &lnrpc.GetRecoveryInfoRequest{}
resp, err := client.GetRecoveryInfo(ctxb, req) resp, err := client.GetRecoveryInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1237,12 +1248,12 @@ var pendingChannelsCommand = cli.Command{
} }
func pendingChannels(ctx *cli.Context) error { func pendingChannels(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.PendingChannelsRequest{} req := &lnrpc.PendingChannelsRequest{}
resp, err := client.PendingChannels(ctxb, req) resp, err := client.PendingChannels(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1284,7 +1295,7 @@ var listChannelsCommand = cli.Command{
} }
func listChannels(ctx *cli.Context) error { func listChannels(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1310,7 +1321,7 @@ func listChannels(ctx *cli.Context) error {
Peer: peerKey, Peer: peerKey,
} }
resp, err := client.ListChannels(ctxb, req) resp, err := client.ListChannels(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1359,7 +1370,7 @@ var closedChannelsCommand = cli.Command{
} }
func closedChannels(ctx *cli.Context) error { func closedChannels(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1372,7 +1383,7 @@ func closedChannels(ctx *cli.Context) error {
Abandoned: ctx.Bool("abandoned"), Abandoned: ctx.Bool("abandoned"),
} }
resp, err := client.ClosedChannels(ctxb, req) resp, err := client.ClosedChannels(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1400,6 +1411,7 @@ var describeGraphCommand = cli.Command{
} }
func describeGraph(ctx *cli.Context) error { func describeGraph(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1407,7 +1419,7 @@ func describeGraph(ctx *cli.Context) error {
IncludeUnannounced: ctx.Bool("include_unannounced"), IncludeUnannounced: ctx.Bool("include_unannounced"),
} }
graph, err := client.DescribeGraph(context.Background(), req) graph, err := client.DescribeGraph(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1425,6 +1437,7 @@ var getNodeMetricsCommand = cli.Command{
} }
func getNodeMetrics(ctx *cli.Context) error { func getNodeMetrics(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1432,7 +1445,7 @@ func getNodeMetrics(ctx *cli.Context) error {
Types: []lnrpc.NodeMetricType{lnrpc.NodeMetricType_BETWEENNESS_CENTRALITY}, Types: []lnrpc.NodeMetricType{lnrpc.NodeMetricType_BETWEENNESS_CENTRALITY},
} }
nodeMetrics, err := client.GetNodeMetrics(context.Background(), req) nodeMetrics, err := client.GetNodeMetrics(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1487,6 +1500,7 @@ var listPaymentsCommand = cli.Command{
} }
func listPayments(ctx *cli.Context) error { func listPayments(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1497,7 +1511,7 @@ func listPayments(ctx *cli.Context) error {
Reversed: !ctx.Bool("paginate_forwards"), Reversed: !ctx.Bool("paginate_forwards"),
} }
payments, err := client.ListPayments(context.Background(), req) payments, err := client.ListPayments(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1523,7 +1537,7 @@ var getChanInfoCommand = cli.Command{
} }
func getChanInfo(ctx *cli.Context) error { func getChanInfo(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1548,7 +1562,7 @@ func getChanInfo(ctx *cli.Context) error {
ChanId: uint64(chanID), ChanId: uint64(chanID),
} }
chanInfo, err := client.GetChanInfo(ctxb, req) chanInfo, err := client.GetChanInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1579,7 +1593,7 @@ var getNodeInfoCommand = cli.Command{
} }
func getNodeInfo(ctx *cli.Context) error { func getNodeInfo(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1600,7 +1614,7 @@ func getNodeInfo(ctx *cli.Context) error {
IncludeChannels: ctx.Bool("include_channels"), IncludeChannels: ctx.Bool("include_channels"),
} }
nodeInfo, err := client.GetNodeInfo(ctxb, req) nodeInfo, err := client.GetNodeInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1655,7 +1669,7 @@ var queryRoutesCommand = cli.Command{
} }
func queryRoutes(ctx *cli.Context) error { func queryRoutes(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1704,7 +1718,7 @@ func queryRoutes(ctx *cli.Context) error {
OutgoingChanId: ctx.Uint64("outgoing_chanid"), OutgoingChanId: ctx.Uint64("outgoing_chanid"),
} }
route, err := client.QueryRoutes(ctxb, req) route, err := client.QueryRoutes(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1756,13 +1770,13 @@ var getNetworkInfoCommand = cli.Command{
} }
func getNetworkInfo(ctx *cli.Context) error { func getNetworkInfo(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.NetworkInfoRequest{} req := &lnrpc.NetworkInfoRequest{}
netInfo, err := client.GetNetworkInfo(ctxb, req) netInfo, err := client.GetNetworkInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1792,7 +1806,7 @@ var debugLevelCommand = cli.Command{
} }
func debugLevel(ctx *cli.Context) error { func debugLevel(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.DebugLevelRequest{ req := &lnrpc.DebugLevelRequest{
@ -1800,7 +1814,7 @@ func debugLevel(ctx *cli.Context) error {
LevelSpec: ctx.String("level"), LevelSpec: ctx.String("level"),
} }
resp, err := client.DebugLevel(ctxb, req) resp, err := client.DebugLevel(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1844,7 +1858,7 @@ var listChainTxnsCommand = cli.Command{
} }
func listChainTxns(ctx *cli.Context) error { func listChainTxns(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1857,7 +1871,7 @@ func listChainTxns(ctx *cli.Context) error {
req.EndHeight = int32(ctx.Int64("end_height")) req.EndHeight = int32(ctx.Int64("end_height"))
} }
resp, err := client.GetTransactions(ctxb, req) resp, err := client.GetTransactions(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -1876,11 +1890,11 @@ var stopCommand = cli.Command{
} }
func stopDaemon(ctx *cli.Context) error { func stopDaemon(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
_, err := client.StopDaemon(ctxb, &lnrpc.StopRequest{}) _, err := client.StopDaemon(ctxc, &lnrpc.StopRequest{})
if err != nil { if err != nil {
return err return err
} }
@ -1908,7 +1922,7 @@ var signMessageCommand = cli.Command{
} }
func signMessage(ctx *cli.Context) error { func signMessage(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1923,7 +1937,7 @@ func signMessage(ctx *cli.Context) error {
return fmt.Errorf("msg argument missing") return fmt.Errorf("msg argument missing")
} }
resp, err := client.SignMessage(ctxb, &lnrpc.SignMessageRequest{Msg: msg}) resp, err := client.SignMessage(ctxc, &lnrpc.SignMessageRequest{Msg: msg})
if err != nil { if err != nil {
return err return err
} }
@ -1957,7 +1971,7 @@ var verifyMessageCommand = cli.Command{
} }
func verifyMessage(ctx *cli.Context) error { func verifyMessage(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -1988,7 +2002,7 @@ func verifyMessage(ctx *cli.Context) error {
} }
req := &lnrpc.VerifyMessageRequest{Msg: msg, Signature: sig} req := &lnrpc.VerifyMessageRequest{Msg: msg, Signature: sig}
resp, err := client.VerifyMessage(ctxb, req) resp, err := client.VerifyMessage(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -2008,12 +2022,12 @@ var feeReportCommand = cli.Command{
} }
func feeReport(ctx *cli.Context) error { func feeReport(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
req := &lnrpc.FeeReportRequest{} req := &lnrpc.FeeReportRequest{}
resp, err := client.FeeReport(ctxb, req) resp, err := client.FeeReport(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -2101,7 +2115,7 @@ func parseChanPoint(s string) (*lnrpc.ChannelPoint, error) {
} }
func updateChannelPolicy(ctx *cli.Context) error { func updateChannelPolicy(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -2196,7 +2210,7 @@ func updateChannelPolicy(ctx *cli.Context) error {
} }
} }
resp, err := client.UpdateChannelPolicy(ctxb, req) resp, err := client.UpdateChannelPolicy(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -2252,7 +2266,7 @@ var forwardingHistoryCommand = cli.Command{
} }
func forwardingHistory(ctx *cli.Context) error { func forwardingHistory(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -2321,7 +2335,7 @@ func forwardingHistory(ctx *cli.Context) error {
IndexOffset: indexOffset, IndexOffset: indexOffset,
NumMaxEvents: maxEvents, NumMaxEvents: maxEvents,
} }
resp, err := client.ForwardingHistory(ctxb, req) resp, err := client.ForwardingHistory(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -2384,7 +2398,7 @@ var exportChanBackupCommand = cli.Command{
} }
func exportChanBackup(ctx *cli.Context) error { func exportChanBackup(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -2418,7 +2432,7 @@ func exportChanBackup(ctx *cli.Context) error {
} }
chanBackup, err := client.ExportChannelBackup( chanBackup, err := client.ExportChannelBackup(
ctxb, &lnrpc.ExportChannelBackupRequest{ ctxc, &lnrpc.ExportChannelBackupRequest{
ChanPoint: chanPointRPC, ChanPoint: chanPointRPC,
}, },
) )
@ -2453,7 +2467,7 @@ func exportChanBackup(ctx *cli.Context) error {
} }
chanBackup, err := client.ExportAllChannelBackups( chanBackup, err := client.ExportAllChannelBackups(
ctxb, &lnrpc.ChanBackupExportRequest{}, ctxc, &lnrpc.ChanBackupExportRequest{},
) )
if err != nil { if err != nil {
return err return err
@ -2529,7 +2543,7 @@ var verifyChanBackupCommand = cli.Command{
} }
func verifyChanBackup(ctx *cli.Context) error { func verifyChanBackup(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -2555,7 +2569,7 @@ func verifyChanBackup(ctx *cli.Context) error {
} }
} }
resp, err := client.VerifyChanBackup(ctxb, &verifyReq) resp, err := client.VerifyChanBackup(ctxc, &verifyReq)
if err != nil { if err != nil {
return err return err
} }
@ -2671,7 +2685,7 @@ func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error)
} }
func restoreChanBackup(ctx *cli.Context) error { func restoreChanBackup(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -2690,7 +2704,7 @@ func restoreChanBackup(ctx *cli.Context) error {
req.Backup = backups.Backup req.Backup = backups.Backup
_, err = client.RestoreChannelBackups(ctxb, &req) _, err = client.RestoreChannelBackups(ctxc, &req)
if err != nil { if err != nil {
return fmt.Errorf("unable to restore chan backups: %v", err) return fmt.Errorf("unable to restore chan backups: %v", err)
} }

@ -3,7 +3,6 @@
package main package main
import ( import (
"context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
@ -56,6 +55,7 @@ func settleInvoice(ctx *cli.Context) error {
err error err error
) )
ctxc := getContext()
client, cleanUp := getInvoicesClient(ctx) client, cleanUp := getInvoicesClient(ctx)
defer cleanUp() defer cleanUp()
@ -76,7 +76,7 @@ func settleInvoice(ctx *cli.Context) error {
Preimage: preimage, Preimage: preimage,
} }
resp, err := client.SettleInvoice(context.Background(), invoice) resp, err := client.SettleInvoice(ctxc, invoice)
if err != nil { if err != nil {
return err return err
} }
@ -109,6 +109,7 @@ func cancelInvoice(ctx *cli.Context) error {
err error err error
) )
ctxc := getContext()
client, cleanUp := getInvoicesClient(ctx) client, cleanUp := getInvoicesClient(ctx)
defer cleanUp() defer cleanUp()
@ -129,7 +130,7 @@ func cancelInvoice(ctx *cli.Context) error {
PaymentHash: paymentHash, PaymentHash: paymentHash,
} }
resp, err := client.CancelInvoice(context.Background(), invoice) resp, err := client.CancelInvoice(ctxc, invoice)
if err != nil { if err != nil {
return err return err
} }
@ -199,6 +200,7 @@ func addHoldInvoice(ctx *cli.Context) error {
err error err error
) )
ctxc := getContext()
client, cleanUp := getInvoicesClient(ctx) client, cleanUp := getInvoicesClient(ctx)
defer cleanUp() defer cleanUp()
@ -245,7 +247,7 @@ func addHoldInvoice(ctx *cli.Context) error {
Private: ctx.Bool("private"), Private: ctx.Bool("private"),
} }
resp, err := client.AddHoldInvoice(context.Background(), invoice) resp, err := client.AddHoldInvoice(ctxc, invoice)
if err != nil { if err != nil {
return err return err
} }

@ -3,7 +3,6 @@
package main package main
import ( import (
"context"
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
@ -75,12 +74,12 @@ var pendingSweepsCommand = cli.Command{
} }
func pendingSweeps(ctx *cli.Context) error { func pendingSweeps(ctx *cli.Context) error {
ctxb := context.Background() ctxc := getContext()
client, cleanUp := getWalletClient(ctx) client, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
req := &walletrpc.PendingSweepsRequest{} req := &walletrpc.PendingSweepsRequest{}
resp, err := client.PendingSweeps(ctxb, req) resp, err := client.PendingSweeps(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -165,6 +164,8 @@ var bumpFeeCommand = cli.Command{
} }
func bumpFee(ctx *cli.Context) error { func bumpFee(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if we do not have the expected // Display the command's help message if we do not have the expected
// number of arguments/flags. // number of arguments/flags.
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
@ -180,7 +181,7 @@ func bumpFee(ctx *cli.Context) error {
client, cleanUp := getWalletClient(ctx) client, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
resp, err := client.BumpFee(context.Background(), &walletrpc.BumpFeeRequest{ resp, err := client.BumpFee(ctxc, &walletrpc.BumpFeeRequest{
Outpoint: protoOutPoint, Outpoint: protoOutPoint,
TargetConf: uint32(ctx.Uint64("conf_target")), TargetConf: uint32(ctx.Uint64("conf_target")),
SatPerByte: uint32(ctx.Uint64("sat_per_byte")), SatPerByte: uint32(ctx.Uint64("sat_per_byte")),
@ -222,6 +223,8 @@ var bumpCloseFeeCommand = cli.Command{
} }
func bumpCloseFee(ctx *cli.Context) error { func bumpCloseFee(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if we do not have the expected // Display the command's help message if we do not have the expected
// number of arguments/flags. // number of arguments/flags.
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
@ -249,9 +252,8 @@ func bumpCloseFee(ctx *cli.Context) error {
walletClient, cleanUp := getWalletClient(ctx) walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
ctxb := context.Background()
sweeps, err := walletClient.PendingSweeps( sweeps, err := walletClient.PendingSweeps(
ctxb, &walletrpc.PendingSweepsRequest{}, ctxc, &walletrpc.PendingSweepsRequest{},
) )
if err != nil { if err != nil {
return err return err
@ -286,7 +288,7 @@ func bumpCloseFee(ctx *cli.Context) error {
fmt.Printf("Bumping fee of %v:%v\n", fmt.Printf("Bumping fee of %v:%v\n",
sweepTxID, sweep.Outpoint.OutputIndex) sweepTxID, sweep.Outpoint.OutputIndex)
_, err = walletClient.BumpFee(ctxb, &walletrpc.BumpFeeRequest{ _, err = walletClient.BumpFee(ctxc, &walletrpc.BumpFeeRequest{
Outpoint: sweep.Outpoint, Outpoint: sweep.Outpoint,
TargetConf: uint32(ctx.Uint64("conf_target")), TargetConf: uint32(ctx.Uint64("conf_target")),
SatPerByte: uint32(ctx.Uint64("sat_per_byte")), SatPerByte: uint32(ctx.Uint64("sat_per_byte")),
@ -304,10 +306,10 @@ func getWaitingCloseCommitments(client lnrpc.LightningClient,
channelPoint string) (*lnrpc.PendingChannelsResponse_Commitments, channelPoint string) (*lnrpc.PendingChannelsResponse_Commitments,
error) { error) {
ctxb := context.Background() ctxc := getContext()
req := &lnrpc.PendingChannelsRequest{} req := &lnrpc.PendingChannelsRequest{}
resp, err := client.PendingChannels(ctxb, req) resp, err := client.PendingChannels(ctxc, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -343,11 +345,12 @@ var listSweepsCommand = cli.Command{
} }
func listSweeps(ctx *cli.Context) error { func listSweeps(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getWalletClient(ctx) client, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
resp, err := client.ListSweeps( resp, err := client.ListSweeps(
context.Background(), &walletrpc.ListSweepsRequest{ ctxc, &walletrpc.ListSweepsRequest{
Verbose: ctx.IsSet("verbose"), Verbose: ctx.IsSet("verbose"),
}, },
) )
@ -380,6 +383,8 @@ var labelTxCommand = cli.Command{
} }
func labelTransaction(ctx *cli.Context) error { func labelTransaction(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if we do not have the expected // Display the command's help message if we do not have the expected
// number of arguments/flags. // number of arguments/flags.
if ctx.NArg() != 2 { if ctx.NArg() != 2 {
@ -398,9 +403,8 @@ func labelTransaction(ctx *cli.Context) error {
walletClient, cleanUp := getWalletClient(ctx) walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
ctxb := context.Background()
_, err = walletClient.LabelTransaction( _, err = walletClient.LabelTransaction(
ctxb, &walletrpc.LabelTransactionRequest{ ctxc, &walletrpc.LabelTransactionRequest{
Txid: hash[:], Txid: hash[:],
Label: label, Label: label,
Overwrite: ctx.Bool("overwrite"), Overwrite: ctx.Bool("overwrite"),
@ -494,6 +498,8 @@ var fundPsbtCommand = cli.Command{
} }
func fundPsbt(ctx *cli.Context) error { func fundPsbt(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if there aren't any flags // Display the command's help message if there aren't any flags
// specified. // specified.
if ctx.NumFlags() == 0 { if ctx.NumFlags() == 0 {
@ -594,7 +600,7 @@ func fundPsbt(ctx *cli.Context) error {
walletClient, cleanUp := getWalletClient(ctx) walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
response, err := walletClient.FundPsbt(context.Background(), req) response, err := walletClient.FundPsbt(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -652,6 +658,8 @@ var finalizePsbtCommand = cli.Command{
} }
func finalizePsbt(ctx *cli.Context) error { func finalizePsbt(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if we do not have the expected // Display the command's help message if we do not have the expected
// number of arguments/flags. // number of arguments/flags.
if ctx.NArg() != 1 && ctx.NumFlags() != 1 { if ctx.NArg() != 1 && ctx.NumFlags() != 1 {
@ -682,7 +690,7 @@ func finalizePsbt(ctx *cli.Context) error {
walletClient, cleanUp := getWalletClient(ctx) walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
response, err := walletClient.FinalizePsbt(context.Background(), req) response, err := walletClient.FinalizePsbt(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -717,6 +725,8 @@ var releaseOutputCommand = cli.Command{
} }
func releaseOutput(ctx *cli.Context) error { func releaseOutput(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if we do not have the expected // Display the command's help message if we do not have the expected
// number of arguments/flags. // number of arguments/flags.
if ctx.NArg() != 1 && ctx.NumFlags() != 1 { if ctx.NArg() != 1 && ctx.NumFlags() != 1 {
@ -748,7 +758,7 @@ func releaseOutput(ctx *cli.Context) error {
walletClient, cleanUp := getWalletClient(ctx) walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp() defer cleanUp()
response, err := walletClient.ReleaseOutput(context.Background(), req) response, err := walletClient.ReleaseOutput(ctxc, req)
if err != nil { if err != nil {
return err return err
} }

@ -3,8 +3,6 @@
package main package main
import ( import (
"context"
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc" "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -37,6 +35,7 @@ var towerInfoCommand = cli.Command{
} }
func towerInfo(ctx *cli.Context) error { func towerInfo(ctx *cli.Context) error {
ctxc := getContext()
if ctx.NArg() != 0 || ctx.NumFlags() > 0 { if ctx.NArg() != 0 || ctx.NumFlags() > 0 {
return cli.ShowCommandHelp(ctx, "info") return cli.ShowCommandHelp(ctx, "info")
} }
@ -45,7 +44,7 @@ func towerInfo(ctx *cli.Context) error {
defer cleanup() defer cleanup()
req := &watchtowerrpc.GetInfoRequest{} req := &watchtowerrpc.GetInfoRequest{}
resp, err := client.GetInfo(context.Background(), req) resp, err := client.GetInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }

@ -1,7 +1,6 @@
package main package main
import ( import (
"context"
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
@ -51,6 +50,8 @@ var addTowerCommand = cli.Command{
} }
func addTower(ctx *cli.Context) error { func addTower(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() != 1 || ctx.NumFlags() > 0 { if ctx.NArg() != 1 || ctx.NumFlags() > 0 {
@ -74,7 +75,7 @@ func addTower(ctx *cli.Context) error {
Pubkey: pubKey, Pubkey: pubKey,
Address: address, Address: address,
} }
resp, err := client.AddTower(context.Background(), req) resp, err := client.AddTower(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -96,6 +97,8 @@ var removeTowerCommand = cli.Command{
} }
func removeTower(ctx *cli.Context) error { func removeTower(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() != 1 || ctx.NumFlags() > 0 { if ctx.NArg() != 1 || ctx.NumFlags() > 0 {
@ -130,7 +133,7 @@ func removeTower(ctx *cli.Context) error {
Pubkey: pubKey, Pubkey: pubKey,
Address: address, Address: address,
} }
resp, err := client.RemoveTower(context.Background(), req) resp, err := client.RemoveTower(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -153,6 +156,8 @@ var listTowersCommand = cli.Command{
} }
func listTowers(ctx *cli.Context) error { func listTowers(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() > 0 || ctx.NumFlags() > 1 { if ctx.NArg() > 0 || ctx.NumFlags() > 1 {
@ -165,7 +170,7 @@ func listTowers(ctx *cli.Context) error {
req := &wtclientrpc.ListTowersRequest{ req := &wtclientrpc.ListTowersRequest{
IncludeSessions: ctx.Bool("include_sessions"), IncludeSessions: ctx.Bool("include_sessions"),
} }
resp, err := client.ListTowers(context.Background(), req) resp, err := client.ListTowers(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -190,6 +195,8 @@ var getTowerCommand = cli.Command{
} }
func getTower(ctx *cli.Context) error { func getTower(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() != 1 || ctx.NumFlags() > 1 { if ctx.NArg() != 1 || ctx.NumFlags() > 1 {
@ -211,7 +218,7 @@ func getTower(ctx *cli.Context) error {
Pubkey: pubKey, Pubkey: pubKey,
IncludeSessions: ctx.Bool("include_sessions"), IncludeSessions: ctx.Bool("include_sessions"),
} }
resp, err := client.GetTowerInfo(context.Background(), req) resp, err := client.GetTowerInfo(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -227,6 +234,8 @@ var statsCommand = cli.Command{
} }
func stats(ctx *cli.Context) error { func stats(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() > 0 || ctx.NumFlags() > 0 { if ctx.NArg() > 0 || ctx.NumFlags() > 0 {
@ -237,7 +246,7 @@ func stats(ctx *cli.Context) error {
defer cleanUp() defer cleanUp()
req := &wtclientrpc.StatsRequest{} req := &wtclientrpc.StatsRequest{}
resp, err := client.Stats(context.Background(), req) resp, err := client.Stats(ctxc, req)
if err != nil { if err != nil {
return err return err
} }
@ -264,6 +273,8 @@ var policyCommand = cli.Command{
} }
func policy(ctx *cli.Context) error { func policy(ctx *cli.Context) error {
ctxc := getContext()
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() > 0 || ctx.NumFlags() > 1 { if ctx.NArg() > 0 || ctx.NumFlags() > 1 {
@ -288,7 +299,7 @@ func policy(ctx *cli.Context) error {
req := &wtclientrpc.PolicyRequest{ req := &wtclientrpc.PolicyRequest{
PolicyType: policyType, PolicyType: policyType,
} }
resp, err := client.Policy(context.Background(), req) resp, err := client.Policy(ctxc, req)
if err != nil { if err != nil {
return err return err
} }