laconicd/x/onboarding/msgs.go
Prathamesh Musale 9fab3f8326 Add fields for role and KYC ID for onboarded participants (#43)
Part of [Sumsub KYC integration in onboarding app](https://www.notion.so/Sumsub-KYC-integration-in-onboarding-app-607b598c9c1d4d12adc71725e2ab5e7e)

Reviewed-on: cerc-io/laconicd#43
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-07-26 14:42:40 +00:00

46 lines
1.0 KiB
Go

package onboarding
import (
"fmt"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var PERMITTED_ROLES = []string{"participant", "validator"}
var _ sdk.Msg = &MsgOnboardParticipant{}
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 {
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))
}
return nil
}