forked from cerc-io/laconicd
a21e9ea387
* Add proto files for onboarding module * Add generated proto bindings * Define onboarding object * Define the participants state in keeper * Update genesis file to initialize and export module state to/from genesis * Add msg to onboard participant * Register command to enroll participant * Add functionality to decode ethereum address from signature * Add comments for messages and fields * Fix lint errors in proto files * Add message validation and events in msg_server * Reuse crypto utils from go-nitro * Sign entire eth_payload object * Use google API for rpc method * Regenerate proto bindings --------- Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"git.vdb.to/cerc-io/laconicd/utils"
|
|
"git.vdb.to/cerc-io/laconicd/x/onboarding"
|
|
)
|
|
|
|
type msgServer struct {
|
|
k Keeper
|
|
}
|
|
|
|
var _ onboarding.MsgServer = msgServer{}
|
|
|
|
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
|
func NewMsgServerImpl(keeper *Keeper) onboarding.MsgServer {
|
|
return &msgServer{k: *keeper}
|
|
}
|
|
|
|
func (ms msgServer) OnboardParticipant(c context.Context, msg *onboarding.MsgOnboardParticipant) (*onboarding.MsgOnboardParticipantResponse, error) {
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
|
|
|
signerAddress, err := sdk.AccAddressFromBech32(msg.Participant)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, err = ms.k.OnboardParticipant(ctx, msg, signerAddress)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvents(sdk.Events{
|
|
sdk.NewEvent(
|
|
onboarding.EventTypeOnboardParticipant,
|
|
sdk.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
|
|
sdk.NewAttribute(onboarding.AttributeKeyEthAddress, msg.EthPayload.Address),
|
|
),
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, onboarding.AttributeValueCategory),
|
|
sdk.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
|
|
),
|
|
})
|
|
|
|
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "OnboardParticipant")
|
|
|
|
return &onboarding.MsgOnboardParticipantResponse{}, nil
|
|
}
|