mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
b38cd850df
* Add multiple strategies to params, queries, txs * Check deposit/withdraw strategy if supported by vault * Add note for deposit strategy * Add strategy type to messages * Update swagger docs, ignore ethermint proto linting errors * Update strategy test, move single strategy support to strategytype * Simplify NewStrategyTypeFromString
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
)
|
|
|
|
type msgServer struct {
|
|
keeper Keeper
|
|
}
|
|
|
|
// NewMsgServerImpl returns an implementation of the earn MsgServer interface
|
|
// for the provided Keeper.
|
|
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
|
return &msgServer{keeper: keeper}
|
|
}
|
|
|
|
var _ types.MsgServer = msgServer{}
|
|
|
|
// Deposit handles MsgDeposit messages
|
|
func (m msgServer) Deposit(goCtx context.Context, msg *types.MsgDeposit) (*types.MsgDepositResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
depositor, err := sdk.AccAddressFromBech32(msg.Depositor)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := m.keeper.Deposit(ctx, depositor, msg.Amount, msg.Strategy); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
|
sdk.NewAttribute(sdk.AttributeKeySender, depositor.String()),
|
|
),
|
|
)
|
|
|
|
return &types.MsgDepositResponse{}, nil
|
|
}
|
|
|
|
// Withdraw handles MsgWithdraw messages
|
|
func (m msgServer) Withdraw(goCtx context.Context, msg *types.MsgWithdraw) (*types.MsgWithdrawResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
from, err := sdk.AccAddressFromBech32(msg.From)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := m.keeper.Withdraw(ctx, from, msg.Amount, msg.Strategy); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
|
sdk.NewAttribute(sdk.AttributeKeySender, from.String()),
|
|
),
|
|
)
|
|
|
|
return &types.MsgWithdrawResponse{}, nil
|
|
}
|