32 lines
698 B
Go
32 lines
698 B
Go
package store
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
)
|
|
|
|
// Used for associating paramstore key and field of param structs
|
|
type KeyFieldPair struct {
|
|
Key []byte
|
|
Field interface{}
|
|
}
|
|
|
|
// Slice of KeyFieldPair
|
|
type KeyFieldPairs []KeyFieldPair
|
|
|
|
// Interface for structs containing parameters for a module
|
|
type ParamStruct interface {
|
|
KeyFieldPairs() KeyFieldPairs
|
|
}
|
|
|
|
// Takes a map from key string to byte slice and
|
|
// unmarshalles it to ParamStruct
|
|
func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps ParamStruct) error {
|
|
for _, p := range ps.KeyFieldPairs() {
|
|
err := cdc.UnmarshalJSON(m[string(p.Key)], p.Field)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|