mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
liquidity: add default parameters struct
This commit is contained in:
parent
ad8b5d0552
commit
559abd1eea
2 changed files with 12 additions and 14 deletions
|
|
@ -45,6 +45,12 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
// defaultParameters contains the default parameters that we start our
|
||||
// liquidity manger with.
|
||||
defaultParameters = Parameters{
|
||||
ChannelRules: make(map[lnwire.ShortChannelID]*ThresholdRule),
|
||||
}
|
||||
|
||||
// ErrZeroChannelID is returned if we get a rule for a 0 channel ID.
|
||||
ErrZeroChannelID = fmt.Errorf("zero channel ID not allowed")
|
||||
)
|
||||
|
|
@ -71,13 +77,6 @@ type Parameters struct {
|
|||
ChannelRules map[lnwire.ShortChannelID]*ThresholdRule
|
||||
}
|
||||
|
||||
// newParameters creates an empty set of parameters.
|
||||
func newParameters() Parameters {
|
||||
return Parameters{
|
||||
ChannelRules: make(map[lnwire.ShortChannelID]*ThresholdRule),
|
||||
}
|
||||
}
|
||||
|
||||
// String returns the string representation of our parameters.
|
||||
func (p Parameters) String() string {
|
||||
channelRules := make([]string, 0, len(p.ChannelRules))
|
||||
|
|
@ -127,7 +126,7 @@ type Manager struct {
|
|||
func NewManager(cfg *Config) *Manager {
|
||||
return &Manager{
|
||||
cfg: cfg,
|
||||
params: newParameters(),
|
||||
params: defaultParameters,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func TestParameters(t *testing.T) {
|
|||
|
||||
// Start with the case where we have no rules set.
|
||||
startParams := manager.GetParameters()
|
||||
require.Equal(t, newParameters(), startParams)
|
||||
require.Equal(t, defaultParameters, startParams)
|
||||
|
||||
// Mutate the parameters returned by our get function.
|
||||
startParams.ChannelRules[chanID] = NewThresholdRule(1, 1)
|
||||
|
|
@ -81,15 +81,14 @@ func TestParameters(t *testing.T) {
|
|||
// Make sure that we have not mutated the liquidity manager's params
|
||||
// by making this change.
|
||||
params := manager.GetParameters()
|
||||
require.Equal(t, newParameters(), params)
|
||||
require.Equal(t, defaultParameters, params)
|
||||
|
||||
// Provide a valid set of parameters and validate assert that they are
|
||||
// set.
|
||||
originalRule := NewThresholdRule(10, 10)
|
||||
expected := Parameters{
|
||||
ChannelRules: map[lnwire.ShortChannelID]*ThresholdRule{
|
||||
chanID: originalRule,
|
||||
},
|
||||
expected := defaultParameters
|
||||
expected.ChannelRules = map[lnwire.ShortChannelID]*ThresholdRule{
|
||||
chanID: originalRule,
|
||||
}
|
||||
|
||||
err := manager.SetParameters(expected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue