Skip to content

Commit

Permalink
call delegation keeper store method from custom staking.
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja committed Dec 19, 2023
1 parent e8a72b9 commit 38c7444
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ
k.mintkeeper.SetLastTotalPower(ctx, math.Int{})
k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{})

k.stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount)

return &types.MsgDelegateResponse{}, nil
// return nil, fmt.Errorf("My custom error: Nikita")
// return k.msgServer.Delegate(goCtx, msg)
Expand Down
21 changes: 20 additions & 1 deletion x/stakingmiddleware/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package keeper
import (
"cosmossdk.io/math"

Check failure on line 4 in x/stakingmiddleware/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "cosmossdk.io/math" is being imported more than once (stylecheck)
"github.com/cometbft/cometbft/libs/log"
"github.com/notional-labs/composable/v6/x/mint/types"
"github.com/notional-labs/composable/v6/x/stakingmiddleware/types"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"

// "github.com/notional-labs/composable/v6/x/mint/types"
sdkmath "cosmossdk.io/math"

Check failure on line 13 in x/stakingmiddleware/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "cosmossdk.io/math" (stylecheck)
)

// Keeper of the staking middleware store
Expand Down Expand Up @@ -99,3 +101,20 @@ func (k Keeper) GetLastTotalPower(ctx sdk.Context) math.Int {

return ip.Int
}

func (k Keeper) SetDelegation(ctx sdk.Context, DelegatorAddress string, ValidatorAddress string, Denom string, Amount sdkmath.Int) {

Check failure on line 105 in x/stakingmiddleware/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

captLocal: `DelegatorAddress' should not be capitalized (gocritic)
delegation := types.Delegation{DelegatorAddress: DelegatorAddress, ValidatorAddress: ValidatorAddress, Amount: sdk.NewCoin(Denom, Amount)}
delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)

store := ctx.KVStore(k.storeKey)
b := k.cdc.MustMarshal(&delegation)
store.Set(types.GetDelegationKey(delegatorAddress, GetValidatorAddr(delegation)), b)
}

func GetValidatorAddr(d types.Delegation) sdk.ValAddress {
addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress)
if err != nil {
panic(err)
}
return addr
}

0 comments on commit 38c7444

Please sign in to comment.