/
msg_server_chain_link.go
52 lines (40 loc) · 1.72 KB
/
msg_server_chain_link.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
package keeper
import (
"context"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/v2/x/profiles/types"
)
func (k msgServer) LinkChainAccount(goCtx context.Context, msg *types.MsgLinkChainAccount) (*types.MsgLinkChainAccountResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
srcAddrData, err := types.UnpackAddressData(k.cdc, msg.ChainAddress)
if err != nil {
return nil, err
}
link := types.NewChainLink(msg.Signer, srcAddrData, msg.Proof, msg.ChainConfig, ctx.BlockTime())
err = k.SaveChainLink(ctx, link)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeLinkChainAccount,
sdk.NewAttribute(types.AttributeChainLinkSourceAddress, srcAddrData.GetValue()),
sdk.NewAttribute(types.AttributeChainLinkSourceChainName, msg.ChainConfig.Name),
sdk.NewAttribute(types.AttributeChainLinkDestinationAddress, msg.Signer),
sdk.NewAttribute(types.AttributeChainLinkCreationTime, link.CreationTime.Format(time.RFC3339Nano)),
))
return &types.MsgLinkChainAccountResponse{}, nil
}
func (k msgServer) UnlinkChainAccount(goCtx context.Context, msg *types.MsgUnlinkChainAccount) (*types.MsgUnlinkChainAccountResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.DeleteChainLink(ctx, msg.Owner, msg.ChainName, msg.Target); err != nil {
return &types.MsgUnlinkChainAccountResponse{}, err
}
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeUnlinkChainAccount,
sdk.NewAttribute(types.AttributeChainLinkSourceAddress, msg.Target),
sdk.NewAttribute(types.AttributeChainLinkSourceChainName, msg.ChainName),
sdk.NewAttribute(types.AttributeChainLinkDestinationAddress, msg.Owner),
))
return &types.MsgUnlinkChainAccountResponse{}, nil
}