/
mappable.go
50 lines (40 loc) · 1.46 KB
/
mappable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package mappable
import (
codecUtilities "github.com/AssetMantle/schema/go/codec/utilities"
"github.com/AssetMantle/schema/go/documents"
baseDocuments "github.com/AssetMantle/schema/go/documents/base"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/AssetMantle/modules/helpers"
)
var _ helpers.Mappable = (*Mappable)(nil)
func (mappable *Mappable) ValidateBasic() error {
return mappable.Maintainer.ValidateBasic()
}
func (*Mappable) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, Mappable{})
}
func NewMappable(maintainer documents.Maintainer) helpers.Mappable {
return &Mappable{Maintainer: maintainer.Get().(*baseDocuments.Document)}
}
func Prototype() helpers.Mappable {
return &Mappable{}
}
func GetMaintainer(mappable helpers.Mappable) documents.Maintainer {
return baseDocuments.NewMaintainerFromDocument(mappable.(*Mappable).Maintainer)
}
func MappablesFromInterface(mappables []helpers.Mappable) []*Mappable {
Mappables := make([]*Mappable, len(mappables))
for index, mappable := range mappables {
Mappables[index] = mappable.(*Mappable)
}
return Mappables
}
func MappablesToInterface(mappables []*Mappable) []helpers.Mappable {
Mappables := make([]helpers.Mappable, len(mappables))
for index, mappable := range mappables {
Mappables[index] = mappable
}
return Mappables
}