/
mappable.go
50 lines (40 loc) · 1.35 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/data"
baseData "github.com/AssetMantle/schema/go/data/base"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/AssetMantle/modules/helpers"
)
var _ helpers.Mappable = (*Mappable)(nil)
func (mappable *Mappable) ValidateBasic() error {
return mappable.Data.ValidateBasic()
}
func (*Mappable) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, Mappable{})
}
func NewMappable(data data.Data) helpers.Mappable {
return &Mappable{Data: data.ToAnyData().(*baseData.AnyData)}
}
func Prototype() helpers.Mappable {
return &Mappable{}
}
func GetData(mappable helpers.Mappable) data.Data {
return mappable.(*Mappable).Data
}
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
}