Skip to content

Commit

Permalink
emit dlc events
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jan 12, 2025
1 parent 24fdb8f commit c268fcb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
8 changes: 4 additions & 4 deletions x/dlc/keeper/agency.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ 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,
Time: ctx.BlockTime(),
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
Expand Down
27 changes: 25 additions & 2 deletions x/dlc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions x/dlc/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ 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,
Time: ctx.BlockTime(),
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
Expand Down
12 changes: 12 additions & 0 deletions x/dlc/types/events.go
Original file line number Diff line number Diff line change
@@ -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"
)

0 comments on commit c268fcb

Please # to comment.