Skip to content

Commit

Permalink
refactor: eliminate unnecessary nil check in BigEndianToUint64 function
Browse files Browse the repository at this point in the history
  • Loading branch information
fx0x55 committed Oct 23, 2024
1 parent edcf0b2 commit 8500327
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 31 deletions.
7 changes: 1 addition & 6 deletions x/crosschain/keeper/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,5 @@ func (k Keeper) SetLastEventBlockHeightByOracle(ctx sdk.Context, oracleAddr sdk.
// GetLastEventBlockHeightByOracle get the latest event blockHeight for a give oracle
func (k Keeper) GetLastEventBlockHeightByOracle(ctx sdk.Context, oracleAddr sdk.AccAddress) uint64 {
store := ctx.KVStore(k.storeKey)
key := types.GetLastEventBlockHeightByOracleKey(oracleAddr)
if !store.Has(key) {
return 0
}
data := store.Get(key)
return sdk.BigEndianToUint64(data)
return sdk.BigEndianToUint64(store.Get(types.GetLastEventBlockHeightByOracleKey(oracleAddr)))
}
6 changes: 1 addition & 5 deletions x/crosschain/keeper/batch_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ func (k Keeper) SetLastSlashedBatchBlock(ctx sdk.Context, blockHeight uint64) {
// GetLastSlashedBatchBlock returns the latest slashed Batch block
func (k Keeper) GetLastSlashedBatchBlock(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
bytes := store.Get(types.LastSlashedBatchBlock)
if len(bytes) == 0 {
return 0
}
return sdk.BigEndianToUint64(bytes)
return sdk.BigEndianToUint64(store.Get(types.LastSlashedBatchBlock))
}

// GetUnSlashedBatches returns all the unSlashed batches in state
Expand Down
6 changes: 1 addition & 5 deletions x/crosschain/keeper/observed.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import (
// GetLastObservedEventNonce returns the latest observed event nonce
func (k Keeper) GetLastObservedEventNonce(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
bytes := store.Get(types.LastObservedEventNonceKey)
if len(bytes) == 0 {
return 0
}
return sdk.BigEndianToUint64(bytes)
return sdk.BigEndianToUint64(store.Get(types.LastObservedEventNonceKey))
}

// SetLastObservedEventNonce sets the latest observed event nonce
Expand Down
6 changes: 1 addition & 5 deletions x/crosschain/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,5 @@ func (k Keeper) SetLastOracleSlashBlockHeight(ctx sdk.Context, blockHeight uint6
// GetLastOracleSlashBlockHeight returns the last proposal block height
func (k Keeper) GetLastOracleSlashBlockHeight(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
data := store.Get(types.LastOracleSlashBlockHeight)
if len(data) == 0 {
return 0
}
return sdk.BigEndianToUint64(data)
return sdk.BigEndianToUint64(store.Get(types.LastOracleSlashBlockHeight))
}
6 changes: 1 addition & 5 deletions x/crosschain/keeper/oracle_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,7 @@ func (k Keeper) SetLatestOracleSetNonce(ctx sdk.Context, nonce uint64) {
// GetLatestOracleSetNonce returns the latest oracleSet nonce
func (k Keeper) GetLatestOracleSetNonce(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
data := store.Get(types.LatestOracleSetNonce)
if len(data) == 0 {
return 0
}
return sdk.BigEndianToUint64(data)
return sdk.BigEndianToUint64(store.Get(types.LatestOracleSetNonce))
}

// GetUnSlashedOracleSets returns all the unSlashed oracle sets in state
Expand Down
6 changes: 1 addition & 5 deletions x/crosschain/keeper/oracle_set_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,5 @@ func (k Keeper) SetLastSlashedOracleSetNonce(ctx sdk.Context, nonce uint64) {
// GetLastSlashedOracleSetNonce returns the latest slashed oracleSet nonce
func (k Keeper) GetLastSlashedOracleSetNonce(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
data := store.Get(types.LastSlashedOracleSetNonce)
if len(data) == 0 {
return 0
}
return sdk.BigEndianToUint64(data)
return sdk.BigEndianToUint64(store.Get(types.LastSlashedOracleSetNonce))
}

0 comments on commit 8500327

Please sign in to comment.