feat(collections): implement appmodule.HasGenesis interface (#17021)

This commit is contained in:
Julien Robert 2023-07-24 17:46:54 +02:00 committed by GitHub
parent 5442197d6b
commit 2102074024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -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)

View File

@ -3,6 +3,7 @@ package collections
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
)
@ -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()

View File

@ -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 {