2024-02-15 07:08:32 +00:00
package keeper
2024-02-16 06:40:42 +00:00
import (
"context"
2024-02-15 07:08:32 +00:00
2024-09-02 04:13:08 +00:00
errorsmod "cosmossdk.io/errors"
2024-02-16 06:40:42 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
2024-09-02 04:13:08 +00:00
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
2024-02-16 06:40:42 +00:00
2024-06-25 06:33:41 +00:00
"git.vdb.to/cerc-io/laconicd/utils"
2024-04-01 09:57:26 +00:00
registrytypes "git.vdb.to/cerc-io/laconicd/x/registry"
2024-02-16 06:40:42 +00:00
)
var _ registrytypes . MsgServer = msgServer { }
2024-02-15 07:08:32 +00:00
type msgServer struct {
k Keeper
}
2024-02-16 06:40:42 +00:00
// 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 ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
_ , 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 ) ,
) ,
} )
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "SetRecord" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgSetRecordResponse { Id : record . Id } , nil
}
// nolint: all
func ( ms msgServer ) SetName ( c context . Context , msg * registrytypes . MsgSetName ) ( * registrytypes . MsgSetNameResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 05:42:36 +00:00
err = ms . k . SetName ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
ctx . EventManager ( ) . EmitEvents ( sdk . Events {
sdk . NewEvent (
registrytypes . EventTypeSetRecord ,
sdk . NewAttribute ( registrytypes . AttributeKeySigner , msg . Signer ) ,
2024-02-28 04:53:23 +00:00
sdk . NewAttribute ( registrytypes . AttributeKeyLRN , msg . Lrn ) ,
2024-02-16 06:40:42 +00:00
sdk . NewAttribute ( registrytypes . AttributeKeyCID , msg . Cid ) ,
) ,
sdk . NewEvent (
sdk . EventTypeMessage ,
sdk . NewAttribute ( sdk . AttributeKeyModule , registrytypes . AttributeValueCategory ) ,
sdk . NewAttribute ( registrytypes . AttributeKeySigner , msg . Signer ) ,
) ,
} )
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "SetName" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgSetNameResponse { } , nil
}
2024-03-07 11:25:15 +00:00
func ( ms msgServer ) ReserveAuthority ( c context . Context , msg * registrytypes . MsgReserveAuthority ) ( * registrytypes . MsgReserveAuthorityResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
_ , err = sdk . AccAddressFromBech32 ( msg . Owner )
if err != nil {
return nil , err
}
2024-02-26 05:42:36 +00:00
err = ms . k . ReserveAuthority ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
ctx . EventManager ( ) . EmitEvents ( sdk . Events {
sdk . NewEvent (
2024-03-07 11:25:15 +00:00
registrytypes . EventTypeReserveAuthority ,
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "ReserveAuthority" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgReserveAuthorityResponse { } , nil
}
// nolint: all
func ( ms msgServer ) SetAuthorityBond ( c context . Context , msg * registrytypes . MsgSetAuthorityBond ) ( * registrytypes . MsgSetAuthorityBondResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-26 05:42:36 +00:00
err = ms . k . SetAuthorityBond ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-02-26 12:56:11 +00:00
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "SetAuthorityBond" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgSetAuthorityBondResponse { } , nil
}
2024-03-07 11:25:15 +00:00
func ( ms msgServer ) DeleteName ( c context . Context , msg * registrytypes . MsgDeleteName ) ( * registrytypes . MsgDeleteNameResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-26 05:42:36 +00:00
err = ms . k . DeleteName ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 05:42:36 +00:00
2024-02-16 06:40:42 +00:00
ctx . EventManager ( ) . EmitEvents ( sdk . Events {
sdk . NewEvent (
registrytypes . EventTypeDeleteName ,
sdk . NewAttribute ( registrytypes . AttributeKeySigner , msg . Signer ) ,
2024-02-28 04:53:23 +00:00
sdk . NewAttribute ( registrytypes . AttributeKeyLRN , msg . Lrn ) ,
2024-02-16 06:40:42 +00:00
) ,
sdk . NewEvent (
sdk . EventTypeMessage ,
sdk . NewAttribute ( sdk . AttributeKeyModule , registrytypes . AttributeValueCategory ) ,
sdk . NewAttribute ( registrytypes . AttributeKeySigner , msg . Signer ) ,
) ,
} )
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "DeleteName" )
2024-03-07 11:25:15 +00:00
return & registrytypes . MsgDeleteNameResponse { } , nil
2024-02-16 06:40:42 +00:00
}
func ( ms msgServer ) RenewRecord ( c context . Context , msg * registrytypes . MsgRenewRecord ) ( * registrytypes . MsgRenewRecordResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 06:16:09 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 06:16:09 +00:00
err = ms . k . RenewRecord ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 06:16:09 +00:00
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "RenewRecord" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgRenewRecordResponse { } , nil
}
// nolint: all
func ( ms msgServer ) AssociateBond ( c context . Context , msg * registrytypes . MsgAssociateBond ) ( * registrytypes . MsgAssociateBondResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
err = ms . k . AssociateBond ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-02-26 12:56:11 +00:00
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "AssociateBond" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgAssociateBondResponse { } , nil
}
func ( ms msgServer ) DissociateBond ( c context . Context , msg * registrytypes . MsgDissociateBond ) ( * registrytypes . MsgDissociateBondResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
err = ms . k . DissociateBond ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-02-26 12:56:11 +00:00
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "DissociateBond" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgDissociateBondResponse { } , nil
}
2024-07-11 05:16:31 +00:00
func ( ms msgServer ) DissociateRecords (
c context . Context ,
msg * registrytypes . MsgDissociateRecords ,
) ( * registrytypes . MsgDissociateRecordsResponse , error ) {
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
err = ms . k . DissociateRecords ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-02-26 12:56:11 +00:00
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "DissociateRecords" )
2024-02-16 06:40:42 +00:00
return & registrytypes . MsgDissociateRecordsResponse { } , nil
}
2024-02-26 12:56:11 +00:00
func ( ms msgServer ) ReassociateRecords ( c context . Context , msg * registrytypes . MsgReassociateRecords ) ( * registrytypes . MsgReassociateRecordsResponse , error ) { //nolint: all
2024-03-06 09:24:15 +00:00
if err := msg . ValidateBasic ( ) ; err != nil {
return nil , err
}
2024-02-16 06:40:42 +00:00
ctx := sdk . UnwrapSDKContext ( c )
2024-06-25 06:33:41 +00:00
ctx = * utils . CtxWithCustomKVGasConfig ( & ctx )
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
_ , err := sdk . AccAddressFromBech32 ( msg . Signer )
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
err = ms . k . ReassociateRecords ( ctx , * msg )
2024-02-16 06:40:42 +00:00
if err != nil {
return nil , err
}
2024-02-26 12:56:11 +00:00
2024-02-16 06:40:42 +00:00
ctx . EventManager ( ) . EmitEvents ( sdk . Events {
sdk . NewEvent (
2024-02-26 12:56:11 +00:00
registrytypes . EventTypeReassociateRecords ,
2024-02-16 06:40:42 +00:00
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 ) ,
) ,
} )
2024-02-26 12:56:11 +00:00
2024-06-25 06:33:41 +00:00
utils . LogTxGasConsumed ( ctx , ms . k . Logger ( ctx ) , "ReassociateRecords" )
2024-02-26 12:56:11 +00:00
return & registrytypes . MsgReassociateRecordsResponse { } , nil
2024-02-16 06:40:42 +00:00
}
2024-09-02 04:13:08 +00:00
// 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 & registrytypes . MsgUpdateParamsResponse { } , nil
}