-
Notifications
You must be signed in to change notification settings - Fork 12
/
auxiliary_keeper.go
52 lines (37 loc) · 1.81 KB
/
auxiliary_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
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package transfer
import (
"context"
"github.com/AssetMantle/schema/go/data"
errorConstants "github.com/AssetMantle/schema/go/errors/constants"
propertyConstants "github.com/AssetMantle/schema/go/properties/constants"
"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/x/splits/utilities"
)
type auxiliaryKeeper struct {
mapper helpers.Mapper
parameterManager helpers.ParameterManager
}
var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil)
func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) {
if !auxiliaryKeeper.parameterManager.Fetch(context).GetParameter(propertyConstants.TransferEnabledProperty.GetID()).GetMetaProperty().GetData().Get().(data.BooleanData).Get() {
return nil, errorConstants.NotAuthorized.Wrapf("transfer is not enabled")
}
auxiliaryRequest := auxiliaryRequestFromInterface(request)
splits := auxiliaryKeeper.mapper.NewCollection(context)
if _, err := utilities.SubtractSplits(splits, auxiliaryRequest.FromID, auxiliaryRequest.AssetID, auxiliaryRequest.Value); err != nil {
return newAuxiliaryResponse(), err
}
if _, err := utilities.AddSplits(splits, auxiliaryRequest.ToID, auxiliaryRequest.AssetID, auxiliaryRequest.Value); err != nil {
return newAuxiliaryResponse(), err
}
return newAuxiliaryResponse(), nil
}
func (auxiliaryKeeper auxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, _ []interface{}) helpers.Keeper {
auxiliaryKeeper.mapper, auxiliaryKeeper.parameterManager = mapper, parameterManager
return auxiliaryKeeper
}
func keeperPrototype() helpers.AuxiliaryKeeper {
return auxiliaryKeeper{}
}