From fe916397ccc458619a51fcec10e56de51794753a Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:12:44 +0100 Subject: [PATCH] chore(state): document NewStore() logger param --- internal/state/store.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/state/store.go b/internal/state/store.go index 3fce06073..d969272b3 100644 --- a/internal/state/store.go +++ b/internal/state/store.go @@ -122,15 +122,31 @@ type dbStore struct { var _ Store = (*dbStore)(nil) // NewStore creates the dbStore of the state pkg. +// +// ## Parameters +// +// - `db` - the database to use +// - `logger` - the logger to use; optional, defaults to a nop logger if not provided; if more than one is provided, +// it will panic +// +// ##Panics +// +// If more than one logger is provided. func NewStore(db dbm.DB, logger ...log.Logger) Store { - if len(logger) != 1 || logger[0] == nil { + // To avoid changing the API, we use `logger ...log.Logger` in function signature, so that old code can + // provide only `db`. In this case, we use NopLogger. + if logger[0] == nil { logger = []log.Logger{log.NewNopLogger()} } + if len(logger) > 1 { + panic("NewStore(): maximum one logger is allowed") + } + return dbStore{db, logger[0]} } -// LoadState loads the State from the database. +// Load loads the State from the database. func (store dbStore) Load() (State, error) { return store.loadState(stateKey) }