diff --git a/CHANGELOG_UNRELEASED.md b/CHANGELOG_UNRELEASED.md index 8bab8bd607..eaf6d2ea52 100644 --- a/CHANGELOG_UNRELEASED.md +++ b/CHANGELOG_UNRELEASED.md @@ -10,6 +10,7 @@ ### Chain +- (chore) [\#1933](https://github.com/bandprotocol/bandchain/pull/1933) Improve code quality and conciseness in x/oracle/keeper. - (bugs) [\#1935](https://github.com/bandprotocol/bandchain/pull/1935) Fix wrong order on call search latest request. - (feat) [\#1927](https://github.com/bandprotocol/bandchain/pull/1927) Add reporter list of validator REST endpoint. - (impv) [\#1891](https://github.com/bandprotocol/bandchain/pull/1891) Add end-to-end request flow test. diff --git a/chain/x/oracle/keeper/data_source.go b/chain/x/oracle/keeper/data_source.go index cbe0794e74..12e4ff668d 100644 --- a/chain/x/oracle/keeper/data_source.go +++ b/chain/x/oracle/keeper/data_source.go @@ -1,9 +1,10 @@ package keeper import ( - "github.com/bandprotocol/bandchain/chain/x/oracle/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/bandprotocol/bandchain/chain/x/oracle/types" ) // HasDataSource checks if the data source of this ID exists in the storage. diff --git a/chain/x/oracle/keeper/keeper.go b/chain/x/oracle/keeper/keeper.go index 2e92126c3d..f4281acaee 100644 --- a/chain/x/oracle/keeper/keeper.go +++ b/chain/x/oracle/keeper/keeper.go @@ -10,7 +10,6 @@ import ( porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types" "github.com/cosmos/cosmos-sdk/x/params" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/staking" "github.com/tendermint/tendermint/libs/log" "github.com/bandprotocol/bandchain/chain/pkg/filecache" @@ -30,8 +29,8 @@ type Keeper struct { // NewKeeper creates a new oracle Keeper instance. func NewKeeper( - cdc *codec.Codec, key sdk.StoreKey, fileDir string, - paramSpace params.Subspace, stakingKeeper staking.Keeper, channelKeeper types.ChannelKeeper, + cdc *codec.Codec, key sdk.StoreKey, fileDir string, paramSpace params.Subspace, + stakingKeeper types.StakingKeeper, channelKeeper types.ChannelKeeper, scopedKeeper capability.ScopedKeeper, portKeeper types.PortKeeper, ) Keeper { if !paramSpace.HasKeyTable() { @@ -114,18 +113,15 @@ func (k Keeper) GetRequestLastExpired(ctx sdk.Context) int64 { // If the global request count is not set, it initializes it with value 0. func (k Keeper) GetNextRequestID(ctx sdk.Context) types.RequestID { requestNumber := k.GetRequestCount(ctx) - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(requestNumber + 1) - store.Set(types.RequestCountStoreKey, bz) + ctx.KVStore(k.storeKey).Set(types.RequestCountStoreKey, bz) return types.RequestID(requestNumber + 1) } // GetDataSourceCount returns the current number of all data sources ever exist. func (k Keeper) GetDataSourceCount(ctx sdk.Context) int64 { var dataSourceCount int64 - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.DataSourceCountStoreKey) + bz := ctx.KVStore(k.storeKey).Get(types.DataSourceCountStoreKey) if bz == nil { return 0 } @@ -137,17 +133,15 @@ func (k Keeper) GetDataSourceCount(ctx sdk.Context) int64 { // If the global data source count is not set, it initializes the value and returns 1. func (k Keeper) GetNextDataSourceID(ctx sdk.Context) types.DataSourceID { dataSourceCount := k.GetDataSourceCount(ctx) - store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshalBinaryLengthPrefixed(dataSourceCount + 1) - store.Set(types.DataSourceCountStoreKey, bz) + ctx.KVStore(k.storeKey).Set(types.DataSourceCountStoreKey, bz) return types.DataSourceID(dataSourceCount + 1) } // GetOracleScriptCount returns the current number of all oracle scripts ever exist. func (k Keeper) GetOracleScriptCount(ctx sdk.Context) int64 { var oracleScriptCount int64 - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.OracleScriptCountStoreKey) + bz := ctx.KVStore(k.storeKey).Get(types.OracleScriptCountStoreKey) if bz == nil { return 0 } @@ -159,9 +153,8 @@ func (k Keeper) GetOracleScriptCount(ctx sdk.Context) int64 { // If the global oracle script count is not set, it initializes the value and returns 1. func (k Keeper) GetNextOracleScriptID(ctx sdk.Context) types.OracleScriptID { oracleScriptCount := k.GetOracleScriptCount(ctx) - store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshalBinaryLengthPrefixed(oracleScriptCount + 1) - store.Set(types.OracleScriptCountStoreKey, bz) + ctx.KVStore(k.storeKey).Set(types.OracleScriptCountStoreKey, bz) return types.OracleScriptID(oracleScriptCount + 1) } diff --git a/chain/x/oracle/keeper/oracle_script.go b/chain/x/oracle/keeper/oracle_script.go index 5e6292beb1..12baf79441 100644 --- a/chain/x/oracle/keeper/oracle_script.go +++ b/chain/x/oracle/keeper/oracle_script.go @@ -1,9 +1,10 @@ package keeper import ( - "github.com/bandprotocol/bandchain/chain/x/oracle/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/bandprotocol/bandchain/chain/x/oracle/types" ) // HasOracleScript checks if the oracle script of this ID exists in the storage. @@ -47,7 +48,6 @@ func (k Keeper) AddOracleScript(ctx sdk.Context, oracleScript types.OracleScript // MustEditOracleScript edits the given oracle script by id and flushes it to the storage. Panic if not exists. func (k Keeper) MustEditOracleScript(ctx sdk.Context, id types.OracleScriptID, new types.OracleScript) { oracleScript := k.MustGetOracleScript(ctx, id) - oracleScript.Owner = new.Owner oracleScript.Name = modify(oracleScript.Name, new.Name) oracleScript.Description = modify(oracleScript.Description, new.Description) diff --git a/chain/x/oracle/keeper/report.go b/chain/x/oracle/keeper/report.go index 8bf5924152..fbc1a7fece 100644 --- a/chain/x/oracle/keeper/report.go +++ b/chain/x/oracle/keeper/report.go @@ -1,9 +1,10 @@ package keeper import ( - "github.com/bandprotocol/bandchain/chain/x/oracle/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/bandprotocol/bandchain/chain/x/oracle/types" ) // HasReport checks if the report of this ID triple exists in the storage. diff --git a/chain/x/oracle/keeper/reporter.go b/chain/x/oracle/keeper/reporter.go index 0dbdb83a02..babdce7e1d 100644 --- a/chain/x/oracle/keeper/reporter.go +++ b/chain/x/oracle/keeper/reporter.go @@ -1,9 +1,10 @@ package keeper import ( - "github.com/bandprotocol/bandchain/chain/x/oracle/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/bandprotocol/bandchain/chain/x/oracle/types" ) // IsReporter returns true iff the address is an authorized reporter for the given validator.