-
Notifications
You must be signed in to change notification settings - Fork 31
/
authz.go
35 lines (27 loc) · 1.09 KB
/
authz.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
package stakingplus
import (
sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
"github.com/Finschia/finschia-sdk/x/foundation"
stakingtypes "github.com/Finschia/finschia-sdk/x/staking/types"
)
var _ foundation.Authorization = (*CreateValidatorAuthorization)(nil)
func (a CreateValidatorAuthorization) MsgTypeURL() string {
return sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{})
}
func (a CreateValidatorAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (foundation.AcceptResponse, error) {
mCreate, ok := msg.(*stakingtypes.MsgCreateValidator)
if !ok {
return foundation.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
}
if mCreate.ValidatorAddress != a.ValidatorAddress {
return foundation.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrap("validator address differs from the authorization's")
}
return foundation.AcceptResponse{Accept: true}, nil
}
func (a CreateValidatorAuthorization) ValidateBasic() error {
if _, err := sdk.ValAddressFromBech32(a.ValidatorAddress); err != nil {
return err
}
return nil
}