-
Notifications
You must be signed in to change notification settings - Fork 17
/
msg_server_cancel_bid.go
48 lines (35 loc) · 1.08 KB
/
msg_server_cancel_bid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package keeper
import (
"context"
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/jackalLabs/canine-chain/x/rns/types"
)
func (k Keeper) CancelOneBid(ctx sdk.Context, sender string, name string) error {
name = strings.ToLower(name)
bidder, err := sdk.AccAddressFromBech32(sender)
if err != nil {
return err
}
bid, bidFound := k.GetBids(ctx, fmt.Sprintf("%s%s", sender, name))
if !bidFound {
return sdkerrors.Wrap(sdkerrors.ErrNotFound, "Bid does not exist or has expired.")
}
price, err := sdk.ParseCoinsNormalized(bid.Price)
if err != nil {
return err
}
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, bidder, price)
if err != nil {
return err
}
k.RemoveBids(ctx, fmt.Sprintf("%s%s", sender, name))
return nil
}
func (k msgServer) CancelBid(goCtx context.Context, msg *types.MsgCancelBid) (*types.MsgCancelBidResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
err := k.CancelOneBid(ctx, msg.Creator, msg.Name)
return &types.MsgCancelBidResponse{}, err
}