2020-02-24 08:05:21 -08:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2020-05-05 07:28:20 -07:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
2020-02-24 08:05:21 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2020-05-05 07:28:20 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
2020-02-24 08:05:21 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Message types for the evidence module
|
|
|
|
const (
|
|
|
|
TypeMsgSubmitEvidence = "submit_evidence"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-06-03 12:52:05 -07:00
|
|
|
_ sdk.Msg = &MsgSubmitEvidence{}
|
2020-05-05 07:28:20 -07:00
|
|
|
_ types.UnpackInterfacesMessage = MsgSubmitEvidence{}
|
2020-10-16 09:05:25 -07:00
|
|
|
_ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{}
|
2020-02-24 08:05:21 -08:00
|
|
|
)
|
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
// NewMsgSubmitEvidence returns a new MsgSubmitEvidence with a signer/submitter.
|
2020-09-25 03:25:37 -07:00
|
|
|
//nolint:interfacer
|
2020-06-03 12:52:05 -07:00
|
|
|
func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (*MsgSubmitEvidence, error) {
|
2020-05-05 07:28:20 -07:00
|
|
|
msg, ok := evi.(proto.Message)
|
|
|
|
if !ok {
|
2020-06-03 12:52:05 -07:00
|
|
|
return nil, fmt.Errorf("cannot proto marshal %T", evi)
|
2020-05-05 07:28:20 -07:00
|
|
|
}
|
|
|
|
any, err := types.NewAnyWithValue(msg)
|
|
|
|
if err != nil {
|
2020-06-03 12:52:05 -07:00
|
|
|
return nil, err
|
2020-05-05 07:28:20 -07:00
|
|
|
}
|
2020-09-25 03:25:37 -07:00
|
|
|
return &MsgSubmitEvidence{Submitter: s.String(), Evidence: any}, nil
|
2020-02-24 08:05:21 -08:00
|
|
|
}
|
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
// Route returns the MsgSubmitEvidence's route.
|
|
|
|
func (m MsgSubmitEvidence) Route() string { return RouterKey }
|
2020-02-24 08:05:21 -08:00
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
// Type returns the MsgSubmitEvidence's type.
|
|
|
|
func (m MsgSubmitEvidence) Type() string { return TypeMsgSubmitEvidence }
|
2020-02-24 08:05:21 -08:00
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
// ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitEvidence.
|
|
|
|
func (m MsgSubmitEvidence) ValidateBasic() error {
|
2020-09-25 03:25:37 -07:00
|
|
|
if m.Submitter == "" {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, m.Submitter)
|
2020-02-24 08:05:21 -08:00
|
|
|
}
|
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
evi := m.GetEvidence()
|
|
|
|
if evi == nil {
|
|
|
|
return sdkerrors.Wrap(ErrInvalidEvidence, "missing evidence")
|
|
|
|
}
|
|
|
|
if err := evi.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-24 08:05:21 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSignBytes returns the raw bytes a signer is expected to sign when submitting
|
2020-05-05 07:28:20 -07:00
|
|
|
// a MsgSubmitEvidence message.
|
|
|
|
func (m MsgSubmitEvidence) GetSignBytes() []byte {
|
2020-08-26 02:39:38 -07:00
|
|
|
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
|
2020-02-24 08:05:21 -08:00
|
|
|
}
|
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
// GetSigners returns the single expected signer for a MsgSubmitEvidence.
|
|
|
|
func (m MsgSubmitEvidence) GetSigners() []sdk.AccAddress {
|
2020-09-25 03:25:37 -07:00
|
|
|
accAddr, err := sdk.AccAddressFromBech32(m.Submitter)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return []sdk.AccAddress{accAddr}
|
2020-02-24 08:05:21 -08:00
|
|
|
}
|
2020-05-05 07:28:20 -07:00
|
|
|
|
|
|
|
func (m MsgSubmitEvidence) GetEvidence() exported.Evidence {
|
|
|
|
evi, ok := m.Evidence.GetCachedValue().(exported.Evidence)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return evi
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MsgSubmitEvidence) GetSubmitter() sdk.AccAddress {
|
2020-09-25 03:25:37 -07:00
|
|
|
accAddr, err := sdk.AccAddressFromBech32(m.Submitter)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return accAddr
|
2020-05-05 07:28:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m MsgSubmitEvidence) UnpackInterfaces(ctx types.AnyUnpacker) error {
|
|
|
|
var evi exported.Evidence
|
|
|
|
return ctx.UnpackAny(m.Evidence, &evi)
|
|
|
|
}
|