Skip to content

Commit

Permalink
Trying fixing migration
Browse files Browse the repository at this point in the history
Signed-off-by: riccardo.montagnin <riccardo.montagnin@gmail.com>
  • Loading branch information
RiccardoM committed Sep 24, 2020
1 parent de57506 commit e69ec49
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions x/posts/keeper/legacy/v0.10.0/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v0100

import (
"sort"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -13,6 +14,46 @@ type PostID string
// Amino and JSON serialization and deserialization.
type OptionalData map[string]string

// KeyValue is a simple key/value representation of one field of a OptionalData.
type KeyValue struct {
Key string
Value string
}

// MarshalAmino transforms the OptionalData to an array of key/value.
func (m OptionalData) MarshalAmino() ([]KeyValue, error) {
fieldKeys := make([]string, len(m))
i := 0
for key := range m {
fieldKeys[i] = key
i++
}

sort.Stable(sort.StringSlice(fieldKeys))

p := make([]KeyValue, len(m))
for i, key := range fieldKeys {
p[i] = KeyValue{
Key: key,
Value: m[key],
}
}

return p, nil
}

// UnmarshalAmino transforms the key/value array to a OptionalData.
func (m *OptionalData) UnmarshalAmino(keyValues []KeyValue) error {
tempMap := make(map[string]string, len(keyValues))
for _, p := range keyValues {
tempMap[p.Key] = p.Value
}

*m = tempMap

return nil
}

// Attachment contains the information representing any type of file provided with a post.
// This file can be an image or a multimedia file (vocals, video, documents, etc.).
type Attachment struct {
Expand Down

0 comments on commit e69ec49

Please sign in to comment.