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

Rename all methods IsEmpty to Empty to be consistent with all codebase #6409

Merged
merged 6 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/gov/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}

Expand Down
2 changes: 1 addition & 1 deletion x/ibc/03-connection/types/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions x/ibc/03-connection/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions x/ibc/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/07-tendermint/types/consensus_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions x/ibc/23-commitment/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ package exported
type Root interface {
GetCommitmentType() Type
GetHash() []byte
IsEmpty() bool
Empty() bool
}

// Prefix implements spec:CommitmentPrefix.
// Prefix represents the common "prefix" that a set of keys shares.
type Prefix interface {
GetCommitmentType() Type
Bytes() []byte
IsEmpty() bool
Empty() bool
}

// Path implements spec:CommitmentPath.
// A path is the additional information provided to the verification function.
type Path interface {
GetCommitmentType() Type
String() string
IsEmpty() bool
Empty() bool
}

// Proof implements spec:CommitmentProof.
Expand All @@ -41,7 +41,7 @@ type Proof interface {
GetCommitmentType() Type
VerifyMembership(Root, Path, []byte) error
VerifyNonMembership(Root, Path) error
IsEmpty() bool
Empty() bool

ValidateBasic() error
}
Expand Down
24 changes: 12 additions & 12 deletions x/ibc/23-commitment/types/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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")
}

Expand All @@ -139,22 +139,22 @@ 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")
}

runtime := rootmulti.DefaultProofRuntime()
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
Expand Down