-
Notifications
You must be signed in to change notification settings - Fork 169
/
msg_server.go
75 lines (56 loc) · 2.35 KB
/
msg_server.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package keeper
import (
"context"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/CosmosContracts/juno/v19/x/clock/types"
)
var _ types.MsgServer = &msgServer{}
// msgServer is a wrapper of Keeper.
type msgServer struct {
Keeper
}
// NewMsgServerImpl returns an implementation of the x/clock MsgServer interface.
func NewMsgServerImpl(k Keeper) types.MsgServer {
return &msgServer{
Keeper: k,
}
}
// RegisterClockContract handles incoming transactions to register clock contracts.
func (k msgServer) RegisterClockContract(goCtx context.Context, req *types.MsgRegisterClockContract) (*types.MsgRegisterClockContractResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// Validate request
if err := req.ValidateBasic(); err != nil {
return nil, err
}
return &types.MsgRegisterClockContractResponse{}, k.RegisterContract(ctx, req.SenderAddress, req.ContractAddress)
}
// UnregisterClockContract handles incoming transactions to unregister clock contracts.
func (k msgServer) UnregisterClockContract(goCtx context.Context, req *types.MsgUnregisterClockContract) (*types.MsgUnregisterClockContractResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// Validate request
if err := req.ValidateBasic(); err != nil {
return nil, err
}
return &types.MsgUnregisterClockContractResponse{}, k.UnregisterContract(ctx, req.SenderAddress, req.ContractAddress)
}
// UnjailClockContract handles incoming transactions to unjail clock contracts.
func (k msgServer) UnjailClockContract(goCtx context.Context, req *types.MsgUnjailClockContract) (*types.MsgUnjailClockContractResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// Validate request
if err := req.ValidateBasic(); err != nil {
return nil, err
}
return &types.MsgUnjailClockContractResponse{}, k.SetJailStatusBySender(ctx, req.SenderAddress, req.ContractAddress, false)
}
func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.authority != req.Authority {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
}
return &types.MsgUpdateParamsResponse{}, nil
}