Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Aug 29, 2024
1 parent d2e117d commit a4d13e6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
3 changes: 1 addition & 2 deletions x/assets/keeper/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"

"github.com/ExocoreNetwork/exocore/x/assets/types"
assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -46,7 +45,7 @@ func (k Keeper) PerformDepositOrWithdraw(ctx sdk.Context, params *DepositWithdra
return errorsmod.Wrapf(assetstypes.ErrInvalidOperationType, "the operation type is: %v", params.Action)
}

if types.IsNativeToken(assetID) {
if assetstypes.IsNativeToken(assetID) {
// TODO: we skip check for case like withdraw amount>withdrawable is fine since it will fail for later check and the state will be rollback
actualOpAmount = k.UpdateNativeTokenByDepositOrWithdraw(ctx, assetID, hexutil.Encode(params.StakerAddress), params.OpAmount)
}
Expand Down
5 changes: 2 additions & 3 deletions x/delegation/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Valida
panic(err)
}
// and the other is the fact that it matures at the next block
err = k.StorePendingUndelegationRecord(ctx, recordKey, record)
//TODO: remove previous index with currentHeight for pendingUndelegationRecord
if err != nil {
if err = k.StorePendingUndelegationRecord(ctx, recordKey, record); err != nil {
// TODO: remove previous index with currentHeight for pendingUndelegationRecord
panic(err)
}
continue
Expand Down
24 changes: 12 additions & 12 deletions x/oracle/keeper/native_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ func (k Keeper) GetNativeTokenPriceUSDForOperator(ctx sdk.Context, assetID strin

store := ctx.KVStore(k.storeKey)
key := types.NativeTokenOperatorKey(assetID, operatorAddr)
if value := store.Get(key); value == nil {
value := store.Get(key)
if value == nil {
return types.Price{}, types.ErrGetPriceAssetNotFound
}
operatorInfo := &types.OperatorInfo{}
k.cdc.MustUnmarshal(value, operatorInfo)
baseTokenUSDPrice, err := k.GetSpecifiedAssetsPrice(ctx, assetstypes.GetBaseTokenForNativeToken(assetID))
if err != nil {
return types.Price{}, types.ErrGetPriceAssetNotFound
} else {
operatorInfo := &types.OperatorInfo{}
k.cdc.MustUnmarshal(value, operatorInfo)
baseTokenUSDPrice, err := k.GetSpecifiedAssetsPrice(ctx, assetstypes.GetBaseTokenForNativeToken(assetID))
if err != nil {
return types.Price{}, types.ErrGetPriceAssetNotFound
}
operatorPriceFloat := getLatestOperatorPriceFloat(operatorInfo)
baseTokenUSDPrice.Value = (baseTokenUSDPrice.Value.ToLegacyDec().Mul(operatorPriceFloat)).RoundInt()
return baseTokenUSDPrice, nil
}
operatorPriceFloat := getLatestOperatorPriceFloat(operatorInfo)
baseTokenUSDPrice.Value = (baseTokenUSDPrice.Value.ToLegacyDec().Mul(operatorPriceFloat)).RoundInt()
return baseTokenUSDPrice, nil
}

func (k Keeper) GetStakerList(ctx sdk.Context, assetID string) types.StakerList {
Expand Down Expand Up @@ -340,7 +340,7 @@ func parseBalanceChange(rawData []byte, sl types.StakerList) (map[string]int, er

bitsExtracted := 0
stakerChange := 0
for bitsExtracted < int(lenValue) { //0<8, offset:
for bitsExtracted < int(lenValue) {
bitsLeft := 8 - bitOffset
byteValue := changes[byteIndex] << bitOffset
if (int(lenValue) - bitsExtracted) < bitsLeft {
Expand Down
6 changes: 4 additions & 2 deletions x/oracle/keeper/prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ func (k Keeper) AppendPriceTR(ctx sdk.Context, tokenID uint64, priceTR types.Pri
assetIDs := p.GetAssetIDsFromTokenID(tokenID)
for _, assetID := range assetIDs {
if assetstypes.IsNativeToken(assetID) {
k.UpdateNativeTokenByBalanceChange(ctx, assetID, []byte(priceTR.Price), roundID)
if err := k.UpdateNativeTokenByBalanceChange(ctx, assetID, []byte(priceTR.Price), roundID); err != nil {
// we just report this error in log to notify validators
k.Logger(ctx).Error(types.ErrUpdateNativeTokenVirtualPriceFail.Error(), "error", err)
}
}
}

Expand All @@ -216,7 +219,6 @@ func (k Keeper) AppendPriceTR(ctx sdk.Context, tokenID uint64, priceTR types.Pri

// GrowRoundID Increases roundID with the previous price
func (k Keeper) GrowRoundID(ctx sdk.Context, tokenID uint64) (price string, roundID uint64) {
// logInfo := fmt.Sprintf("add new round with previous price under fail aggregation, tokenID:%d", tokenID)
if pTR, ok := k.GetPriceTRLatest(ctx, tokenID); ok {
pTR.RoundID++
k.AppendPriceTR(ctx, tokenID, pTR)
Expand Down
14 changes: 8 additions & 6 deletions x/oracle/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ const (
invalidParams
getPriceFailedAssetNotFound
getPriceFailedRoundNotFound
updateNativeTokenVirtualPriceFail
)

// x/oracle module sentinel errors
var (
ErrInvalidMsg = sdkerrors.Register(ModuleName, invalidMsg, "invalid input create price")
ErrPriceProposalIgnored = sdkerrors.Register(ModuleName, priceProposalIgnored, "price proposal ignored")
ErrPriceProposalFormatInvalid = sdkerrors.Register(ModuleName, priceProposalFormatInvalid, "price proposal message format invalid")
ErrInvalidParams = sdkerrors.Register(ModuleName, invalidParams, "invalid params")
ErrGetPriceAssetNotFound = sdkerrors.Register(ModuleName, getPriceFailedAssetNotFound, "get price failed for asset not found")
ErrGetPriceRoundNotFound = sdkerrors.Register(ModuleName, getPriceFailedRoundNotFound, "get price failed for round not found")
ErrInvalidMsg = sdkerrors.Register(ModuleName, invalidMsg, "invalid input create price")
ErrPriceProposalIgnored = sdkerrors.Register(ModuleName, priceProposalIgnored, "price proposal ignored")
ErrPriceProposalFormatInvalid = sdkerrors.Register(ModuleName, priceProposalFormatInvalid, "price proposal message format invalid")
ErrInvalidParams = sdkerrors.Register(ModuleName, invalidParams, "invalid params")
ErrGetPriceAssetNotFound = sdkerrors.Register(ModuleName, getPriceFailedAssetNotFound, "get price failed for asset not found")
ErrGetPriceRoundNotFound = sdkerrors.Register(ModuleName, getPriceFailedRoundNotFound, "get price failed for round not found")
ErrUpdateNativeTokenVirtualPriceFail = sdkerrors.Register(ModuleName, updateNativeTokenVirtualPriceFail, "update native token balance change failed")
)

0 comments on commit a4d13e6

Please sign in to comment.