2022-04-05 07:09:27 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-20 07:37:38 +00:00
|
|
|
|
2022-12-09 04:17:14 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/registry/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type msgServer struct {
|
|
|
|
Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMsgServerImpl returns an implementation of the bond MsgServer interface for the provided Keeper.
|
|
|
|
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
|
|
|
return &msgServer{Keeper: keeper}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.MsgServer = msgServer{}
|
|
|
|
|
|
|
|
func (m msgServer) SetRecord(c context.Context, msg *types.MsgSetRecord) (*types.MsgSetRecordResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-01-22 10:27:08 +00:00
|
|
|
record, err := m.Keeper.ProcessSetRecord(ctx, *msg)
|
2022-04-05 07:09:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeSetRecord,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.GetSigner()),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyBondID, msg.GetBondId()),
|
2022-11-15 06:21:14 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyPayload, msg.Payload.Record.Id),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
|
2022-10-17 11:03:31 +00:00
|
|
|
return &types.MsgSetRecordResponse{Id: record.ID}, nil
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (m msgServer) SetName(c context.Context, msg *types.MsgSetName) (*types.MsgSetNameResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessSetName(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeSetRecord,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-04-20 07:37:38 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyCRN, msg.Crn),
|
2022-04-05 07:09:27 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyCID, msg.Cid),
|
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgSetNameResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m msgServer) ReserveName(c context.Context, msg *types.MsgReserveAuthority) (*types.MsgReserveAuthorityResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_, err = sdk.AccAddressFromBech32(msg.Owner)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessReserveAuthority(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeReserveNameAuthority,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyName, msg.Name),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyOwner, msg.Owner),
|
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgReserveAuthorityResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (m msgServer) SetAuthorityBond(c context.Context, msg *types.MsgSetAuthorityBond) (*types.MsgSetAuthorityBondResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessSetAuthorityBond(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeAuthorityBond,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyName, msg.Name),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyBondID, msg.BondId),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgSetAuthorityBondResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m msgServer) DeleteName(c context.Context, msg *types.MsgDeleteNameAuthority) (*types.MsgDeleteNameAuthorityResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessDeleteName(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeDeleteName,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-04-20 07:37:38 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyCRN, msg.Crn),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgDeleteNameAuthorityResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m msgServer) RenewRecord(c context.Context, msg *types.MsgRenewRecord) (*types.MsgRenewRecordResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
2022-10-17 11:03:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
err = m.Keeper.ProcessRenewRecord(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeRenewRecord,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyRecordID, msg.RecordId),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgRenewRecordResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (m msgServer) AssociateBond(c context.Context, msg *types.MsgAssociateBond) (*types.MsgAssociateBondResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = m.Keeper.ProcessAssociateBond(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeAssociateBond,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyRecordID, msg.RecordId),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyBondID, msg.BondId),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgAssociateBondResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m msgServer) DissociateBond(c context.Context, msg *types.MsgDissociateBond) (*types.MsgDissociateBondResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessDissociateBond(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeDissociateBond,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyRecordID, msg.RecordId),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgDissociateBondResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m msgServer) DissociateRecords(c context.Context, msg *types.MsgDissociateRecords) (*types.MsgDissociateRecordsResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessDissociateRecords(ctx, *msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeDissociateRecords,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyBondID, msg.BondId),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgDissociateRecordsResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-17 11:03:31 +00:00
|
|
|
func (m msgServer) ReAssociateRecords(c context.Context, msg *types.MsgReAssociateRecords) (*types.MsgReAssociateRecordsResponse, error) { //nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = m.Keeper.ProcessReAssociateRecords(ctx, *msg)
|
2022-10-17 11:03:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeReAssociateRecords,
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
2022-10-17 11:03:31 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyOldBondID, msg.OldBondId),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyNewBondID, msg.NewBondId),
|
2022-04-05 07:09:27 +00:00
|
|
|
),
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(types.AttributeKeySigner, msg.Signer),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
return &types.MsgReAssociateRecordsResponse{}, nil
|
|
|
|
}
|