Skip to content

Commit

Permalink
refactor: remove sprintf
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
  • Loading branch information
Francisco de Borja Aranda Castillejo committed Jul 12, 2024
1 parent 9b98839 commit 732f11f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
26 changes: 10 additions & 16 deletions x/observer/keeper/msg_server_update_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -25,18 +24,16 @@ func (k msgServer) UpdateObserver(
return nil, errorsmod.Wrap(types.ErrUpdateObserver, err.Error())
}
if !ok {
return nil, errorsmod.Wrap(
return nil, errorsmod.Wrapf(
types.ErrUpdateObserver,
fmt.Sprintf("Unable to update observer with update reason : %s", msg.UpdateReason),
)
"Unable to update observer with update reason : %s", msg.UpdateReason)
}

// We do not use IsNonTombstonedObserver here because we want to allow tombstoned observers to be updated
if !k.IsAddressPartOfObserverSet(ctx, msg.OldObserverAddress) {
return nil, errorsmod.Wrap(
return nil, errorsmod.Wrapf(
types.ErrNotObserver,
fmt.Sprintf("Observer address is not authorized : %s", msg.OldObserverAddress),
)
"Observer address is not authorized : %s", msg.OldObserverAddress)
}

err = k.IsValidator(ctx, msg.NewObserverAddress)
Expand All @@ -53,10 +50,9 @@ func (k msgServer) UpdateObserver(
// Update the node account with the new operator address
nodeAccount, found := k.GetNodeAccount(ctx, msg.OldObserverAddress)
if !found {
return nil, errorsmod.Wrap(
return nil, errorsmod.Wrapf(
types.ErrNodeAccountNotFound,
fmt.Sprintf("Observer node account not found : %s", msg.OldObserverAddress),
)
"Observer node account not found : %s", msg.OldObserverAddress)
}
newNodeAccount := nodeAccount
newNodeAccount.Operator = msg.NewObserverAddress
Expand All @@ -68,15 +64,15 @@ func (k msgServer) UpdateObserver(
// Check LastBlockObserver count just to be safe
observerSet, found := k.GetObserverSet(ctx)
if !found {
return nil, errorsmod.Wrap(types.ErrObserverSetNotFound, fmt.Sprintf("Observer set not found"))
return nil, errorsmod.Wrap(types.ErrObserverSetNotFound, "Observer set not found")
}
totalObserverCountCurrentBlock := observerSet.LenUint()
lastBlockCount, found := k.GetLastObserverCount(ctx)
if !found {
return nil, errorsmod.Wrap(types.ErrLastObserverCountNotFound, fmt.Sprintf("Observer count not found"))
return nil, errorsmod.Wrap(types.ErrLastObserverCountNotFound, "Observer count not found")
}
if lastBlockCount.Count != totalObserverCountCurrentBlock {
return nil, errorsmod.Wrap(types.ErrUpdateObserver, fmt.Sprintf("Observer count mismatch"))
return nil, errorsmod.Wrap(types.ErrUpdateObserver, "Observer count mismatch")
}
return &types.MsgUpdateObserverResponse{}, nil
}
Expand All @@ -88,9 +84,7 @@ func (k Keeper) CheckUpdateReason(ctx sdk.Context, msg *types.MsgUpdateObserver)
if msg.Creator != msg.OldObserverAddress {
return false, errorsmod.Wrap(
types.ErrUpdateObserver,
fmt.Sprintf(
"Creator address and old observer address need to be same for updating tombstoned observer",
),
"Creator address and old observer address need to be same for updating tombstoned observer",
)
}
return k.IsOperatorTombstoned(ctx, msg.Creator)
Expand Down
8 changes: 3 additions & 5 deletions x/observer/keeper/msg_server_vote_blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -20,10 +19,9 @@ func (k msgServer) VoteBlame(
// GetChainFromChainID makes sure we are getting only supported chains , if a chain support has been turned on using gov proposal, this function returns nil
observationChain, found := k.GetSupportedChainFromChainID(ctx, msg.ChainId)
if !found {
return nil, sdkerrors.Wrap(
return nil, sdkerrors.Wrapf(
crosschainTypes.ErrUnsupportedChain,
fmt.Sprintf("ChainID %d, Blame vote", msg.ChainId),
)
"ChainID %d, Blame vote", msg.ChainId)
}

if ok := k.IsNonTombstonedObserver(ctx, msg.Creator); !ok {
Expand All @@ -39,7 +37,7 @@ func (k msgServer) VoteBlame(
types.VoteType_SuccessObservation,
)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to vote on ballot")
return nil, sdkerrors.Wrap(err, errVoteOnBallot)
}

if isNew {
Expand Down
2 changes: 1 addition & 1 deletion x/observer/keeper/msg_server_vote_block_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (k msgServer) VoteBlockHeader(
types.VoteType_SuccessObservation,
)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to vote on ballot")
return nil, sdkerrors.Wrap(err, errVoteOnBallot)
}

if !isFinalized {
Expand Down
6 changes: 2 additions & 4 deletions x/observer/keeper/msg_server_vote_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -29,10 +28,9 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types
// checks whether a signer is authorized to sign , by checking their address against the observer mapper which contains the observer list for the chain and type
_, found := k.GetNodeAccount(ctx, msg.Creator)
if !found {
return nil, errorsmod.Wrap(
return nil, errorsmod.Wrapf(
sdkerrors.ErrorInvalidSigner,
fmt.Sprintf("signer %s does not have a node account set", msg.Creator),
)
"signer %s does not have a node account set", msg.Creator)
}
// no need to create a ballot if keygen does not exist
keygen, found := k.GetKeygen(ctx)
Expand Down
14 changes: 5 additions & 9 deletions x/observer/keeper/vote_inbound.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"fmt"

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -31,11 +29,10 @@ func (k Keeper) VoteOnInboundBallot(
// this function returns nil
senderChain, found := k.GetSupportedChainFromChainID(ctx, senderChainID)
if !found {
return false, false, sdkerrors.Wrap(types.ErrSupportedChains, fmt.Sprintf(
return false, false, sdkerrors.Wrapf(types.ErrSupportedChains,
"ChainID %d, Observation %s",
senderChainID,
types.ObservationType_InboundTx.String()),
)
types.ObservationType_InboundTx.String())
}

// checks the voter is authorized to vote on the observation chain
Expand All @@ -46,11 +43,10 @@ func (k Keeper) VoteOnInboundBallot(
// makes sure we are getting only supported chains
receiverChain, found := k.GetSupportedChainFromChainID(ctx, receiverChainID)
if !found {
return false, false, sdkerrors.Wrap(types.ErrSupportedChains, fmt.Sprintf(
return false, false, sdkerrors.Wrapf(types.ErrSupportedChains,
"ChainID %d, Observation %s",
receiverChainID,
types.ObservationType_InboundTx.String()),
)
types.ObservationType_InboundTx.String())
}

// check if we want to send ZETA to external chain, but there is no ZETA token.
Expand All @@ -73,7 +69,7 @@ func (k Keeper) VoteOnInboundBallot(
types.VoteType_SuccessObservation,
)
if err != nil {
return false, false, sdkerrors.Wrap(err, "failed to vote on ballot")
return false, false, sdkerrors.Wrap(err, errVoteOnBallot)
}

if isNew {
Expand Down
2 changes: 1 addition & 1 deletion x/observer/keeper/vote_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (k Keeper) VoteOnOutboundBallot(
observertypes.ConvertReceiveStatusToVoteType(receiveStatus),
)
if err != nil {
return false, false, ballot, "", sdkerrors.Wrap(err, "failed to vote on ballot")
return false, false, ballot, "", sdkerrors.Wrap(err, errVoteOnBallot)
}

return isFinalized, isNew, ballot, observationChain.String(), nil
Expand Down
4 changes: 4 additions & 0 deletions x/observer/keeper/voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/zeta-chain/zetacore/x/observer/types"
)

const (
errVoteOnBallot = "error while voting on ballot"
)

func (k Keeper) AddVoteToBallot(
ctx sdk.Context,
ballot types.Ballot,
Expand Down

0 comments on commit 732f11f

Please sign in to comment.