Skip to content

Commit

Permalink
refactor: namming and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
minhngoc274 authored and Duong Minh Ngoc committed Jan 11, 2024
1 parent 4733799 commit bdb6a60
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 159 deletions.
8 changes: 4 additions & 4 deletions proto/feeabstraction/absfee/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ service Query {
}

rpc HostChainConfig(QueryHostChainConfigRequest)
returns (QueryHostChainConfigRespone) {
returns (QueryHostChainConfigResponse) {
option (google.api.http).get =
"/fee-abstraction/feeabs/v1/host-chain-config/{ibc_denom}";
}

rpc AllHostChainConfig(AllQueryHostChainConfigRequest)
returns (AllQueryHostChainConfigRespone) {
returns (AllQueryHostChainConfigResponse) {
option (google.api.http).get =
"/fee-abstraction/feeabs/v1/all-host-chain-config";
}
}

message QueryHostChainConfigRequest { string ibc_denom = 1; }

message QueryHostChainConfigRespone {
message QueryHostChainConfigResponse {
HostChainFeeAbsConfig host_chain_config = 1 [
(gogoproto.moretags) = "yaml:\"host_chain_config\"",
(gogoproto.nullable) = false
Expand Down Expand Up @@ -73,7 +73,7 @@ message QueryFeeabsModuleBalacesResponse {

message AllQueryHostChainConfigRequest {}

message AllQueryHostChainConfigRespone {
message AllQueryHostChainConfigResponse {
repeated HostChainFeeAbsConfig all_host_chain_config = 1 [
(gogoproto.moretags) = "yaml:\"all_host_chain_config\"",
(gogoproto.nullable) = false
Expand Down
8 changes: 4 additions & 4 deletions tests/interchaintest/packet_foward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,17 @@ func TestPacketForwardMiddleware(t *testing.T) {
})
}

func QueryFeeabsHostZoneConfig(c *cosmos.CosmosChain, ctx context.Context) (*QueryHostChainConfigRespone, error) {
func QueryFeeabsHostZoneConfig(c *cosmos.CosmosChain, ctx context.Context) (*QueryHostChainConfigResponse, error) {
cmd := []string{"feeabs", "all-host-chain-config"}
stdout, _, err := c.ExecQuery(ctx, cmd)
if err != nil {
return &QueryHostChainConfigRespone{}, err
return &QueryHostChainConfigResponse{}, err
}

var hostZoneConfig QueryHostChainConfigRespone
var hostZoneConfig QueryHostChainConfigResponse
err = json.Unmarshal(stdout, &hostZoneConfig)
if err != nil {
return &QueryHostChainConfigRespone{}, err
return &QueryHostChainConfigResponse{}, err
}

return &hostZoneConfig, nil
Expand Down
2 changes: 1 addition & 1 deletion tests/interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type QueryFeeabsModuleBalacesResponse struct {
Address string
}

type QueryHostChainConfigRespone struct {
type QueryHostChainConfigResponse struct {
HostChainConfig cosmos.HostChainFeeAbsConfig `protobuf:"bytes,1,opt,name=host_chain_config,json=hostChainConfig,proto3" json:"host_chain_config" yaml:"host_chain_config"`
}

Expand Down
11 changes: 3 additions & 8 deletions x/feeabs/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,10 @@ func (k Keeper) GetAllHostZoneConfig(ctx sdk.Context) (allChainConfigs []types.H
return allChainConfigs, nil
}

func (k Keeper) IteratorHostZone(ctx sdk.Context) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
return sdk.KVStorePrefixIterator(store, types.KeyHostChainChainConfigByFeeAbs)
}

// IterateHostZone iterates over the hostzone .
func (k Keeper) IterateHostZone(ctx sdk.Context, cb func(hostZoneConfig types.HostChainFeeAbsConfig) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyHostChainChainConfigByFeeAbs)
iterator := sdk.KVStorePrefixIterator(store, types.KeyHostChainConfigByFeeAbs)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
Expand All @@ -101,7 +96,7 @@ func (k Keeper) IterateHostZone(ctx sdk.Context, cb func(hostZoneConfig types.Ho
}
}

func (k Keeper) FrozenHostZoneByIBCDenom(ctx sdk.Context, ibcDenom string) error {
func (k Keeper) FreezeHostZoneByIBCDenom(ctx sdk.Context, ibcDenom string) error {
hostChainConfig, found := k.GetHostZoneConfig(ctx, ibcDenom)
if !found {
return types.ErrHostZoneConfigNotFound
Expand All @@ -115,7 +110,7 @@ func (k Keeper) FrozenHostZoneByIBCDenom(ctx sdk.Context, ibcDenom string) error
return nil
}

func (k Keeper) UnFrozenHostZoneByIBCDenom(ctx sdk.Context, ibcDenom string) error {
func (k Keeper) UnFreezeHostZoneByIBCDenom(ctx sdk.Context, ibcDenom string) error {
hostChainConfig, found := k.GetHostZoneConfig(ctx, ibcDenom)
if !found {
return types.ErrHostZoneConfigNotFound
Expand Down
18 changes: 0 additions & 18 deletions x/feeabs/keeper/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ func (k Keeper) setEpochInfo(ctx sdk.Context, epoch types.EpochInfo) {
store.Set(append(types.KeyPrefixEpoch, []byte(epoch.Identifier)...), value)
}

// DeleteEpochInfo delete epoch info.
func (k Keeper) DeleteEpochInfo(ctx sdk.Context, identifier string) {
store := ctx.KVStore(k.storeKey)
store.Delete(append(types.KeyPrefixEpoch, []byte(identifier)...))
}

// IterateEpochInfo iterate through epochs.
func (k Keeper) IterateEpochInfo(ctx sdk.Context, fn func(index int64, epochInfo types.EpochInfo) (stop bool)) {
store := ctx.KVStore(k.storeKey)
Expand Down Expand Up @@ -104,18 +98,6 @@ func (k Keeper) AllEpochInfos(ctx sdk.Context) []types.EpochInfo {
return epochs
}

// NumBlocksSinceEpochStart returns the number of blocks since the epoch started.
// if the epoch started on block N, then calling this during block N (after BeforeEpochStart)
// would return 0.
// Calling it any point in block N+1 (assuming the epoch doesn't increment) would return 1.
func (k Keeper) NumBlocksSinceEpochStart(ctx sdk.Context, identifier string) (int64, error) {
epoch := k.GetEpochInfo(ctx, identifier)
if (epoch == types.EpochInfo{}) {
return 0, fmt.Errorf("epoch with identifier %s not found", identifier)
}
return ctx.BlockHeight() - epoch.CurrentEpochStartHeight, nil
}

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string) {
switch epochIdentifier {
case types.DefaultQueryEpochIdentifier:
Expand Down
8 changes: 4 additions & 4 deletions x/feeabs/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (q Querier) FeeabsModuleBalances(goCtx context.Context, req *types.QueryFee
}, nil
}

func (q Querier) HostChainConfig(goCtx context.Context, req *types.QueryHostChainConfigRequest) (*types.QueryHostChainConfigRespone, error) {
func (q Querier) HostChainConfig(goCtx context.Context, req *types.QueryHostChainConfigRequest) (*types.QueryHostChainConfigResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -70,12 +70,12 @@ func (q Querier) HostChainConfig(goCtx context.Context, req *types.QueryHostChai
return nil, types.ErrHostZoneConfigNotFound
}

return &types.QueryHostChainConfigRespone{
return &types.QueryHostChainConfigResponse{
HostChainConfig: hostChainConfig,
}, nil
}

func (q Querier) AllHostChainConfig(goCtx context.Context, req *types.AllQueryHostChainConfigRequest) (*types.AllQueryHostChainConfigRespone, error) {
func (q Querier) AllHostChainConfig(goCtx context.Context, req *types.AllQueryHostChainConfigRequest) (*types.AllQueryHostChainConfigResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -87,7 +87,7 @@ func (q Querier) AllHostChainConfig(goCtx context.Context, req *types.AllQueryHo
return nil, err
}

return &types.AllQueryHostChainConfigRespone{
return &types.AllQueryHostChainConfigResponse{
AllHostChainConfig: allHostChainConfig,
}, nil
}
6 changes: 3 additions & 3 deletions x/feeabs/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func (s *KeeperTestSuite) TestHostChainConfig() {
for _, tc := range []struct {
desc string
req *types.QueryHostChainConfigRequest
res *types.QueryHostChainConfigRespone
res *types.QueryHostChainConfigResponse
shouldErr bool
}{
{
desc: "Success",
req: &types.QueryHostChainConfigRequest{
IbcDenom: chainConfig.IbcDenom,
},
res: &types.QueryHostChainConfigRespone{
res: &types.QueryHostChainConfigResponse{
HostChainConfig: chainConfig,
},
shouldErr: false,
Expand All @@ -88,7 +88,7 @@ func (s *KeeperTestSuite) TestHostChainConfig() {
req: &types.QueryHostChainConfigRequest{
IbcDenom: "Invalid",
},
res: &types.QueryHostChainConfigRespone{
res: &types.QueryHostChainConfigResponse{
HostChainConfig: chainConfig,
},
shouldErr: true,
Expand Down
8 changes: 4 additions & 4 deletions x/feeabs/keeper/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, ack channeltypes.Acknow

if icqRes.Code != 0 {
k.Logger(ctx).Error(fmt.Sprintf("Failed to send interchain query code %d", icqRes.Code))
err := k.FrozenHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
err := k.FreezeHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
if err != nil {
// should never happen
k.Logger(ctx).Error(fmt.Sprintf("Failed to frozen host zone %s", err.Error()))
Expand All @@ -155,7 +155,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, ack channeltypes.Acknow
k.Logger(ctx).Info(fmt.Sprintf("TwapRate %v", twapRate))
k.SetTwapRate(ctx, hostZoneConfig.IbcDenom, twapRate)

err = k.UnFrozenHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
err = k.UnFreezeHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
if err != nil {
// should never happen
k.Logger(ctx).Error(fmt.Sprintf("Failed to frozen host zone %s", err.Error()))
Expand All @@ -172,7 +172,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, ack channeltypes.Acknow
)
case *channeltypes.Acknowledgement_Error:
k.IterateHostZone(ctx, func(hostZoneConfig types.HostChainFeeAbsConfig) (stop bool) {
err := k.FrozenHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
err := k.FreezeHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Failed to frozen host zone %s", err.Error()))
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (k Keeper) executeAllHostChainSwap(ctx sdk.Context) {

if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Failed to transfer IBC token %s", err.Error()))
err = k.FrozenHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
err = k.FreezeHostZoneByIBCDenom(ctx, hostZoneConfig.IbcDenom)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Failed to frozem host zone %s", err.Error()))
}
Expand Down
16 changes: 8 additions & 8 deletions x/feeabs/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ type (
)

var (
OsmosisTwapExchangeRate = []byte{0x01} // Key for the exchange rate of osmosis (to native token)
KeyChannelID = []byte{0x02} // Key for IBC channel to osmosis
KeyHostChainChainConfigByFeeAbs = []byte{0x03} // Key for IBC channel to osmosis
KeyHostChainChainConfigByOsmosis = []byte{0x04} // Key for IBC channel to osmosis
KeyPrefixEpoch = []byte{0x05} // KeyPrefixEpoch defines prefix key for storing epochs.
KeyTokenDenomPair = []byte{0x06} // Key store token denom pair on feeabs and osmosis
OsmosisTwapExchangeRate = []byte{0x01} // Key for the exchange rate of osmosis (to native token)
KeyChannelID = []byte{0x02} // Key for IBC channel to osmosis
KeyHostChainConfigByFeeAbs = []byte{0x03} // Key for IBC channel to osmosis
KeyHostChainConfigByOsmosis = []byte{0x04} // Key for IBC channel to osmosis
KeyPrefixEpoch = []byte{0x05} // KeyPrefixEpoch defines prefix key for storing epochs.
KeyTokenDenomPair = []byte{0x06} // Key store token denom pair on feeabs and osmosis
)

func GetKeyHostZoneConfigByFeeabsIBCDenom(feeabsIbcDenom string) []byte {
return append(KeyHostChainChainConfigByFeeAbs, []byte(feeabsIbcDenom)...)
return append(KeyHostChainConfigByFeeAbs, []byte(feeabsIbcDenom)...)
}

func GetKeyHostZoneConfigByOsmosisIBCDenom(osmosisIbcDenom string) []byte {
return append(KeyHostChainChainConfigByOsmosis, []byte(osmosisIbcDenom)...)
return append(KeyHostChainConfigByOsmosis, []byte(osmosisIbcDenom)...)
}

func GetKeyTwapExchangeRate(ibcDenom string) []byte {
Expand Down
Loading

0 comments on commit bdb6a60

Please sign in to comment.