11package main
22
33import (
4+ "bytes"
45 "context"
56 "errors"
67 "fmt"
78 "strconv"
89
910 "github.com/lightninglabs/loop/liquidity"
1011 "github.com/lightninglabs/loop/looprpc"
12+ "github.com/lightningnetwork/lnd/routing/route"
1113 "github.com/urfave/cli"
1214 "google.golang.org/grpc/codes"
1315 "google.golang.org/grpc/status"
@@ -42,9 +44,9 @@ func getParams(ctx *cli.Context) error {
4244
4345var setLiquidityRuleCommand = cli.Command {
4446 Name : "setrule" ,
45- Usage : "set liquidity manager rule for a channel" ,
46- Description : "Update or remove the liquidity rule for a channel." ,
47- ArgsUsage : "shortchanid" ,
47+ Usage : "set liquidity manager rule for a channel/peer " ,
48+ Description : "Update or remove the liquidity rule for a channel/peer ." ,
49+ ArgsUsage : "{ shortchanid | peerpubkey} " ,
4850 Flags : []cli.Flag {
4951 cli.IntFlag {
5052 Name : "incoming_threshold" ,
@@ -58,8 +60,9 @@ var setLiquidityRuleCommand = cli.Command{
5860 "that we do not want to drop below." ,
5961 },
6062 cli.BoolFlag {
61- Name : "clear" ,
62- Usage : "remove the rule currently set for the channel." ,
63+ Name : "clear" ,
64+ Usage : "remove the rule currently set for the " +
65+ "channel/peer." ,
6366 },
6467 },
6568 Action : setRule ,
@@ -68,13 +71,22 @@ var setLiquidityRuleCommand = cli.Command{
6871func setRule (ctx * cli.Context ) error {
6972 // We require that a channel ID is set for this rule update.
7073 if ctx .NArg () != 1 {
71- return fmt .Errorf ("please set a channel id for the rule " +
72- "update" )
74+ return fmt .Errorf ("please set a channel id or peer pubkey " +
75+ "for the rule update" )
7376 }
7477
78+ var (
79+ pubkey route.Vertex
80+ pubkeyRule bool
81+ )
7582 chanID , err := strconv .ParseUint (ctx .Args ().First (), 10 , 64 )
7683 if err != nil {
77- return fmt .Errorf ("could not parse channel ID: %v" , err )
84+ pubkey , err = route .NewVertexFromStr (ctx .Args ().First ())
85+ if err != nil {
86+ return fmt .Errorf ("please provide a valid pubkey: " +
87+ "%v, or short channel ID" , err )
88+ }
89+ pubkeyRule = true
7890 }
7991
8092 client , cleanup , err := getClient (ctx )
@@ -101,11 +113,20 @@ func setRule(ctx *cli.Context) error {
101113 )
102114
103115 // Run through our current set of rules and check whether we have a rule
104- // currently set for this channel. We also track a slice containing all
105- // of the rules we currently have set for other channels, because we
106- // want to leave these rules untouched.
116+ // currently set for this channel or peer . We also track a slice
117+ // containing all of the rules we currently have set for other channels,
118+ // and peers because we want to leave these rules untouched.
107119 for _ , rule := range params .Rules {
108- if rule .ChannelId == chanID {
120+ var (
121+ channelRuleSet = rule .ChannelId != 0 &&
122+ rule .ChannelId == chanID
123+
124+ peerRuleSet = rule .Pubkey != nil && bytes .Equal (
125+ rule .Pubkey , pubkey [:],
126+ )
127+ )
128+
129+ if channelRuleSet || peerRuleSet {
109130 ruleSet = true
110131 } else {
111132 otherRules = append (otherRules , rule )
@@ -149,6 +170,10 @@ func setRule(ctx *cli.Context) error {
149170 Type : looprpc .LiquidityRuleType_THRESHOLD ,
150171 }
151172
173+ if pubkeyRule {
174+ newRule .Pubkey = pubkey [:]
175+ }
176+
152177 if inboundSet {
153178 newRule .IncomingThreshold = uint32 (
154179 ctx .Int ("incoming_threshold" ),
0 commit comments