-
Notifications
You must be signed in to change notification settings - Fork 132
/
keeper_delegate_key.go
58 lines (48 loc) · 1.99 KB
/
keeper_delegate_key.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
package keeper
import (
"context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/palomachain/paloma/util/liblog"
"github.com/palomachain/paloma/x/skyway/types"
)
///////////////////////////
//// ADDRESS DELEGATION ///
///////////////////////////
// GetOrchestratorValidator returns the validator key associated with an orchestrator key
func (k Keeper) GetOrchestratorValidator(ctx context.Context, orch sdk.AccAddress) (validator stakingtypes.Validator, found bool, err error) {
valAddr := sdk.ValAddress(orch)
if valAddr == nil {
return validator, false, fmt.Errorf("nil valAddr")
}
if err := sdk.VerifyAddressFormat(orch); err != nil {
liblog.FromSDKLogger(k.Logger(ctx)).WithError(err).Error("invalid orch address")
return validator, false, err
}
validator, err = k.StakingKeeper.GetValidator(ctx, valAddr)
if err != nil {
liblog.FromSDKLogger(k.Logger(ctx)).WithError(err).Error("unable to get validator")
return validator, false, err
}
return validator, true, nil
}
/////////////////////////////
// ETH ADDRESS //
/////////////////////////////
// GetEthAddressByValidator returns the eth address for a given skyway validator
func (k Keeper) GetEthAddressByValidator(ctx context.Context, validator sdk.ValAddress, chainReferenceId string) (ethAddress *types.EthAddress, found bool, err error) {
return k.evmKeeper.GetEthAddressByValidator(ctx, validator, chainReferenceId)
}
// GetValidatorByEthAddress returns the validator for a given eth address
func (k Keeper) GetValidatorByEthAddress(ctx context.Context, ethAddr types.EthAddress, chainReferenceId string) (validator stakingtypes.Validator, found bool, err error) {
valAddr, found, err := k.evmKeeper.GetValidatorAddressByEthAddress(ctx, ethAddr, chainReferenceId)
if err != nil {
return validator, false, err
}
if valAddr == nil {
return validator, false, nil
}
validator, err = k.StakingKeeper.GetValidator(ctx, valAddr)
return validator, found, nil
}