liquidity: add default parameters struct

pull/289/head
carla 4 years ago
parent ad8b5d0552
commit 559abd1eea
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -45,6 +45,12 @@ const (
) )
var ( 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 is returned if we get a rule for a 0 channel ID.
ErrZeroChannelID = fmt.Errorf("zero channel ID not allowed") ErrZeroChannelID = fmt.Errorf("zero channel ID not allowed")
) )
@ -71,13 +77,6 @@ type Parameters struct {
ChannelRules map[lnwire.ShortChannelID]*ThresholdRule 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. // String returns the string representation of our parameters.
func (p Parameters) String() string { func (p Parameters) String() string {
channelRules := make([]string, 0, len(p.ChannelRules)) channelRules := make([]string, 0, len(p.ChannelRules))
@ -127,7 +126,7 @@ type Manager struct {
func NewManager(cfg *Config) *Manager { func NewManager(cfg *Config) *Manager {
return &Manager{ return &Manager{
cfg: cfg, 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. // Start with the case where we have no rules set.
startParams := manager.GetParameters() startParams := manager.GetParameters()
require.Equal(t, newParameters(), startParams) require.Equal(t, defaultParameters, startParams)
// Mutate the parameters returned by our get function. // Mutate the parameters returned by our get function.
startParams.ChannelRules[chanID] = NewThresholdRule(1, 1) 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 // Make sure that we have not mutated the liquidity manager's params
// by making this change. // by making this change.
params := manager.GetParameters() 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 // Provide a valid set of parameters and validate assert that they are
// set. // set.
originalRule := NewThresholdRule(10, 10) originalRule := NewThresholdRule(10, 10)
expected := Parameters{ expected := defaultParameters
ChannelRules: map[lnwire.ShortChannelID]*ThresholdRule{ expected.ChannelRules = map[lnwire.ShortChannelID]*ThresholdRule{
chanID: originalRule, chanID: originalRule,
},
} }
err := manager.SetParameters(expected) err := manager.SetParameters(expected)

Loading…
Cancel
Save