-
Notifications
You must be signed in to change notification settings - Fork 12
/
msg_server.go
51 lines (39 loc) · 1.21 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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/allinbits/cosmos-cash/x/verifiable-credential/types"
)
type msgServer struct {
Keeper
}
// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}
var _ types.MsgServer = msgServer{}
// CreateVerifiableCredential creates a new verifiable credential
func (k msgServer) CreateVerifiableCredential(
goCtx context.Context,
msg *types.MsgCreateVerifiableCredential,
) (*types.MsgCreateVerifiableCredentialResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
_, found := k.Keeper.GetVerifiableCredential(ctx, []byte(msg.VerifiableCredential.Id))
if found {
return nil, sdkerrors.Wrapf(
types.ErrVerifiableCredentialFound,
"vc already exists",
)
}
k.Keeper.SetVerifiableCredential(
ctx,
[]byte(msg.VerifiableCredential.Id),
*msg.VerifiableCredential,
)
ctx.EventManager().EmitEvent(
types.NewCredentialCreatedEvent(msg.Owner, msg.VerifiableCredential.Id),
)
return &types.MsgCreateVerifiableCredentialResponse{}, nil
}