2024-07-03 11:38:48 +00:00
|
|
|
package onboarding
|
|
|
|
|
|
|
|
import (
|
2024-07-26 14:42:40 +00:00
|
|
|
"fmt"
|
|
|
|
|
2024-07-03 11:38:48 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
)
|
|
|
|
|
2024-07-26 14:42:40 +00:00
|
|
|
var PERMITTED_ROLES = []string{"participant", "validator"}
|
|
|
|
|
2024-07-11 05:16:31 +00:00
|
|
|
var _ sdk.Msg = &MsgOnboardParticipant{}
|
2024-07-03 11:38:48 +00:00
|
|
|
|
|
|
|
func (msg MsgOnboardParticipant) ValidateBasic() error {
|
|
|
|
if len(msg.Participant) == 0 {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrorInvalidSigner, msg.Participant)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(msg.EthPayload.Address) != 42 {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Participant)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(msg.EthSignature) != 132 {
|
2024-07-26 14:42:40 +00:00
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid signature.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(msg.KycId) == 0 {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Empty KYC ID.")
|
|
|
|
}
|
|
|
|
|
|
|
|
isRoleValid := false
|
|
|
|
for _, v := range PERMITTED_ROLES {
|
|
|
|
if msg.Role == v {
|
|
|
|
isRoleValid = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isRoleValid {
|
|
|
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("Participant role has to be one of: %v", PERMITTED_ROLES))
|
2024-07-03 11:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|