Merge pull request #5097 from ellemouton/lncli-interrupt-handler

lncli: cancel RPC context on OS interrupts
This commit is contained in:
Oliver Gugger 2021-03-17 10:31:08 +01:00 committed by GitHub
commit 05342f25b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 211 additions and 181 deletions

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

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

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

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

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

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

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

@ -338,6 +338,7 @@ func sendPayment(ctx *cli.Context) error {
func sendPaymentRequest(ctx *cli.Context,
req *routerrpc.SendPaymentRequest) error {
ctxc := getContext()
conn := getClientConn(ctx, false)
defer conn.Close()
@ -419,9 +420,7 @@ func sendPaymentRequest(ctx *cli.Context,
if req.PaymentRequest != "" {
// Decode payment request to find out the amount.
decodeReq := &lnrpc.PayReqString{PayReq: req.PaymentRequest}
decodeResp, err := client.DecodePayReq(
context.Background(), decodeReq,
)
decodeResp, err := client.DecodePayReq(ctxc, decodeReq)
if err != nil {
return err
}
@ -462,13 +461,13 @@ func sendPaymentRequest(ctx *cli.Context,
printJSON := ctx.Bool(jsonFlag.Name)
req.NoInflightUpdates = !ctx.Bool(inflightUpdatesFlag.Name) && printJSON
stream, err := routerClient.SendPaymentV2(context.Background(), req)
stream, err := routerClient.SendPaymentV2(ctxc, req)
if err != nil {
return err
}
finalState, err := printLivePayment(
stream, client, printJSON,
ctxc, stream, client, printJSON,
)
if err != nil {
return err
@ -497,6 +496,7 @@ var trackPaymentCommand = cli.Command{
}
func trackPayment(ctx *cli.Context) error {
ctxc := getContext()
args := ctx.Args()
conn := getClientConn(ctx, false)
@ -517,13 +517,13 @@ func trackPayment(ctx *cli.Context) error {
PaymentHash: hash,
}
stream, err := routerClient.TrackPaymentV2(context.Background(), req)
stream, err := routerClient.TrackPaymentV2(ctxc, req)
if err != nil {
return err
}
client := lnrpc.NewLightningClient(conn)
_, err = printLivePayment(stream, client, ctx.Bool(jsonFlag.Name))
_, err = printLivePayment(ctxc, stream, client, ctx.Bool(jsonFlag.Name))
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
// option uses terminal control codes to rewrite the output. This call
// 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) {
// 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.
printRespJSON(payment)
} else {
table := formatPayment(payment, aliases)
table := formatPayment(ctxc, payment, aliases)
// Clear all previously written lines and print the
// 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.
func (a *aliasCache) get(pubkey string) string {
func (a *aliasCache) get(ctxc context.Context, pubkey string) string {
alias, ok := a.cache[pubkey]
if ok {
return alias
@ -607,7 +608,7 @@ func (a *aliasCache) get(pubkey string) string {
// Request node info.
resp, err := a.client.GetNodeInfo(
context.Background(),
ctxc,
&lnrpc.NodeInfoRequest{
PubKey: pubkey,
},
@ -630,7 +631,8 @@ func formatMsat(amt int64) string {
}
// 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()
// Build table header.
@ -669,7 +671,7 @@ func formatPayment(payment *lnrpc.Payment, aliases *aliasCache) string {
hops := []string{}
for _, h := range route.Hops {
alias := aliases.get(h.PubKey)
alias := aliases.get(ctxc, h.PubKey)
hops = append(hops, alias)
}
@ -891,12 +893,13 @@ func sendToRoute(ctx *cli.Context) error {
}
func sendToRouteRequest(ctx *cli.Context, req *routerrpc.SendToRouteRequest) error {
ctxc := getContext()
conn := getClientConn(ctx, false)
defer conn.Close()
client := routerrpc.NewRouterClient(conn)
resp, err := client.SendToRouteV2(context.Background(), req)
resp, err := client.SendToRouteV2(ctxc, req)
if err != nil {
return err
}

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

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

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

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

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

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

@ -23,6 +23,7 @@ import (
"github.com/lightninglabs/protobuf-hex-display/proto"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/signal"
"github.com/urfave/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -39,6 +40,15 @@ const (
defaultUtxoMinConf = 1
)
func getContext() context.Context {
ctxc, cancel := context.WithCancel(context.Background())
go func() {
<-signal.ShutdownChannel()
cancel()
}()
return ctxc
}
func printJSON(resp interface{}) {
b, err := json.Marshal(resp)
if err != nil {
@ -119,6 +129,7 @@ var newAddressCommand = cli.Command{
}
func newAddress(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -137,8 +148,7 @@ func newAddress(ctx *cli.Context) error {
"are: p2wkh and np2wkh", stringAddrType)
}
ctxb := context.Background()
addr, err := client.NewAddress(ctxb, &lnrpc.NewAddressRequest{
addr, err := client.NewAddress(ctxc, &lnrpc.NewAddressRequest{
Type: addrType,
})
if err != nil {
@ -172,6 +182,7 @@ var estimateFeeCommand = cli.Command{
}
func estimateFees(ctx *cli.Context) error {
ctxc := getContext()
var amountToAddr map[string]int64
jsonMap := ctx.Args().First()
@ -179,11 +190,10 @@ func estimateFees(ctx *cli.Context) error {
return err
}
ctxb := context.Background()
client, cleanUp := getClient(ctx)
defer cleanUp()
resp, err := client.EstimateFee(ctxb, &lnrpc.EstimateFeeRequest{
resp, err := client.EstimateFee(ctxc, &lnrpc.EstimateFeeRequest{
AddrToAmount: amountToAddr,
TargetConf: int32(ctx.Int64("conf_target")),
})
@ -260,6 +270,7 @@ func sendCoins(ctx *cli.Context) error {
amt int64
err error
)
ctxc := getContext()
args := ctx.Args()
if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
@ -299,7 +310,6 @@ func sendCoins(ctx *cli.Context) error {
"sweep all coins out of the wallet")
}
ctxb := context.Background()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -314,7 +324,7 @@ func sendCoins(ctx *cli.Context) error {
MinConfs: minConfs,
SpendUnconfirmed: minConfs == 0,
}
txid, err := client.SendCoins(ctxb, req)
txid, err := client.SendCoins(ctxc, req)
if err != nil {
return err
}
@ -367,6 +377,7 @@ func listUnspent(ctx *cli.Context) error {
maxConfirms int64
err error
)
ctxc := getContext()
args := ctx.Args()
if ctx.IsSet("max_confs") && !ctx.IsSet("min_confs") {
@ -413,7 +424,6 @@ func listUnspent(ctx *cli.Context) error {
maxConfirms = math.MaxInt32
}
ctxb := context.Background()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -421,7 +431,7 @@ func listUnspent(ctx *cli.Context) error {
MinConfs: int32(minConfirms),
MaxConfs: int32(maxConfirms),
}
resp, err := client.ListUnspent(ctxb, req)
resp, err := client.ListUnspent(ctxc, req)
if err != nil {
return err
}
@ -481,6 +491,7 @@ var sendManyCommand = cli.Command{
}
func sendMany(ctx *cli.Context) error {
ctxc := getContext()
var amountToAddr map[string]int64
jsonMap := ctx.Args().First()
@ -493,12 +504,11 @@ func sendMany(ctx *cli.Context) error {
"set, but not both")
}
ctxb := context.Background()
client, cleanUp := getClient(ctx)
defer cleanUp()
minConfs := int32(ctx.Uint64("min_confs"))
txid, err := client.SendMany(ctxb, &lnrpc.SendManyRequest{
txid, err := client.SendMany(ctxc, &lnrpc.SendManyRequest{
AddrToAmount: amountToAddr,
TargetConf: int32(ctx.Int64("conf_target")),
SatPerByte: ctx.Int64("sat_per_byte"),
@ -546,7 +556,7 @@ var connectCommand = cli.Command{
}
func connectPeer(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -567,7 +577,7 @@ func connectPeer(ctx *cli.Context) error {
Timeout: uint64(ctx.Duration("timeout").Seconds()),
}
lnid, err := client.ConnectPeer(ctxb, req)
lnid, err := client.ConnectPeer(ctxc, req)
if err != nil {
return err
}
@ -592,7 +602,7 @@ var disconnectCommand = cli.Command{
}
func disconnectPeer(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -610,7 +620,7 @@ func disconnectPeer(ctx *cli.Context) error {
PubKey: pubKey,
}
lnid, err := client.DisconnectPeer(ctxb, req)
lnid, err := client.DisconnectPeer(ctxc, req)
if err != nil {
return err
}
@ -691,6 +701,7 @@ var closeChannelCommand = cli.Command{
}
func closeChannel(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -733,7 +744,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 {
return err
}
@ -750,10 +761,10 @@ func closeChannel(ctx *cli.Context) error {
// 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
// closing transaction receives all of its required confirmations.
func executeChannelClose(client lnrpc.LightningClient, req *lnrpc.CloseChannelRequest,
txidChan chan<- string, block bool) error {
func executeChannelClose(ctxc context.Context, client lnrpc.LightningClient,
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 {
return err
}
@ -836,11 +847,12 @@ var closeAllChannelsCommand = cli.Command{
}
func closeAllChannels(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
listReq := &lnrpc.ListChannelsRequest{}
openChannels, err := client.ListChannels(context.Background(), listReq)
openChannels, err := client.ListChannels(ctxc, listReq)
if err != nil {
return fmt.Errorf("unable to fetch open channels: %v", err)
}
@ -971,7 +983,7 @@ func closeAllChannels(ctx *cli.Context) error {
}
txidChan := make(chan string, 1)
err = executeChannelClose(client, req, txidChan, false)
err = executeChannelClose(ctxc, client, req, txidChan, false)
if err != nil {
res.FailErr = fmt.Sprintf("unable to close "+
"channel: %v", err)
@ -1046,8 +1058,7 @@ var abandonChannelCommand = cli.Command{
}
func abandonChannel(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1066,7 +1077,7 @@ func abandonChannel(ctx *cli.Context) error {
ChannelPoint: channelPoint,
}
resp, err := client.AbandonChannel(ctxb, req)
resp, err := client.AbandonChannel(ctxc, req)
if err != nil {
return err
}
@ -1126,7 +1137,7 @@ var listPeersCommand = cli.Command{
}
func listPeers(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1135,7 +1146,7 @@ func listPeers(ctx *cli.Context) error {
req := &lnrpc.ListPeersRequest{
LatestError: !ctx.IsSet("list_errors"),
}
resp, err := client.ListPeers(ctxb, req)
resp, err := client.ListPeers(ctxc, req)
if err != nil {
return err
}
@ -1152,12 +1163,12 @@ var walletBalanceCommand = cli.Command{
}
func walletBalance(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.WalletBalanceRequest{}
resp, err := client.WalletBalance(ctxb, req)
resp, err := client.WalletBalance(ctxc, req)
if err != nil {
return err
}
@ -1175,12 +1186,12 @@ var channelBalanceCommand = cli.Command{
}
func channelBalance(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.ChannelBalanceRequest{}
resp, err := client.ChannelBalance(ctxb, req)
resp, err := client.ChannelBalance(ctxc, req)
if err != nil {
return err
}
@ -1196,12 +1207,12 @@ var getInfoCommand = cli.Command{
}
func getInfo(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.GetInfoRequest{}
resp, err := client.GetInfo(ctxb, req)
resp, err := client.GetInfo(ctxc, req)
if err != nil {
return err
}
@ -1217,12 +1228,12 @@ var getRecoveryInfoCommand = cli.Command{
}
func getRecoveryInfo(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.GetRecoveryInfoRequest{}
resp, err := client.GetRecoveryInfo(ctxb, req)
resp, err := client.GetRecoveryInfo(ctxc, req)
if err != nil {
return err
}
@ -1239,12 +1250,12 @@ var pendingChannelsCommand = cli.Command{
}
func pendingChannels(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.PendingChannelsRequest{}
resp, err := client.PendingChannels(ctxb, req)
resp, err := client.PendingChannels(ctxc, req)
if err != nil {
return err
}
@ -1286,7 +1297,7 @@ var listChannelsCommand = cli.Command{
}
func listChannels(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1312,7 +1323,7 @@ func listChannels(ctx *cli.Context) error {
Peer: peerKey,
}
resp, err := client.ListChannels(ctxb, req)
resp, err := client.ListChannels(ctxc, req)
if err != nil {
return err
}
@ -1361,7 +1372,7 @@ var closedChannelsCommand = cli.Command{
}
func closedChannels(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1374,7 +1385,7 @@ func closedChannels(ctx *cli.Context) error {
Abandoned: ctx.Bool("abandoned"),
}
resp, err := client.ClosedChannels(ctxb, req)
resp, err := client.ClosedChannels(ctxc, req)
if err != nil {
return err
}
@ -1402,6 +1413,7 @@ var describeGraphCommand = cli.Command{
}
func describeGraph(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1409,7 +1421,7 @@ func describeGraph(ctx *cli.Context) error {
IncludeUnannounced: ctx.Bool("include_unannounced"),
}
graph, err := client.DescribeGraph(context.Background(), req)
graph, err := client.DescribeGraph(ctxc, req)
if err != nil {
return err
}
@ -1427,6 +1439,7 @@ var getNodeMetricsCommand = cli.Command{
}
func getNodeMetrics(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1434,7 +1447,7 @@ func getNodeMetrics(ctx *cli.Context) error {
Types: []lnrpc.NodeMetricType{lnrpc.NodeMetricType_BETWEENNESS_CENTRALITY},
}
nodeMetrics, err := client.GetNodeMetrics(context.Background(), req)
nodeMetrics, err := client.GetNodeMetrics(ctxc, req)
if err != nil {
return err
}
@ -1489,6 +1502,7 @@ var listPaymentsCommand = cli.Command{
}
func listPayments(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1499,7 +1513,7 @@ func listPayments(ctx *cli.Context) error {
Reversed: !ctx.Bool("paginate_forwards"),
}
payments, err := client.ListPayments(context.Background(), req)
payments, err := client.ListPayments(ctxc, req)
if err != nil {
return err
}
@ -1525,7 +1539,7 @@ var getChanInfoCommand = cli.Command{
}
func getChanInfo(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1550,7 +1564,7 @@ func getChanInfo(ctx *cli.Context) error {
ChanId: uint64(chanID),
}
chanInfo, err := client.GetChanInfo(ctxb, req)
chanInfo, err := client.GetChanInfo(ctxc, req)
if err != nil {
return err
}
@ -1581,7 +1595,7 @@ var getNodeInfoCommand = cli.Command{
}
func getNodeInfo(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1602,7 +1616,7 @@ func getNodeInfo(ctx *cli.Context) error {
IncludeChannels: ctx.Bool("include_channels"),
}
nodeInfo, err := client.GetNodeInfo(ctxb, req)
nodeInfo, err := client.GetNodeInfo(ctxc, req)
if err != nil {
return err
}
@ -1657,7 +1671,7 @@ var queryRoutesCommand = cli.Command{
}
func queryRoutes(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1706,7 +1720,7 @@ func queryRoutes(ctx *cli.Context) error {
OutgoingChanId: ctx.Uint64("outgoing_chanid"),
}
route, err := client.QueryRoutes(ctxb, req)
route, err := client.QueryRoutes(ctxc, req)
if err != nil {
return err
}
@ -1758,13 +1772,13 @@ var getNetworkInfoCommand = cli.Command{
}
func getNetworkInfo(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.NetworkInfoRequest{}
netInfo, err := client.GetNetworkInfo(ctxb, req)
netInfo, err := client.GetNetworkInfo(ctxc, req)
if err != nil {
return err
}
@ -1794,7 +1808,7 @@ var debugLevelCommand = cli.Command{
}
func debugLevel(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.DebugLevelRequest{
@ -1802,7 +1816,7 @@ func debugLevel(ctx *cli.Context) error {
LevelSpec: ctx.String("level"),
}
resp, err := client.DebugLevel(ctxb, req)
resp, err := client.DebugLevel(ctxc, req)
if err != nil {
return err
}
@ -1846,7 +1860,7 @@ var listChainTxnsCommand = cli.Command{
}
func listChainTxns(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1859,7 +1873,7 @@ func listChainTxns(ctx *cli.Context) error {
req.EndHeight = int32(ctx.Int64("end_height"))
}
resp, err := client.GetTransactions(ctxb, req)
resp, err := client.GetTransactions(ctxc, req)
if err != nil {
return err
}
@ -1878,11 +1892,11 @@ var stopCommand = cli.Command{
}
func stopDaemon(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
_, err := client.StopDaemon(ctxb, &lnrpc.StopRequest{})
_, err := client.StopDaemon(ctxc, &lnrpc.StopRequest{})
if err != nil {
return err
}
@ -1910,7 +1924,7 @@ var signMessageCommand = cli.Command{
}
func signMessage(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1925,7 +1939,7 @@ func signMessage(ctx *cli.Context) error {
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 {
return err
}
@ -1959,7 +1973,7 @@ var verifyMessageCommand = cli.Command{
}
func verifyMessage(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1990,7 +2004,7 @@ func verifyMessage(ctx *cli.Context) error {
}
req := &lnrpc.VerifyMessageRequest{Msg: msg, Signature: sig}
resp, err := client.VerifyMessage(ctxb, req)
resp, err := client.VerifyMessage(ctxc, req)
if err != nil {
return err
}
@ -2010,12 +2024,12 @@ var feeReportCommand = cli.Command{
}
func feeReport(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.FeeReportRequest{}
resp, err := client.FeeReport(ctxb, req)
resp, err := client.FeeReport(ctxc, req)
if err != nil {
return err
}
@ -2103,7 +2117,7 @@ func parseChanPoint(s string) (*lnrpc.ChannelPoint, error) {
}
func updateChannelPolicy(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -2198,7 +2212,7 @@ func updateChannelPolicy(ctx *cli.Context) error {
}
}
resp, err := client.UpdateChannelPolicy(ctxb, req)
resp, err := client.UpdateChannelPolicy(ctxc, req)
if err != nil {
return err
}
@ -2254,7 +2268,7 @@ var forwardingHistoryCommand = cli.Command{
}
func forwardingHistory(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -2323,7 +2337,7 @@ func forwardingHistory(ctx *cli.Context) error {
IndexOffset: indexOffset,
NumMaxEvents: maxEvents,
}
resp, err := client.ForwardingHistory(ctxb, req)
resp, err := client.ForwardingHistory(ctxc, req)
if err != nil {
return err
}
@ -2386,7 +2400,7 @@ var exportChanBackupCommand = cli.Command{
}
func exportChanBackup(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -2420,7 +2434,7 @@ func exportChanBackup(ctx *cli.Context) error {
}
chanBackup, err := client.ExportChannelBackup(
ctxb, &lnrpc.ExportChannelBackupRequest{
ctxc, &lnrpc.ExportChannelBackupRequest{
ChanPoint: chanPointRPC,
},
)
@ -2455,7 +2469,7 @@ func exportChanBackup(ctx *cli.Context) error {
}
chanBackup, err := client.ExportAllChannelBackups(
ctxb, &lnrpc.ChanBackupExportRequest{},
ctxc, &lnrpc.ChanBackupExportRequest{},
)
if err != nil {
return err
@ -2531,7 +2545,7 @@ var verifyChanBackupCommand = cli.Command{
}
func verifyChanBackup(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -2557,7 +2571,7 @@ func verifyChanBackup(ctx *cli.Context) error {
}
}
resp, err := client.VerifyChanBackup(ctxb, &verifyReq)
resp, err := client.VerifyChanBackup(ctxc, &verifyReq)
if err != nil {
return err
}
@ -2673,7 +2687,7 @@ func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error)
}
func restoreChanBackup(ctx *cli.Context) error {
ctxb := context.Background()
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -2692,7 +2706,7 @@ func restoreChanBackup(ctx *cli.Context) error {
req.Backup = backups.Backup
_, err = client.RestoreChannelBackups(ctxb, &req)
_, err = client.RestoreChannelBackups(ctxc, &req)
if err != nil {
return fmt.Errorf("unable to restore chan backups: %v", err)
}

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

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

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

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