/
mappable.go
52 lines (42 loc) · 1.39 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
51
52
// 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"
"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.Asset.ValidateBasic()
}
func (*Mappable) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, Mappable{})
}
func Prototype() helpers.Mappable {
return &Mappable{}
}
func NewMappable(asset documents.Asset) helpers.Mappable {
return &Mappable{
Asset: asset.Get().(*base.Document),
}
}
func GetAsset(mappable helpers.Mappable) documents.Asset {
return base.NewAssetFromDocument(mappable.(*Mappable).Asset)
}
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
}