Skip to content

Commit

Permalink
feat(collections): implement appmodule.HasGenesis interface (cosmos…
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Jul 24, 2023
1 parent 5442197 commit 2102074
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions collections/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#17024](https://github.com/cosmos/cosmos-sdk/pull/17024) - Introduces `Triple`, a composite key with three keys.

### Improvements

* [#17021](https://github.com/cosmos/cosmos-sdk/pull/17021) Make collections implement the `appmodule.HasGenesis` interface.

## [v0.3.0](https://github.com/cosmos/cosmos-sdk/releases/tag/collections%2Fv0.3.0)

### Features

* [#16074](https://github.com/cosmos/cosmos-sdk/pull/16607) - Introduces `Clear` method for `Map` and `KeySet`
* [#16773](https://github.com/cosmos/cosmos-sdk/pull/16773)
* Adds `AltValueCodec` which provides a way to decode a value in two ways.
* Adds the possibility to specify an alternative way to decode the values of `KeySet`, `indexes.Multi`, `indexes.ReversePair`.
* Adds `AltValueCodec` which provides a way to decode a value in two ways.
* Adds the possibility to specify an alternative way to decode the values of `KeySet`, `indexes.Multi`, `indexes.ReversePair`.

## [v0.2.0](https://github.com/cosmos/cosmos-sdk/releases/tag/collections%2Fv0.2.0)

Expand Down
8 changes: 8 additions & 0 deletions collections/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package collections
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
)
Expand Down Expand Up @@ -39,6 +40,13 @@ func (m Map[K, V]) exportGenesis(ctx context.Context, writer io.Writer) error {

it, err := m.Iterate(ctx, nil)
if err != nil {
// if the iterator is invalid, the state can be empty
// and we can just return an empty array.
if errors.Is(err, ErrInvalidIterator) {
_, err = io.WriteString(writer, "]")
return err
}

return err
}
defer it.Close()
Expand Down
6 changes: 6 additions & 0 deletions collections/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func NewSchemaFromAccessor(accessor func(context.Context) store.KVStore) Schema
}
}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (s Schema) IsOnePerModuleType() {}

// IsAppModule implements the appmodule.AppModule interface.
func (s Schema) IsAppModule() {}

// DefaultGenesis implements the appmodule.HasGenesis.DefaultGenesis method.
func (s Schema) DefaultGenesis(target appmodule.GenesisTarget) error {
for _, name := range s.collectionsOrdered {
Expand Down

0 comments on commit 2102074

Please sign in to comment.