@@ -46,6 +46,7 @@ import (
4646 "github.com/lightninglabs/loop"
4747 "github.com/lightninglabs/loop/labels"
4848 "github.com/lightninglabs/loop/loopdb"
49+ "github.com/lightninglabs/loop/loopdb/sqlc"
4950 clientrpc "github.com/lightninglabs/loop/looprpc"
5051 "github.com/lightninglabs/loop/swap"
5152 "github.com/lightningnetwork/lnd/clock"
@@ -110,6 +111,9 @@ const (
110111 // defaultHtlcConfTarget is the default confirmation target we use for
111112 // loop in swap htlcs, set to the same default at the client.
112113 defaultHtlcConfTarget = loop .DefaultHtlcConfTarget
114+
115+ // defaultBtcAssetId is the default asset ID for BTC.
116+ defaultBtcAssetId = "btc"
113117)
114118
115119var (
@@ -229,13 +233,15 @@ type Config struct {
229233 //
230234 // NOTE: the params are encoded using `proto.Marshal` over an RPC
231235 // request.
232- PutLiquidityParams func (ctx context.Context , params []byte ) error
236+ PutLiquidityParams func (ctx context.Context , assetId string ,
237+ params []byte ) error
233238
234239 // FetchLiquidityParams reads the serialized `Parameters` from db.
235240 //
236241 // NOTE: the params are decoded using `proto.Unmarshal` over a
237242 // serialized RPC request.
238- FetchLiquidityParams func (ctx context.Context ) ([]byte , error )
243+ FetchLiquidityParams func (ctx context.Context ) ([]sqlc.LiquidityParam ,
244+ error )
239245}
240246
241247// Manager contains a set of desired liquidity rules for our channel
@@ -392,7 +398,8 @@ func (m *Manager) saveParams(ctx context.Context, req proto.Message) error {
392398 }
393399
394400 // Save the params on disk.
395- if err := m .cfg .PutLiquidityParams (ctx , paramsBytes ); err != nil {
401+ err = m .cfg .PutLiquidityParams (ctx , defaultBtcAssetId , paramsBytes )
402+ if err != nil {
396403 return fmt .Errorf ("failed to save params: %v" , err )
397404 }
398405
@@ -404,19 +411,22 @@ func (m *Manager) saveParams(ctx context.Context, req proto.Message) error {
404411func (m * Manager ) loadParams (ctx context.Context ) (
405412 * clientrpc.LiquidityParameters , error ) {
406413
407- paramsBytes , err := m .cfg .FetchLiquidityParams (ctx )
414+ params , err := m .cfg .FetchLiquidityParams (ctx )
408415 if err != nil {
409416 return nil , fmt .Errorf ("failed to read params: %v" , err )
410417 }
411418
412419 // Return early if there's nothing saved.
413- if paramsBytes == nil {
420+ if params == nil {
414421 return nil , nil
415422 }
416423
417424 // Unmarshal the params.
418425 req := & clientrpc.LiquidityParameters {}
419- err = proto .Unmarshal (paramsBytes , req )
426+ if len (params ) != 1 {
427+ return nil , fmt .Errorf ("expected 1 param, got %v" , len (params ))
428+ }
429+ err = proto .Unmarshal (params [0 ].Params , req )
420430 if err != nil {
421431 return nil , fmt .Errorf ("failed to unmarshal params: %v" , err )
422432 }
0 commit comments