diff --git a/x/dlc/keeper/agency.go b/x/dlc/keeper/agency.go index b5dfe3fb..e3acff96 100644 --- a/x/dlc/keeper/agency.go +++ b/x/dlc/keeper/agency.go @@ -11,8 +11,8 @@ import ( ) // CreateAgency initiates the agency creation request -func (k Keeper) CreateAgency(ctx sdk.Context, participants []string, threshold uint32) error { - agency := types.Agency{ +func (k Keeper) CreateAgency(ctx sdk.Context, participants []string, threshold uint32) (*types.Agency, error) { + agency := &types.Agency{ Id: k.IncrementAgencyId(ctx), Participants: participants, Threshold: threshold, @@ -20,9 +20,9 @@ func (k Keeper) CreateAgency(ctx sdk.Context, participants []string, threshold u Status: types.AgencyStatus_Agency_Status_Pending, } - k.SetAgency(ctx, &agency) + k.SetAgency(ctx, agency) - return nil + return agency, nil } // SubmitAgencyPubKey performs the agency public key submission diff --git a/x/dlc/keeper/msg_server.go b/x/dlc/keeper/msg_server.go index 5c765c59..e0e68654 100644 --- a/x/dlc/keeper/msg_server.go +++ b/x/dlc/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -82,10 +83,21 @@ func (m msgServer) CreateOracle(goCtx context.Context, msg *types.MsgCreateOracl ctx := sdk.UnwrapSDKContext(goCtx) - if err := m.Keeper.CreateOracle(ctx, msg.Participants, msg.Threshold); err != nil { + oracle, err := m.Keeper.CreateOracle(ctx, msg.Participants, msg.Threshold) + if err != nil { return nil, err } + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeCreateOracle, + sdk.NewAttribute(types.AttributeKeyId, fmt.Sprintf("%d", oracle.Id)), + sdk.NewAttribute(types.AttributeKeyParticipants, fmt.Sprintf("%s", oracle.Participants)), + sdk.NewAttribute(types.AttributeKeyThreshold, fmt.Sprintf("%d", oracle.Threshold)), + sdk.NewAttribute(types.AttributeKeyExpirationTime, oracle.Time.Add(m.GetDKGTimeoutPeriod(ctx)).String()), + ), + ) + return &types.MsgCreateOracleResponse{}, nil } @@ -97,10 +109,21 @@ func (m msgServer) CreateAgency(goCtx context.Context, msg *types.MsgCreateAgenc ctx := sdk.UnwrapSDKContext(goCtx) - if err := m.Keeper.CreateAgency(ctx, msg.Participants, msg.Threshold); err != nil { + agency, err := m.Keeper.CreateAgency(ctx, msg.Participants, msg.Threshold) + if err != nil { return nil, err } + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeCreateAgency, + sdk.NewAttribute(types.AttributeKeyId, fmt.Sprintf("%d", agency.Id)), + sdk.NewAttribute(types.AttributeKeyParticipants, fmt.Sprintf("%s", agency.Participants)), + sdk.NewAttribute(types.AttributeKeyThreshold, fmt.Sprintf("%d", agency.Threshold)), + sdk.NewAttribute(types.AttributeKeyExpirationTime, agency.Time.Add(m.GetDKGTimeoutPeriod(ctx)).String()), + ), + ) + return &types.MsgCreateAgencyResponse{}, nil } diff --git a/x/dlc/keeper/oracle.go b/x/dlc/keeper/oracle.go index ae10b71e..0f0e8515 100644 --- a/x/dlc/keeper/oracle.go +++ b/x/dlc/keeper/oracle.go @@ -11,8 +11,8 @@ import ( ) // CreateOracle initiates the oracle creation request -func (k Keeper) CreateOracle(ctx sdk.Context, participants []string, threshold uint32) error { - oracle := types.DLCOracle{ +func (k Keeper) CreateOracle(ctx sdk.Context, participants []string, threshold uint32) (*types.DLCOracle, error) { + oracle := &types.DLCOracle{ Id: k.IncrementOracleId(ctx), Participants: participants, Threshold: threshold, @@ -20,9 +20,9 @@ func (k Keeper) CreateOracle(ctx sdk.Context, participants []string, threshold u Status: types.DLCOracleStatus_Oracle_Status_Pending, } - k.SetOracle(ctx, &oracle) + k.SetOracle(ctx, oracle) - return nil + return oracle, nil } // SubmitOraclePubKey performs the oracle public key submission diff --git a/x/dlc/types/events.go b/x/dlc/types/events.go new file mode 100644 index 00000000..4b262736 --- /dev/null +++ b/x/dlc/types/events.go @@ -0,0 +1,12 @@ +package types + +// DLC module event types +const ( + EventTypeCreateOracle = "create_oracle" + EventTypeCreateAgency = "create_agency" + + AttributeKeyId = "id" + AttributeKeyParticipants = "participants" + AttributeKeyThreshold = "threshold" + AttributeKeyExpirationTime = "expiration_time" +)