Skip to content

Commit

Permalink
strconv.FormatInt -> Uint64ToBigEndian for int encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0n00gler committed Nov 26, 2024
1 parent 1aac21f commit e008388
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 1 addition & 6 deletions x/state-verifier/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"fmt"
"strconv"

"cosmossdk.io/core/comet"
"cosmossdk.io/core/header"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions x/state-verifier/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "strconv"
import (
"github.com/cosmos/cosmos-sdk/types"
)

const (
// ModuleName defines the module name
Expand All @@ -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))...)
}

0 comments on commit e008388

Please sign in to comment.