diff --git a/CHANGELOG.md b/CHANGELOG.md index 544d5e061..5ba6406d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ older clients. ### API Breaking Changes +* [\#6409](https://github.com/cosmos/cosmos-sdk/pull/6409) Rename all IsEmpty methods to Empty across the codebase and enforce consistency. * [\#6231](https://github.com/cosmos/cosmos-sdk/pull/6231) Simplify `AppModule` interface, `Route` and `NewHandler` methods become only `Route` and returns a new `Route` type. * [\#6212](https://github.com/cosmos/cosmos-sdk/pull/6212) Remove `Get*` prefixes from key construction functions diff --git a/x/gov/types/genesis.go b/x/gov/types/genesis.go index 45c8e21ad..038a0b8a2 100644 --- a/x/gov/types/genesis.go +++ b/x/gov/types/genesis.go @@ -48,8 +48,8 @@ func (data GenesisState) Equal(other GenesisState) bool { data.VotingParams.Equal(other.VotingParams) } -// IsEmpty returns true if a GenesisState is empty -func (data GenesisState) IsEmpty() bool { +// Empty returns true if a GenesisState is empty +func (data GenesisState) Empty() bool { return data.Equal(GenesisState{}) } diff --git a/x/ibc/03-connection/types/connection.go b/x/ibc/03-connection/types/connection.go index 0e1e2e3b1..5406b60e3 100644 --- a/x/ibc/03-connection/types/connection.go +++ b/x/ibc/03-connection/types/connection.go @@ -103,7 +103,7 @@ func (c Counterparty) ValidateBasic() error { if err := host.ClientIdentifierValidator(c.ClientID); err != nil { return sdkerrors.Wrap(err, "invalid counterparty client ID") } - if c.Prefix.IsEmpty() { + if c.Prefix.Empty() { return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty prefix cannot be empty") } return nil diff --git a/x/ibc/03-connection/types/msgs.go b/x/ibc/03-connection/types/msgs.go index 669525040..1b61f4332 100644 --- a/x/ibc/03-connection/types/msgs.go +++ b/x/ibc/03-connection/types/msgs.go @@ -109,7 +109,7 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "version can't be blank") } } - if msg.ProofInit.IsEmpty() || msg.ProofConsensus.IsEmpty() { + if msg.ProofInit.Empty() || msg.ProofConsensus.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofInit.ValidateBasic(); err != nil { @@ -177,7 +177,7 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { if strings.TrimSpace(msg.Version) == "" { return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "version can't be blank") } - if msg.ProofTry.IsEmpty() || msg.ProofConsensus.IsEmpty() { + if msg.ProofTry.Empty() || msg.ProofConsensus.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofTry.ValidateBasic(); err != nil { @@ -238,7 +238,7 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(msg.ConnectionID); err != nil { return sdkerrors.Wrap(err, "invalid connection ID") } - if msg.ProofAck.IsEmpty() { + if msg.ProofAck.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofAck.ValidateBasic(); err != nil { diff --git a/x/ibc/04-channel/types/msgs.go b/x/ibc/04-channel/types/msgs.go index ab5427a02..6c038f5ac 100644 --- a/x/ibc/04-channel/types/msgs.go +++ b/x/ibc/04-channel/types/msgs.go @@ -101,7 +101,7 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { if strings.TrimSpace(msg.CounterpartyVersion) == "" { return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty version cannot be blank") } - if msg.ProofInit.IsEmpty() { + if msg.ProofInit.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofInit.ValidateBasic(); err != nil { @@ -162,7 +162,7 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { if strings.TrimSpace(msg.CounterpartyVersion) == "" { return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty version cannot be blank") } - if msg.ProofTry.IsEmpty() { + if msg.ProofTry.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofTry.ValidateBasic(); err != nil { @@ -219,7 +219,7 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil { return sdkerrors.Wrap(err, "invalid channel ID") } - if msg.ProofAck.IsEmpty() { + if msg.ProofAck.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofAck.ValidateBasic(); err != nil { @@ -321,7 +321,7 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil { return sdkerrors.Wrap(err, "invalid channel ID") } - if msg.ProofInit.IsEmpty() { + if msg.ProofInit.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.ProofInit.ValidateBasic(); err != nil { @@ -366,7 +366,7 @@ func (msg MsgPacket) Route() string { // ValidateBasic implements sdk.Msg func (msg MsgPacket) ValidateBasic() error { - if msg.Proof.IsEmpty() { + if msg.Proof.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.Proof.ValidateBasic(); err != nil { @@ -427,7 +427,7 @@ func (msg MsgTimeout) Route() string { // ValidateBasic implements sdk.Msg func (msg MsgTimeout) ValidateBasic() error { - if msg.Proof.IsEmpty() { + if msg.Proof.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.Proof.ValidateBasic(); err != nil { @@ -479,7 +479,7 @@ func (msg MsgAcknowledgement) Route() string { // ValidateBasic implements sdk.Msg func (msg MsgAcknowledgement) ValidateBasic() error { - if msg.Proof.IsEmpty() { + if msg.Proof.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if err := msg.Proof.ValidateBasic(); err != nil { diff --git a/x/ibc/07-tendermint/types/consensus_state.go b/x/ibc/07-tendermint/types/consensus_state.go index 2bfc29f2b..6dbe1d247 100644 --- a/x/ibc/07-tendermint/types/consensus_state.go +++ b/x/ibc/07-tendermint/types/consensus_state.go @@ -54,7 +54,7 @@ func (cs ConsensusState) GetTimestamp() uint64 { // ValidateBasic defines a basic validation for the tendermint consensus state. func (cs ConsensusState) ValidateBasic() error { - if cs.Root == nil || cs.Root.IsEmpty() { + if cs.Root == nil || cs.Root.Empty() { return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "root cannot be empty") } if cs.ValidatorSet == nil { diff --git a/x/ibc/23-commitment/exported/exported.go b/x/ibc/23-commitment/exported/exported.go index c6fbbce3a..5f31d6c91 100644 --- a/x/ibc/23-commitment/exported/exported.go +++ b/x/ibc/23-commitment/exported/exported.go @@ -14,7 +14,7 @@ package exported type Root interface { GetCommitmentType() Type GetHash() []byte - IsEmpty() bool + Empty() bool } // Prefix implements spec:CommitmentPrefix. @@ -22,7 +22,7 @@ type Root interface { type Prefix interface { GetCommitmentType() Type Bytes() []byte - IsEmpty() bool + Empty() bool } // Path implements spec:CommitmentPath. @@ -30,7 +30,7 @@ type Prefix interface { type Path interface { GetCommitmentType() Type String() string - IsEmpty() bool + Empty() bool } // Proof implements spec:CommitmentProof. @@ -41,7 +41,7 @@ type Proof interface { GetCommitmentType() Type VerifyMembership(Root, Path, []byte) error VerifyNonMembership(Root, Path) error - IsEmpty() bool + Empty() bool ValidateBasic() error } diff --git a/x/ibc/23-commitment/types/merkle.go b/x/ibc/23-commitment/types/merkle.go index 2040b1179..e66b22479 100644 --- a/x/ibc/23-commitment/types/merkle.go +++ b/x/ibc/23-commitment/types/merkle.go @@ -36,8 +36,8 @@ func (MerkleRoot) GetCommitmentType() exported.Type { return exported.Merkle } -// IsEmpty returns true if the root is empty -func (mr MerkleRoot) IsEmpty() bool { +// Empty returns true if the root is empty +func (mr MerkleRoot) Empty() bool { return len(mr.GetHash()) == 0 } @@ -60,8 +60,8 @@ func (mp MerklePrefix) Bytes() []byte { return mp.KeyPrefix } -// IsEmpty returns true if the prefix is empty -func (mp MerklePrefix) IsEmpty() bool { +// Empty returns true if the prefix is empty +func (mp MerklePrefix) Empty() bool { return len(mp.Bytes()) == 0 } @@ -98,8 +98,8 @@ func (mp MerklePath) Pretty() string { return path } -// IsEmpty returns true if the path is empty -func (mp MerklePath) IsEmpty() bool { +// Empty returns true if the path is empty +func (mp MerklePath) Empty() bool { return len(mp.KeyPath.Keys) == 0 } @@ -114,7 +114,7 @@ func ApplyPrefix(prefix exported.Prefix, path string) (MerklePath, error) { return MerklePath{}, err } - if prefix == nil || prefix.IsEmpty() { + if prefix == nil || prefix.Empty() { return MerklePath{}, sdkerrors.Wrap(ErrInvalidPrefix, "prefix can't be empty") } return NewMerklePath([]string{string(prefix.Bytes()), path}), nil @@ -129,7 +129,7 @@ func (MerkleProof) GetCommitmentType() exported.Type { // VerifyMembership verifies the membership pf a merkle proof against the given root, path, and value. func (proof MerkleProof) VerifyMembership(root exported.Root, path exported.Path, value []byte) error { - if proof.IsEmpty() || root == nil || root.IsEmpty() || path == nil || path.IsEmpty() || len(value) == 0 { + if proof.Empty() || root == nil || root.Empty() || path == nil || path.Empty() || len(value) == 0 { return sdkerrors.Wrap(ErrInvalidMerkleProof, "empty params or proof") } @@ -139,7 +139,7 @@ func (proof MerkleProof) VerifyMembership(root exported.Root, path exported.Path // VerifyNonMembership verifies the absence of a merkle proof against the given root and path. func (proof MerkleProof) VerifyNonMembership(root exported.Root, path exported.Path) error { - if proof.IsEmpty() || root == nil || root.IsEmpty() || path == nil || path.IsEmpty() { + if proof.Empty() || root == nil || root.Empty() || path == nil || path.Empty() { return sdkerrors.Wrap(ErrInvalidMerkleProof, "empty params or proof") } @@ -147,14 +147,14 @@ func (proof MerkleProof) VerifyNonMembership(root exported.Root, path exported.P return runtime.VerifyAbsence(proof.Proof, root.GetHash(), path.String()) } -// IsEmpty returns true if the root is empty -func (proof MerkleProof) IsEmpty() bool { +// Empty returns true if the root is empty +func (proof MerkleProof) Empty() bool { return proof.Proof.Equal(nil) || proof.Equal(MerkleProof{}) || proof.Proof.Equal(nil) || proof.Proof.Equal(merkle.Proof{}) } // ValidateBasic checks if the proof is empty. func (proof MerkleProof) ValidateBasic() error { - if proof.IsEmpty() { + if proof.Empty() { return ErrInvalidProof } return nil