-
Notifications
You must be signed in to change notification settings - Fork 12
/
auxiliary_keeper.go
61 lines (47 loc) · 2.05 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
53
54
55
56
57
58
59
60
61
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package authenticate
import (
"context"
errorConstants "github.com/AssetMantle/schema/go/errors/constants"
"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/x/identities/key"
"github.com/AssetMantle/modules/x/identities/mappable"
"github.com/AssetMantle/modules/x/metas/auxiliaries/supplement"
)
type auxiliaryKeeper struct {
mapper helpers.Mapper
parameterManager helpers.ParameterManager
supplementAuxiliary helpers.Auxiliary
}
var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil)
func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) {
auxiliaryRequest := auxiliaryRequestFromInterface(request)
Mappable := auxiliaryKeeper.mapper.NewCollection(context).Fetch(key.NewKey(auxiliaryRequest.IdentityID)).GetMappable(key.NewKey(auxiliaryRequest.IdentityID))
if Mappable == nil {
return nil, errorConstants.EntityNotFound.Wrapf("identity with ID %s not found", auxiliaryRequest.IdentityID.AsString())
}
identity := mappable.GetIdentity(Mappable)
if !identity.IsProvisioned(auxiliaryRequest.Address) {
return nil, errorConstants.NotAuthorized.Wrapf("address %s is not provisioned for identity with ID %s", auxiliaryRequest.Address.String(), auxiliaryRequest.IdentityID.AsString())
}
return newAuxiliaryResponse(), nil
}
func (auxiliaryKeeper auxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, auxiliaries []interface{}) helpers.Keeper {
auxiliaryKeeper.mapper, auxiliaryKeeper.parameterManager = mapper, parameterManager
for _, auxiliary := range auxiliaries {
switch value := auxiliary.(type) {
case helpers.Auxiliary:
switch value.GetName() {
case supplement.Auxiliary.GetName():
auxiliaryKeeper.supplementAuxiliary = value
default:
break
}
}
}
return auxiliaryKeeper
}
func keeperPrototype() helpers.AuxiliaryKeeper {
return auxiliaryKeeper{}
}