-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
73 lines (58 loc) · 2.84 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
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package define
import (
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/AssetMantle/modules/modules/classifications/auxiliaries/define"
"github.com/AssetMantle/modules/modules/identities/auxiliaries/authenticate"
"github.com/AssetMantle/modules/modules/maintainers/auxiliaries/super"
"github.com/AssetMantle/modules/schema/errors/constants"
"github.com/AssetMantle/modules/schema/helpers"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
"github.com/AssetMantle/modules/schema/qualified/base"
)
type transactionKeeper struct {
mapper helpers.Mapper
defineAuxiliary helpers.Auxiliary
superAuxiliary 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())
}
immutables := base.NewImmutables(baseLists.NewPropertyList(append(message.ImmutableMetaProperties.GetList(), message.ImmutableProperties.GetList()...)...))
mutables := base.NewMutables(baseLists.NewPropertyList(append(message.MutableMetaProperties.GetList(), message.MutableProperties.GetList()...)...))
classificationID, err := define.GetClassificationIDFromResponse(transactionKeeper.defineAuxiliary.GetKeeper().Help(context, define.NewAuxiliaryRequest(immutables, mutables)))
if err != nil {
return newTransactionResponse(err)
}
if auxiliaryResponse := transactionKeeper.superAuxiliary.GetKeeper().Help(context, super.NewAuxiliaryRequest(classificationID, message.FromID, mutables)); !auxiliaryResponse.IsSuccessful() {
return newTransactionResponse(auxiliaryResponse.GetError())
}
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 define.Auxiliary.GetName():
transactionKeeper.defineAuxiliary = value
case super.Auxiliary.GetName():
transactionKeeper.superAuxiliary = value
case authenticate.Auxiliary.GetName():
transactionKeeper.authenticateAuxiliary = value
}
default:
panic(constants.UninitializedUsage)
}
}
return transactionKeeper
}
func keeperPrototype() helpers.TransactionKeeper {
return transactionKeeper{}
}