Skip to content

Commit

Permalink
chore(state): document NewStore() logger param
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Nov 2, 2024
1 parent 347bb6e commit fe91639
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit fe91639

Please sign in to comment.