From d975b56f0e9742b814f2655a17614723961f31e3 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Tue, 4 Jul 2023 18:49:06 +0200 Subject: [PATCH] loop: xpub support for loop out --- cmd/loop/liquidity.go | 41 +++++++++++++++++++++++++++++++++++++- cmd/loop/loopout.go | 46 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/cmd/loop/liquidity.go b/cmd/loop/liquidity.go index cb74f99..d54294d 100644 --- a/cmd/loop/liquidity.go +++ b/cmd/loop/liquidity.go @@ -292,6 +292,21 @@ var setParamsCommand = cli.Command{ "autoloop loop out, set to \"default\" in " + "order to revert to default behavior.", }, + cli.StringFlag{ + Name: "account", + Usage: "the name of the account to generate a new " + + "address from. You can list the names of " + + "valid accounts in your backing lnd " + + "instance with \"lncli wallet accounts list\".", + Value: "", + }, + cli.StringFlag{ + Name: "account_addr_type", + Usage: "the address type of the extended public key " + + "specified in account. Currently only " + + "pay-to-taproot-pubkey(p2tr) is supported", + Value: "p2tr", + }, cli.Uint64Flag{ Name: "autobudget", Usage: "the maximum amount of fees in satoshis that " + @@ -445,11 +460,35 @@ func setParams(ctx *cli.Context) error { flagSet = true } - if ctx.IsSet("destaddr") { + switch { + case ctx.IsSet("destaddr") && ctx.IsSet("account"): + return fmt.Errorf("cannot set destaddr and account at the " + + "same time") + + case ctx.IsSet("destaddr"): params.AutoloopDestAddress = ctx.String("destaddr") + params.Account = "" + flagSet = true + + case ctx.IsSet("account") != ctx.IsSet("account_addr_type"): + return liquidity.ErrAccountAndAddrType + + case ctx.IsSet("account"): + params.Account = ctx.String("account") + params.AutoloopDestAddress = "" flagSet = true } + if ctx.IsSet("account_addr_type") { + switch ctx.String("account_addr_type") { + case "p2tr": + params.AccountAddrType = looprpc.AddressType_TAPROOT_PUBKEY + + default: + return fmt.Errorf("unknown account address type") + } + } + if ctx.IsSet("autobudgetrefreshperiod") { params.AutoloopBudgetRefreshPeriodSec = uint64(ctx.Duration("autobudgetrefreshperiod").Seconds()) diff --git a/cmd/loop/loopout.go b/cmd/loop/loopout.go index fd945ea..d50ee3d 100644 --- a/cmd/loop/loopout.go +++ b/cmd/loop/loopout.go @@ -39,6 +39,21 @@ var loopOutCommand = cli.Command{ "should be sent to, if let blank the funds " + "will go to lnd's wallet", }, + cli.StringFlag{ + Name: "account", + Usage: "the name of the account to generate a new " + + "address from. You can list the names of " + + "valid accounts in your backing lnd " + + "instance with \"lncli wallet accounts list\".", + Value: "", + }, + cli.StringFlag{ + Name: "account_addr_type", + Usage: "the address type of the extended public key " + + "specified in account. Currently only " + + "pay-to-taproot-pubkey(p2tr) is supported", + Value: "p2tr", + }, cli.Uint64Flag{ Name: "amt", Usage: "the amount in satoshis to loop out", @@ -101,7 +116,7 @@ func loopOut(ctx *cli.Context) error { } // Parse outgoing channel set. Don't string split if the flag is empty. - // Otherwise strings.Split returns a slice of length one with an empty + // Otherwise, strings.Split returns a slice of length one with an empty // element. var outgoingChanSet []uint64 if ctx.IsSet("channel") { @@ -122,14 +137,41 @@ func loopOut(ctx *cli.Context) error { return err } + if ctx.IsSet("addr") && ctx.IsSet("account") { + return fmt.Errorf("cannot set --addr and --account at the " + + "same time. Please specify only one source for a new " + + "address to sweep the loop amount to") + } + var destAddr string + var account string switch { case ctx.IsSet("addr"): destAddr = ctx.String("addr") + + case ctx.IsSet("account"): + account = ctx.String("account") + case args.Present(): destAddr = args.First() } + if ctx.IsSet("account") != ctx.IsSet("account_addr_type") { + return fmt.Errorf("cannot set account without specifying " + + "account address type and vice versa") + } + + var accountAddrType looprpc.AddressType + if ctx.IsSet("account_addr_type") { + switch ctx.String("account_addr_type") { + case "p2tr": + accountAddrType = looprpc.AddressType_TAPROOT_PUBKEY + + default: + return fmt.Errorf("unknown account address type") + } + } + client, cleanup, err := getClient(ctx) if err != nil { return err @@ -191,6 +233,8 @@ func loopOut(ctx *cli.Context) error { resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{ Amt: int64(amt), Dest: destAddr, + Account: account, + AccountAddrType: accountAddrType, MaxMinerFee: int64(limits.maxMinerFee), MaxPrepayAmt: int64(limits.maxPrepayAmt), MaxSwapFee: int64(limits.maxSwapFee),