-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
95 lines (78 loc) · 3.74 KB
/
keeper.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package burn
import (
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/AssetMantle/modules/modules/assets/internal/key"
"github.com/AssetMantle/modules/modules/assets/internal/mappable"
"github.com/AssetMantle/modules/modules/identities/auxiliaries/authenticate"
"github.com/AssetMantle/modules/modules/maintainers/auxiliaries/maintain"
"github.com/AssetMantle/modules/modules/metas/auxiliaries/supplement"
"github.com/AssetMantle/modules/modules/splits/auxiliaries/renumerate"
"github.com/AssetMantle/modules/schema/data"
"github.com/AssetMantle/modules/schema/documents"
errorConstants "github.com/AssetMantle/modules/schema/errors/constants"
"github.com/AssetMantle/modules/schema/helpers"
"github.com/AssetMantle/modules/schema/properties"
"github.com/AssetMantle/modules/schema/properties/constants"
baseTypes "github.com/AssetMantle/modules/schema/types/base"
)
type transactionKeeper struct {
mapper helpers.Mapper
renumerateAuxiliary helpers.Auxiliary
maintainAuxiliary helpers.Auxiliary
supplementAuxiliary helpers.Auxiliary
authenticateAuxiliary helpers.Auxiliary
}
var _ helpers.TransactionKeeper = (*transactionKeeper)(nil)
func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, msg sdkTypes.Msg) helpers.TransactionResponse {
message := messageFromInterface(msg)
if auxiliaryResponse := transactionKeeper.authenticateAuxiliary.GetKeeper().Help(context, authenticate.NewAuxiliaryRequest(message.From, message.FromID)); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}
assets := transactionKeeper.mapper.NewCollection(context).Fetch(key.NewKey(message.AssetID))
Mappable := assets.Get(key.NewKey(message.AssetID))
if Mappable == nil {
return newTransactionResponse(errorConstants.EntityNotFound)
}
asset := Mappable.(documents.Asset)
metaProperties, err := supplement.GetMetaPropertiesFromResponse(transactionKeeper.supplementAuxiliary.GetKeeper().Help(context, supplement.NewAuxiliaryRequest(asset.GetBurn())))
if err != nil {
return newTransactionResponse(err)
}
if burnHeightMetaProperty := metaProperties.GetProperty(constants.BurnHeightProperty.GetID()); burnHeightMetaProperty != nil {
burnHeight := burnHeightMetaProperty.(properties.MetaProperty).GetData().(data.HeightData).Get()
if burnHeight.Compare(baseTypes.NewHeight(context.BlockHeight())) > 0 {
return newTransactionResponse(errorConstants.NotAuthorized)
}
}
if auxiliaryResponse := transactionKeeper.renumerateAuxiliary.GetKeeper().Help(context, renumerate.NewAuxiliaryRequest(message.FromID, message.AssetID, sdkTypes.ZeroDec())); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}
assets.Remove(mappable.NewMappable(asset))
return newTransactionResponse(nil)
}
func (transactionKeeper transactionKeeper) Initialize(mapper helpers.Mapper, _ helpers.Parameters, auxiliaries []interface{}) helpers.Keeper {
transactionKeeper.mapper = mapper
for _, auxiliary := range auxiliaries {
switch value := auxiliary.(type) {
case helpers.Auxiliary:
switch value.GetName() {
case renumerate.Auxiliary.GetName():
transactionKeeper.renumerateAuxiliary = value
case maintain.Auxiliary.GetName():
transactionKeeper.maintainAuxiliary = value
case supplement.Auxiliary.GetName():
transactionKeeper.supplementAuxiliary = value
case authenticate.Auxiliary.GetName():
transactionKeeper.authenticateAuxiliary = value
}
default:
panic(errorConstants.UninitializedUsage)
}
}
return transactionKeeper
}
func keeperPrototype() helpers.TransactionKeeper {
return transactionKeeper{}
}