Skip to content

Commit 22cb00a

Browse files
committed
looprpc: add asset id to liquidity request
1 parent a180f2a commit 22cb00a

File tree

6 files changed

+1104
-973
lines changed

6 files changed

+1104
-973
lines changed

cmd/loop/liquidity.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/lightninglabs/loop/liquidity"
1111
"github.com/lightninglabs/loop/looprpc"
12+
"github.com/lightninglabs/loop/swap"
1213
"github.com/lightningnetwork/lnd/routing/route"
1314
"github.com/urfave/cli"
1415
"google.golang.org/grpc/codes"
@@ -106,7 +107,7 @@ func setRule(ctx *cli.Context) error {
106107
// We need to set the full set of current parameters every time we call
107108
// SetParameters. To allow users to set only individual fields on the
108109
// cli, we lookup our current params, then update individual values.
109-
params, err := client.GetLiquidityParams(
110+
paramsResponse, err := client.GetLiquidityParams(
110111
context.Background(), &looprpc.GetLiquidityParamsRequest{},
111112
)
112113
if err != nil {
@@ -120,6 +121,12 @@ func setRule(ctx *cli.Context) error {
120121
otherRules []*looprpc.LiquidityRule
121122
)
122123

124+
// We're only interested in the btc rules for now.
125+
params, ok := paramsResponse.Rules[swap.DefaultBtcAssetID]
126+
if !ok {
127+
return errors.New("no rules set for BTC")
128+
}
129+
123130
// Run through our current set of rules and check whether we have a rule
124131
// currently set for this channel or peer. We also track a slice
125132
// containing all of the rules we currently have set for other channels,
@@ -160,6 +167,7 @@ func setRule(ctx *cli.Context) error {
160167
context.Background(),
161168
&looprpc.SetLiquidityParamsRequest{
162169
Parameters: params,
170+
AssetId: swap.DefaultBtcAssetID,
163171
},
164172
)
165173
return err
@@ -216,6 +224,7 @@ func setRule(ctx *cli.Context) error {
216224
context.Background(),
217225
&looprpc.SetLiquidityParamsRequest{
218226
Parameters: params,
227+
AssetId: swap.DefaultBtcAssetID,
219228
},
220229
)
221230

@@ -364,13 +373,19 @@ func setParams(ctx *cli.Context) error {
364373
// We need to set the full set of current parameters every time we call
365374
// SetParameters. To allow users to set only individual fields on the
366375
// cli, we lookup our current params, then update individual values.
367-
params, err := client.GetLiquidityParams(
376+
paramsResponse, err := client.GetLiquidityParams(
368377
context.Background(), &looprpc.GetLiquidityParamsRequest{},
369378
)
370379
if err != nil {
371380
return err
372381
}
373382

383+
// We're only interested in the btc rules for now.
384+
params, ok := paramsResponse.Rules[swap.DefaultBtcAssetID]
385+
if !ok {
386+
return errors.New("no rules set for BTC")
387+
}
388+
374389
var flagSet, categoriesSet, feePercentSet bool
375390

376391
// Update our existing parameters with the values provided by cli flags.
@@ -556,6 +571,7 @@ func setParams(ctx *cli.Context) error {
556571
_, err = client.SetLiquidityParams(
557572
context.Background(), &looprpc.SetLiquidityParamsRequest{
558573
Parameters: params,
574+
AssetId: swap.DefaultBtcAssetID,
559575
},
560576
)
561577

loopd/swapclient_server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ func (s *swapClientServer) GetInfo(ctx context.Context,
12241224

12251225
// GetLiquidityParams gets our current liquidity manager's parameters.
12261226
func (s *swapClientServer) GetLiquidityParams(_ context.Context,
1227-
_ *looprpc.GetLiquidityParamsRequest) (*looprpc.LiquidityParameters,
1228-
error) {
1227+
_ *looprpc.GetLiquidityParamsRequest) (
1228+
*looprpc.GetLiquidityParamsResponse, error) {
12291229

12301230
cfg := s.liquidityMgr.GetParameters()
12311231

@@ -1234,7 +1234,11 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
12341234
return nil, err
12351235
}
12361236

1237-
return rpcCfg, nil
1237+
return &looprpc.GetLiquidityParamsResponse{
1238+
Rules: map[string]*looprpc.LiquidityParameters{
1239+
swap.DefaultBtcAssetID: rpcCfg,
1240+
},
1241+
}, nil
12381242
}
12391243

12401244
// SetLiquidityParams attempts to set our current liquidity manager's

0 commit comments

Comments
 (0)