Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: migrate x/evidence to hybridcodec #5634

Merged
merged 97 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
adfae21
Migrate types to use proto
alexanderbez Jan 7, 2020
72f70c0
Add newline
alexanderbez Jan 7, 2020
80ab9d6
Fix rand_util
alexanderbez Jan 7, 2020
bf49ef2
Add nolint
alexanderbez Jan 7, 2020
d9c08cf
Implement amino marshal interface for int, uint, and dec
alexanderbez Jan 7, 2020
c5e5c6b
Update encoding doc
alexanderbez Jan 8, 2020
c1b17a5
Update CircleCI config
alexanderbez Jan 8, 2020
28b2da6
Remove tools target from proto job
alexanderbez Jan 8, 2020
f039b99
Rename to CustomProtobufType
alexanderbez Jan 8, 2020
49aa60d
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 8, 2020
cd092c0
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 8, 2020
b3463f7
changed proto docker image
Jan 8, 2020
f05929c
changed proto job to skip the binary installs
Jan 8, 2020
52e0a49
removed extra files and update proto CI
Jan 8, 2020
161f23b
Use third_party over vendor
alexanderbez Jan 9, 2020
5098419
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 9, 2020
7501af3
Merge PR #5505: Convert Int and Dec to string's on Coin and DecCoin p…
aaronc Jan 13, 2020
5c6c08c
Update go.sum
alexanderbez Jan 13, 2020
2e80b77
Fix protoc-gen-gocosmos target by allowing versioning
alexanderbez Jan 13, 2020
9e6a906
Lint
alexanderbez Jan 13, 2020
33400ef
Update go.{mod, sum} and install
alexanderbez Jan 13, 2020
241eafb
wildcard import
alexanderbez Jan 13, 2020
489d5e0
Merge branch 'master' into bez/5444-types-proto-enc
alexanderbez Jan 13, 2020
01f7766
go mod tidy
alexanderbez Jan 13, 2020
bb4ae4e
Bump cosmos-proto to v0.1.0
alexanderbez Jan 13, 2020
d6182fb
Update go.{mod, sum}
alexanderbez Jan 13, 2020
ba12a87
Update third party proto deps
alexanderbez Jan 15, 2020
153dadd
Define Marshaler and ProtoMarshaler interfaces along with BaseCodec type
alexanderbez Jan 16, 2020
94ca99c
Initial commit/demo
alexanderbez Jan 16, 2020
4113099
Fix MarshalAccount
alexanderbez Jan 17, 2020
4499aa0
proto: migrate x/evidence to hybridcodec
tac0turtle Feb 11, 2020
7fd26dd
Prep merge from master
alexanderbez Feb 11, 2020
b268466
Merge branch 'master' into bez/5444-auth-proto-enc
alexanderbez Feb 11, 2020
d463703
Merge branch 'master' into proto/evidence
tac0turtle Feb 11, 2020
fb6fc91
Update codec pkg
alexanderbez Feb 11, 2020
e1d2287
init on mint module
tac0turtle Feb 11, 2020
2d7e8a8
Fix GetAccountWithHeight
alexanderbez Feb 11, 2020
f8c4632
Use codec json over json pkg
alexanderbez Feb 11, 2020
9ef271e
move to custom type over decproto
tac0turtle Feb 11, 2020
2b3644b
add custom marshlers for evidenceI
tac0turtle Feb 11, 2020
aaeaf2e
Update auth types
alexanderbez Feb 11, 2020
305db41
Update account marshal tests
alexanderbez Feb 11, 2020
31af710
Update vesting types
alexanderbez Feb 11, 2020
c21d5fe
Update module APIs
alexanderbez Feb 11, 2020
769e57f
Update client logic to use pkg-level codec
alexanderbez Feb 11, 2020
c242f1c
Proto
alexanderbez Feb 11, 2020
b1d6213
add mint to app codec
tac0turtle Feb 12, 2020
e896ac3
add evidence to appcodec
tac0turtle Feb 12, 2020
45f516e
decoder test
tac0turtle Feb 12, 2020
dc862d1
yaml.marshler in params
tac0turtle Feb 12, 2020
2fa963a
some missed evidienc to ei changes
tac0turtle Feb 13, 2020
41773be
Update vesting (remove codec)
alexanderbez Feb 13, 2020
b218b1e
Update auth types
alexanderbez Feb 13, 2020
56f824b
Update proto
alexanderbez Feb 13, 2020
38338fd
Undo account interface naming
alexanderbez Feb 13, 2020
df62b47
Update APIs
alexanderbez Feb 13, 2020
d9dbdd6
Update alias
alexanderbez Feb 13, 2020
6849bcb
Update simapp codec
alexanderbez Feb 13, 2020
e2fccc0
Add missing UnmarshalAccountJSON
alexanderbez Feb 13, 2020
66c8beb
Update simapp
alexanderbez Feb 13, 2020
96e36b4
Migrate x/supply to proto and update Supply interface
alexanderbez Feb 13, 2020
4d49c14
cleanup module codecs
alexanderbez Feb 13, 2020
4b1b6bb
Define SupplyCodec
alexanderbez Feb 13, 2020
f0aab9f
Restructure x/supply
alexanderbez Feb 13, 2020
fd1758f
Supply proto updates
alexanderbez Feb 14, 2020
98de856
Merge branch 'master' into bez/5444-auth-proto-enc
alexanderbez Feb 14, 2020
eebcba3
Refactor Module Manager to use codec
alexanderbez Feb 14, 2020
348a7e1
Update genutil
alexanderbez Feb 14, 2020
c52731d
Fix cal to DefaultGenesis
alexanderbez Feb 14, 2020
0dfd3ef
Lint
alexanderbez Feb 14, 2020
e9d161c
Fix supply tests
alexanderbez Feb 14, 2020
098e3a9
Update changelog
alexanderbez Feb 14, 2020
2c721af
Update changelog
alexanderbez Feb 14, 2020
2482e86
Add error checking
alexanderbez Feb 15, 2020
08502d6
Remove x/auth Account test type and codec
alexanderbez Feb 15, 2020
40497b6
Merge branch 'bez/5444-auth-proto-enc' into proto/evidence
tac0turtle Feb 17, 2020
2d2ca85
minor change to evidence
tac0turtle Feb 17, 2020
908454e
remove internal frmo mint and generate proto files
tac0turtle Feb 17, 2020
458f682
fix internal imports
tac0turtle Feb 17, 2020
afdac31
Merge branch 'master' into proto/evidence
tac0turtle Feb 20, 2020
14caef0
fix merge conflict bugs
tac0turtle Feb 20, 2020
804ef66
Merge branch 'master' into proto/evidence
alexanderbez Feb 21, 2020
dc39c6a
Update app codec
alexanderbez Feb 21, 2020
4a6278b
Linting
alexanderbez Feb 21, 2020
44db137
Update app codec
alexanderbez Feb 21, 2020
09a1ca6
Update evidence types
alexanderbez Feb 21, 2020
e8cdf95
Update evidence tests
alexanderbez Feb 21, 2020
cedd9d4
Implement MsgSubmitEvidence interface type
alexanderbez Feb 21, 2020
5043f0b
Update mint
alexanderbez Feb 21, 2020
e823947
Fix evidence keeper tests
alexanderbez Feb 24, 2020
2938880
proto lint
alexanderbez Feb 24, 2020
a61d854
Update x/mint
alexanderbez Feb 24, 2020
b871d4b
lint
alexanderbez Feb 24, 2020
ae1ad5c
Update ADR
alexanderbez Feb 24, 2020
5e4340e
Merge branch 'master' into proto/evidence
alexanderbez Feb 24, 2020
7da1786
Add changelog entries
alexanderbez Feb 24, 2020
08f28d9
Merge branch 'proto/evidence' of github.com:cosmos/cosmos-sdk into pr…
alexanderbez Feb 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func NewSimApp(
appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
)
app.MintKeeper = mint.NewKeeper(
app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
appCodec.Mint, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName,
)
app.DistrKeeper = distr.NewKeeper(
Expand All @@ -192,7 +192,7 @@ func NewSimApp(

// create evidence keeper with router
evidenceKeeper := evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper,
appCodec.Evidence, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper,
)
evidenceRouter := evidence.NewRouter()
// TODO: Register evidence routes.
Expand Down
6 changes: 6 additions & 0 deletions simapp/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/staking"
)

Expand All @@ -15,6 +17,8 @@ type AppCodec struct {

Staking *staking.Codec
Distribution *distr.Codec
Mint *mint.Codec
Evidence *evidence.Codec
}

func NewAppCodec() *AppCodec {
Expand All @@ -24,6 +28,8 @@ func NewAppCodec() *AppCodec {
amino: amino,
Staking: staking.NewCodec(amino),
Distribution: distr.NewCodec(amino),
Mint: mint.NewCodec(amino),
Evidence: evidence.NewCodec(amino),
}
}

Expand Down
2 changes: 2 additions & 0 deletions x/evidence/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
KeyMaxEvidenceAge = types.KeyMaxEvidenceAge
DoubleSignJailEndTime = types.DoubleSignJailEndTime
ParamKeyTable = types.ParamKeyTable
NewCodec = types.NewCodec
)

type (
Expand All @@ -50,4 +51,5 @@ type (
Handler = types.Handler
Router = types.Router
Equivocation = types.Equivocation
Codec = types.Codec
)
4 changes: 2 additions & 2 deletions x/evidence/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func queryEvidence(cdc *codec.Codec, cliCtx context.CLIContext, hash string) err
return err
}

var evidence exported.Evidence
var evidence exported.EvidenceI
err = cdc.UnmarshalJSON(res, &evidence)
if err != nil {
return fmt.Errorf("failed to unmarshal evidence: %w", err)
Expand All @@ -133,7 +133,7 @@ func queryAllEvidence(cdc *codec.Codec, cliCtx context.CLIContext) error {
return err
}

var evidence []exported.Evidence
var evidence []exported.EvidenceI
err = cdc.UnmarshalJSON(res, &evidence)
if err != nil {
return fmt.Errorf("failed to unmarshal evidence: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/exported/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Evidence defines the contract which concrete evidence types of misbehavior
// must implement.
type Evidence interface {
type EvidenceI interface {
Route() string
Type() string
String() string
Expand Down
6 changes: 3 additions & 3 deletions x/evidence/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (suite *GenesisTestSuite) SetupTest() {

// recreate keeper in order to use custom testing types
evidenceKeeper := evidence.NewKeeper(
cdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper,
types.ModuleCdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper,
)
router := evidence.NewRouter()
router = router.AddRoute(types.TestEvidenceRouteEquivocation, types.TestEquivocationHandler(*evidenceKeeper))
Expand All @@ -45,7 +45,7 @@ func (suite *GenesisTestSuite) SetupTest() {
func (suite *GenesisTestSuite) TestInitGenesis_Valid() {
pk := ed25519.GenPrivKey()

testEvidence := make([]exported.Evidence, 100)
testEvidence := make([]exported.EvidenceI, 100)
for i := 0; i < 100; i++ {
sv := types.TestVote{
ValidatorAddress: pk.PubKey().Address(),
Expand Down Expand Up @@ -78,7 +78,7 @@ func (suite *GenesisTestSuite) TestInitGenesis_Valid() {
func (suite *GenesisTestSuite) TestInitGenesis_Invalid() {
pk := ed25519.GenPrivKey()

testEvidence := make([]exported.Evidence, 100)
testEvidence := make([]exported.EvidenceI, 100)
for i := 0; i < 100; i++ {
sv := types.TestVote{
ValidatorAddress: pk.PubKey().Address(),
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (suite *HandlerTestSuite) SetupTest() {

// recreate keeper in order to use custom testing types
evidenceKeeper := evidence.NewKeeper(
cdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper,
types.ModuleCdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper,
)
router := evidence.NewRouter()
router = router.AddRoute(types.TestEvidenceRouteEquivocation, types.TestEquivocationHandler(*evidenceKeeper))
Expand Down
18 changes: 9 additions & 9 deletions x/evidence/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// managing persistence, state transitions and query handling for the evidence
// module.
type Keeper struct {
cdc *codec.Codec
cdc codec.Marshaler
storeKey sdk.StoreKey
paramSpace params.Subspace
router types.Router
Expand All @@ -28,7 +28,7 @@ type Keeper struct {
}

func NewKeeper(
cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspace,
cdc codec.Marshaler, storeKey sdk.StoreKey, paramSpace params.Subspace,
stakingKeeper types.StakingKeeper, slashingKeeper types.SlashingKeeper,
) *Keeper {

Expand Down Expand Up @@ -83,7 +83,7 @@ func (k Keeper) GetEvidenceHandler(evidenceRoute string) (types.Handler, error)
// the corresponding registered Evidence Handler. An error is returned if no
// registered Handler exists or if the Handler fails. Otherwise, the evidence is
// persisted.
func (k Keeper) SubmitEvidence(ctx sdk.Context, evidence exported.Evidence) error {
func (k Keeper) SubmitEvidence(ctx sdk.Context, evidence exported.EvidenceI) error {
if _, ok := k.GetEvidence(ctx, evidence.Hash()); ok {
return sdkerrors.Wrap(types.ErrEvidenceExists, evidence.Hash().String())
}
Expand All @@ -108,15 +108,15 @@ func (k Keeper) SubmitEvidence(ctx sdk.Context, evidence exported.Evidence) erro
}

// SetEvidence sets Evidence by hash in the module's KVStore.
func (k Keeper) SetEvidence(ctx sdk.Context, evidence exported.Evidence) {
func (k Keeper) SetEvidence(ctx sdk.Context, evidence exported.EvidenceI) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixEvidence)
bz := k.cdc.MustMarshalBinaryLengthPrefixed(evidence)
store.Set(evidence.Hash(), bz)
}

// GetEvidence retrieves Evidence by hash if it exists. If no Evidence exists for
// the given hash, (nil, false) is returned.
func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (evidence exported.Evidence, found bool) {
func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (evidence exported.EvidenceI, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixEvidence)

bz := store.Get(hash)
Expand All @@ -131,13 +131,13 @@ func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (evidence ex
// IterateEvidence provides an interator over all stored Evidence objects. For
// each Evidence object, cb will be called. If the cb returns true, the iterator
// will close and stop.
func (k Keeper) IterateEvidence(ctx sdk.Context, cb func(exported.Evidence) bool) {
func (k Keeper) IterateEvidence(ctx sdk.Context, cb func(exported.EvidenceI) bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixEvidence)
iterator := sdk.KVStorePrefixIterator(store, nil)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var evidence exported.Evidence
var evidence exported.EvidenceI
k.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &evidence)

if cb(evidence) {
Expand All @@ -147,8 +147,8 @@ func (k Keeper) IterateEvidence(ctx sdk.Context, cb func(exported.Evidence) bool
}

// GetAllEvidence returns all stored Evidence objects.
func (k Keeper) GetAllEvidence(ctx sdk.Context) (evidence []exported.Evidence) {
k.IterateEvidence(ctx, func(e exported.Evidence) bool {
func (k Keeper) GetAllEvidence(ctx sdk.Context) (evidence []exported.EvidenceI) {
k.IterateEvidence(ctx, func(e exported.EvidenceI) bool {
evidence = append(evidence, e)
return false
})
Expand Down
6 changes: 3 additions & 3 deletions x/evidence/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (suite *KeeperTestSuite) SetupTest() {

// recreate keeper in order to use custom testing types
evidenceKeeper := evidence.NewKeeper(
cdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper,
types.ModuleCdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper,
)
router := evidence.NewRouter()
router = router.AddRoute(types.TestEvidenceRouteEquivocation, types.TestEquivocationHandler(*evidenceKeeper))
Expand All @@ -84,8 +84,8 @@ func (suite *KeeperTestSuite) SetupTest() {
}
}

func (suite *KeeperTestSuite) populateEvidence(ctx sdk.Context, numEvidence int) []exported.Evidence {
evidence := make([]exported.Evidence, numEvidence)
func (suite *KeeperTestSuite) populateEvidence(ctx sdk.Context, numEvidence int) []exported.EvidenceI {
evidence := make([]exported.EvidenceI, numEvidence)

for i := 0; i < numEvidence; i++ {
pk := ed25519.GenPrivKey()
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/internal/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func queryAllEvidence(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte,

start, end := client.Paginate(len(evidence), params.Page, params.Limit, 100)
if start < 0 || end < 0 {
evidence = []exported.Evidence{}
evidence = []exported.EvidenceI{}
} else {
evidence = evidence[start:end]
}
Expand Down
6 changes: 3 additions & 3 deletions x/evidence/internal/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (suite *KeeperTestSuite) TestQueryEvidence_Existing() {
suite.Nil(err)
suite.NotNil(bz)

var e exported.Evidence
var e exported.EvidenceI
suite.Nil(types.TestingCdc.UnmarshalJSON(bz, &e))
suite.Equal(evidence[0], e)
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) TestQueryAllEvidence() {
suite.Nil(err)
suite.NotNil(bz)

var e []exported.Evidence
var e []exported.EvidenceI
suite.Nil(types.TestingCdc.UnmarshalJSON(bz, &e))
suite.Len(e, numEvidence)
}
Expand All @@ -80,7 +80,7 @@ func (suite *KeeperTestSuite) TestQueryAllEvidence_InvalidPagination() {
suite.Nil(err)
suite.NotNil(bz)

var e []exported.Evidence
var e []exported.EvidenceI
suite.Nil(types.TestingCdc.UnmarshalJSON(bz, &e))
suite.Len(e, 0)
}
Expand Down
59 changes: 55 additions & 4 deletions x/evidence/internal/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,35 @@ import (
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
)

// EvidenceCodec defines the interface required to serialize evidence
type EvidenceCodec interface {
codec.Marshaler
MarshalEvidence(acc exported.EvidenceI) ([]byte, error)
UnmarshalEvidence(bz []byte) (exported.EvidenceI, error)
MarshalEvidenceJSON(acc exported.EvidenceI) ([]byte, error)
UnmarshalEvidenceJSON(bz []byte) (exported.EvidenceI, error)
}

type Codec struct {
codec.Marshaler

// Keep reference to the amino codec to allow backwards compatibility along
// with type, and interface registration.
amino *codec.Codec
}

func NewCodec(amino *codec.Codec) *Codec {
return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino}
}

// ModuleCdc defines the evidence module's codec. The codec is not sealed as to
// allow other modules to register their concrete Evidence types.
var ModuleCdc = codec.New()
var ModuleCdc = NewCodec(codec.New())

// RegisterCodec registers all the necessary types and interfaces for the
// evidence module.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.Evidence)(nil), nil)
cdc.RegisterInterface((*exported.EvidenceI)(nil), nil)
cdc.RegisterConcrete(MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence", nil)
cdc.RegisterConcrete(Equivocation{}, "cosmos-sdk/Equivocation", nil)
}
Expand All @@ -21,9 +42,39 @@ func RegisterCodec(cdc *codec.Codec) {
// in another module for the internal ModuleCdc. This allows the MsgSubmitEvidence
// to be correctly Amino encoded and decoded.
func RegisterEvidenceTypeCodec(o interface{}, name string) {
ModuleCdc.RegisterConcrete(o, name, nil)
ModuleCdc.amino.RegisterConcrete(o, name, nil)
}

func init() {
RegisterCodec(ModuleCdc)
RegisterCodec(ModuleCdc.amino)
}

// MarshalEvidence marshals an EvidenceI interface.
func (c *Codec) MarshalEvidence(eviI exported.EvidenceI) ([]byte, error) {
evi := &Evidence{}
evi.SetEvidenceI(eviI)
return c.MarshalBinaryLengthPrefixed(evi)
}

// UnmarshalEvidence returnes an EvidenceI interface.
func (c *Codec) UnmarshalEvidence(bz []byte) (exported.EvidenceI, error) {
evi := &Evidence{}
if err := c.UnmarshalBinaryLengthPrefixed(bz, evi); err != nil {
return nil, err
}
return evi.GetEvidenceI(), nil
}

// MarshalEvidenceJSON JSON encodes an evidence object implementating the EvidenceI interface
func (c *Codec) MarshalEvidenceJSON(evi exported.EvidenceI) ([]byte, error) {
return c.MarshalJSON(evi)
}

// UnmarshalEvidenceJSON returns an EvidenceI from JSON encoded bytes
func (c *Codec) UnmarshalEvidenceJSON(bz []byte) (exported.EvidenceI, error) {
evi := &Evidence{}
if err := c.UnmarshalJSON(bz, evi); err != nil {
return nil, err
}
return evi.GetEvidenceI(), nil
}
4 changes: 2 additions & 2 deletions x/evidence/internal/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/evidence/internal/types"
)

var _ exported.Evidence = (*testEvidence)(nil)
var _ exported.EvidenceI = (*testEvidence)(nil)

type testEvidence struct{}

Expand All @@ -31,7 +31,7 @@ func TestCodec(t *testing.T) {
types.RegisterCodec(cdc)
types.RegisterEvidenceTypeCodec(testEvidence{}, "cosmos-sdk/testEvidence")

var e exported.Evidence = testEvidence{}
var e exported.EvidenceI = testEvidence{}
bz, err := cdc.MarshalBinaryBare(e)
require.NoError(t, err)

Expand Down
18 changes: 5 additions & 13 deletions x/evidence/internal/types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ const (
TypeEquivocation = "equivocation"
)

var _ exported.Evidence = (*Equivocation)(nil)

// Equivocation implements the Evidence interface and defines evidence of double
// signing misbehavior.
type Equivocation struct {
Height int64 `json:"height" yaml:"height"`
Time time.Time `json:"time" yaml:"time"`
Power int64 `json:"power" yaml:"power"`
ConsensusAddress sdk.ConsAddress `json:"consensus_address" yaml:"consensus_address"`
}
var _ exported.EvidenceI = (*Equivocation)(nil)

// Route returns the Evidence Handler route for an Equivocation type.
func (e Equivocation) Route() string { return RouteEquivocation }
Expand All @@ -43,7 +34,7 @@ func (e Equivocation) String() string {

// Hash returns the hash of an Equivocation object.
func (e Equivocation) Hash() tmbytes.HexBytes {
return tmhash.Sum(ModuleCdc.MustMarshalBinaryBare(e))
return tmhash.Sum(ModuleCdc.MustMarshalBinaryBare(&e))
}

// ValidateBasic performs basic stateless validation checks on an Equivocation object.
Expand All @@ -57,7 +48,8 @@ func (e Equivocation) ValidateBasic() error {
if e.Power < 1 {
return fmt.Errorf("invalid equivocation validator power: %d", e.Power)
}
if e.ConsensusAddress.Empty() {
consaddr := sdk.ConsAddress(e.ConsensusAddress)
if consaddr.Empty() {
return fmt.Errorf("invalid equivocation validator consensus address: %s", e.ConsensusAddress)
}

Expand Down Expand Up @@ -91,7 +83,7 @@ func (e Equivocation) GetTotalPower() int64 { return 0 }

// ConvertDuplicateVoteEvidence converts a Tendermint concrete Evidence type to
// SDK Evidence using Equivocation as the concrete type.
func ConvertDuplicateVoteEvidence(dupVote abci.Evidence) exported.Evidence {
func ConvertDuplicateVoteEvidence(dupVote abci.Evidence) exported.EvidenceI {
return Equivocation{
Height: dupVote.Height,
Power: dupVote.Validator.Power,
Expand Down
Loading