Prathamesh Musale
94ba057807
Some checks failed
Integration Tests / test-integration (push) Successful in 2m42s
E2E Tests / test-e2e (push) Successful in 4m23s
Unit Tests / test-unit (push) Successful in 2m39s
SDK Tests / sdk_tests_nameservice_expiry (push) Successful in 10m14s
SDK Tests / sdk_tests (push) Failing after 11m55s
SDK Tests / sdk_tests_auctions (push) Successful in 15m48s
Part of [Add gov module to laconicd](https://www.notion.so/Add-gov-module-to-laconicd-938c9f5f87634b4fbd7896d3907fb89e) - Add methods to update params for `bond`, `registry` and `auction` modules Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Reviewed-on: #57 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
419 lines
12 KiB
Go
419 lines
12 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
|
|
"git.vdb.to/cerc-io/laconicd/utils"
|
|
registrytypes "git.vdb.to/cerc-io/laconicd/x/registry"
|
|
)
|
|
|
|
var _ registrytypes.MsgServer = msgServer{}
|
|
|
|
type msgServer struct {
|
|
k Keeper
|
|
}
|
|
|
|
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
|
func NewMsgServerImpl(keeper Keeper) registrytypes.MsgServer {
|
|
return &msgServer{k: keeper}
|
|
}
|
|
|
|
func (ms msgServer) SetRecord(c context.Context, msg *registrytypes.MsgSetRecord) (*registrytypes.MsgSetRecordResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
record, err := ms.k.SetRecord(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeSetRecord,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.GetSigner()),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.GetBondId()),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyPayload, msg.Payload.Record.Id),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "SetRecord")
|
|
|
|
return ®istrytypes.MsgSetRecordResponse{Id: record.Id}, nil
|
|
}
|
|
|
|
// nolint: all
|
|
func (ms msgServer) SetName(c context.Context, msg *registrytypes.MsgSetName) (*registrytypes.MsgSetNameResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.SetName(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeSetRecord,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyCID, msg.Cid),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "SetName")
|
|
|
|
return ®istrytypes.MsgSetNameResponse{}, nil
|
|
}
|
|
|
|
func (ms msgServer) ReserveAuthority(c context.Context, msg *registrytypes.MsgReserveAuthority) (*registrytypes.MsgReserveAuthorityResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_, err = sdk.AccAddressFromBech32(msg.Owner)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.ReserveAuthority(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeReserveAuthority,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyOwner, msg.Owner),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "ReserveAuthority")
|
|
|
|
return ®istrytypes.MsgReserveAuthorityResponse{}, nil
|
|
}
|
|
|
|
// nolint: all
|
|
func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSetAuthorityBond) (*registrytypes.MsgSetAuthorityBondResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.SetAuthorityBond(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeAuthorityBond,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "SetAuthorityBond")
|
|
|
|
return ®istrytypes.MsgSetAuthorityBondResponse{}, nil
|
|
}
|
|
|
|
func (ms msgServer) DeleteName(c context.Context, msg *registrytypes.MsgDeleteName) (*registrytypes.MsgDeleteNameResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.DeleteName(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeDeleteName,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "DeleteName")
|
|
|
|
return ®istrytypes.MsgDeleteNameResponse{}, nil
|
|
}
|
|
|
|
func (ms msgServer) RenewRecord(c context.Context, msg *registrytypes.MsgRenewRecord) (*registrytypes.MsgRenewRecordResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.RenewRecord(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeRenewRecord,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "RenewRecord")
|
|
|
|
return ®istrytypes.MsgRenewRecordResponse{}, nil
|
|
}
|
|
|
|
// nolint: all
|
|
func (ms msgServer) AssociateBond(c context.Context, msg *registrytypes.MsgAssociateBond) (*registrytypes.MsgAssociateBondResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.AssociateBond(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeAssociateBond,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "AssociateBond")
|
|
|
|
return ®istrytypes.MsgAssociateBondResponse{}, nil
|
|
}
|
|
|
|
func (ms msgServer) DissociateBond(c context.Context, msg *registrytypes.MsgDissociateBond) (*registrytypes.MsgDissociateBondResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.DissociateBond(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeDissociateBond,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "DissociateBond")
|
|
|
|
return ®istrytypes.MsgDissociateBondResponse{}, nil
|
|
}
|
|
|
|
func (ms msgServer) DissociateRecords(
|
|
c context.Context,
|
|
msg *registrytypes.MsgDissociateRecords,
|
|
) (*registrytypes.MsgDissociateRecordsResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.DissociateRecords(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeDissociateRecords,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "DissociateRecords")
|
|
|
|
return ®istrytypes.MsgDissociateRecordsResponse{}, nil
|
|
}
|
|
|
|
func (ms msgServer) ReassociateRecords(c context.Context, msg *registrytypes.MsgReassociateRecords) (*registrytypes.MsgReassociateRecordsResponse, error) { //nolint: all
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
_, err := sdk.AccAddressFromBech32(msg.Signer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ms.k.ReassociateRecords(ctx, *msg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
registrytypes.EventTypeReassociateRecords,
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyOldBondId, msg.OldBondId),
|
|
sdk.NewAttribute(registrytypes.AttributeKeyNewBondId, msg.NewBondId),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
|
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "ReassociateRecords")
|
|
|
|
return ®istrytypes.MsgReassociateRecordsResponse{}, nil
|
|
}
|
|
|
|
// UpdateParams defines a method to perform updation of module params.
|
|
func (ms msgServer) UpdateParams(c context.Context, msg *registrytypes.MsgUpdateParams) (*registrytypes.MsgUpdateParamsResponse, error) {
|
|
if ms.k.authority != msg.Authority {
|
|
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
|
|
}
|
|
|
|
if err := msg.Params.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
if err := ms.k.SetParams(ctx, msg.Params); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ®istrytypes.MsgUpdateParamsResponse{}, nil
|
|
}
|