From e0083885a8481fe347a3feae654dae690eac27aa Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Tue, 26 Nov 2024 13:55:03 +0200 Subject: [PATCH] strconv.FormatInt -> Uint64ToBigEndian for int encoding --- x/state-verifier/keeper/keeper.go | 7 +------ x/state-verifier/types/keys.go | 6 ++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/x/state-verifier/keeper/keeper.go b/x/state-verifier/keeper/keeper.go index 8b558b1da..f70a7d1b8 100644 --- a/x/state-verifier/keeper/keeper.go +++ b/x/state-verifier/keeper/keeper.go @@ -2,7 +2,6 @@ package keeper import ( "fmt" - "strconv" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" @@ -143,11 +142,7 @@ func (k *Keeper) GetAllConsensusStates(ctx sdk.Context) ([]*types.ConsensusState for ; iterator.Valid(); iterator.Next() { cs := tendermint.ConsensusState{} k.cdc.MustUnmarshal(iterator.Value(), &cs) - height, err := strconv.ParseInt(string(iterator.Key()), 10, 64) - if err != nil { - return nil, errors.Wrapf(err, "failed to extract height from consensus state key") - } - + height := int64(sdk.BigEndianToUint64(iterator.Key())) states = append(states, &types.ConsensusState{ Height: height, Cs: &cs, diff --git a/x/state-verifier/types/keys.go b/x/state-verifier/types/keys.go index 0df1de90a..fbe933b08 100644 --- a/x/state-verifier/types/keys.go +++ b/x/state-verifier/types/keys.go @@ -1,6 +1,8 @@ package types -import "strconv" +import ( + "github.com/cosmos/cosmos-sdk/types" +) const ( // ModuleName defines the module name @@ -17,5 +19,5 @@ const ( var ConsensusStateKey = []byte{prefixConsensusStateKey} func GetConsensusStateKey(height int64) []byte { - return append(ConsensusStateKey, []byte(strconv.FormatInt(height, 10))...) + return append(ConsensusStateKey, types.Uint64ToBigEndian(uint64(height))...) }