2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-08 01:10:29 +00:00

loop: xpub support for loop out

This commit is contained in:
Slyghtning 2023-07-04 18:49:06 +02:00
parent ca933f843c
commit d975b56f0e
No known key found for this signature in database
GPG Key ID: F82D456EA023C9BF
2 changed files with 85 additions and 2 deletions

View File

@ -292,6 +292,21 @@ var setParamsCommand = cli.Command{
"autoloop loop out, set to \"default\" in " + "autoloop loop out, set to \"default\" in " +
"order to revert to default behavior.", "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{ cli.Uint64Flag{
Name: "autobudget", Name: "autobudget",
Usage: "the maximum amount of fees in satoshis that " + Usage: "the maximum amount of fees in satoshis that " +
@ -445,9 +460,33 @@ func setParams(ctx *cli.Context) error {
flagSet = true 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.AutoloopDestAddress = ctx.String("destaddr")
params.Account = ""
flagSet = true 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") { if ctx.IsSet("autobudgetrefreshperiod") {

View File

@ -39,6 +39,21 @@ var loopOutCommand = cli.Command{
"should be sent to, if let blank the funds " + "should be sent to, if let blank the funds " +
"will go to lnd's wallet", "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{ cli.Uint64Flag{
Name: "amt", Name: "amt",
Usage: "the amount in satoshis to loop out", 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. // 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. // element.
var outgoingChanSet []uint64 var outgoingChanSet []uint64
if ctx.IsSet("channel") { if ctx.IsSet("channel") {
@ -122,14 +137,41 @@ func loopOut(ctx *cli.Context) error {
return err 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 destAddr string
var account string
switch { switch {
case ctx.IsSet("addr"): case ctx.IsSet("addr"):
destAddr = ctx.String("addr") destAddr = ctx.String("addr")
case ctx.IsSet("account"):
account = ctx.String("account")
case args.Present(): case args.Present():
destAddr = args.First() 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) client, cleanup, err := getClient(ctx)
if err != nil { if err != nil {
return err return err
@ -191,6 +233,8 @@ func loopOut(ctx *cli.Context) error {
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{ resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
Amt: int64(amt), Amt: int64(amt),
Dest: destAddr, Dest: destAddr,
Account: account,
AccountAddrType: accountAddrType,
MaxMinerFee: int64(limits.maxMinerFee), MaxMinerFee: int64(limits.maxMinerFee),
MaxPrepayAmt: int64(limits.maxPrepayAmt), MaxPrepayAmt: int64(limits.maxPrepayAmt),
MaxSwapFee: int64(limits.maxSwapFee), MaxSwapFee: int64(limits.maxSwapFee),