Skip to content

Commit c268fcb

Browse files
committed
emit dlc events
1 parent 24fdb8f commit c268fcb

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

x/dlc/keeper/agency.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import (
1111
)
1212

1313
// CreateAgency initiates the agency creation request
14-
func (k Keeper) CreateAgency(ctx sdk.Context, participants []string, threshold uint32) error {
15-
agency := types.Agency{
14+
func (k Keeper) CreateAgency(ctx sdk.Context, participants []string, threshold uint32) (*types.Agency, error) {
15+
agency := &types.Agency{
1616
Id: k.IncrementAgencyId(ctx),
1717
Participants: participants,
1818
Threshold: threshold,
1919
Time: ctx.BlockTime(),
2020
Status: types.AgencyStatus_Agency_Status_Pending,
2121
}
2222

23-
k.SetAgency(ctx, &agency)
23+
k.SetAgency(ctx, agency)
2424

25-
return nil
25+
return agency, nil
2626
}
2727

2828
// SubmitAgencyPubKey performs the agency public key submission

x/dlc/keeper/msg_server.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper
22

33
import (
44
"context"
5+
"fmt"
56

67
errorsmod "cosmossdk.io/errors"
78
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -82,10 +83,21 @@ func (m msgServer) CreateOracle(goCtx context.Context, msg *types.MsgCreateOracl
8283

8384
ctx := sdk.UnwrapSDKContext(goCtx)
8485

85-
if err := m.Keeper.CreateOracle(ctx, msg.Participants, msg.Threshold); err != nil {
86+
oracle, err := m.Keeper.CreateOracle(ctx, msg.Participants, msg.Threshold)
87+
if err != nil {
8688
return nil, err
8789
}
8890

91+
ctx.EventManager().EmitEvent(
92+
sdk.NewEvent(
93+
types.EventTypeCreateOracle,
94+
sdk.NewAttribute(types.AttributeKeyId, fmt.Sprintf("%d", oracle.Id)),
95+
sdk.NewAttribute(types.AttributeKeyParticipants, fmt.Sprintf("%s", oracle.Participants)),
96+
sdk.NewAttribute(types.AttributeKeyThreshold, fmt.Sprintf("%d", oracle.Threshold)),
97+
sdk.NewAttribute(types.AttributeKeyExpirationTime, oracle.Time.Add(m.GetDKGTimeoutPeriod(ctx)).String()),
98+
),
99+
)
100+
89101
return &types.MsgCreateOracleResponse{}, nil
90102
}
91103

@@ -97,10 +109,21 @@ func (m msgServer) CreateAgency(goCtx context.Context, msg *types.MsgCreateAgenc
97109

98110
ctx := sdk.UnwrapSDKContext(goCtx)
99111

100-
if err := m.Keeper.CreateAgency(ctx, msg.Participants, msg.Threshold); err != nil {
112+
agency, err := m.Keeper.CreateAgency(ctx, msg.Participants, msg.Threshold)
113+
if err != nil {
101114
return nil, err
102115
}
103116

117+
ctx.EventManager().EmitEvent(
118+
sdk.NewEvent(
119+
types.EventTypeCreateAgency,
120+
sdk.NewAttribute(types.AttributeKeyId, fmt.Sprintf("%d", agency.Id)),
121+
sdk.NewAttribute(types.AttributeKeyParticipants, fmt.Sprintf("%s", agency.Participants)),
122+
sdk.NewAttribute(types.AttributeKeyThreshold, fmt.Sprintf("%d", agency.Threshold)),
123+
sdk.NewAttribute(types.AttributeKeyExpirationTime, agency.Time.Add(m.GetDKGTimeoutPeriod(ctx)).String()),
124+
),
125+
)
126+
104127
return &types.MsgCreateAgencyResponse{}, nil
105128
}
106129

x/dlc/keeper/oracle.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import (
1111
)
1212

1313
// CreateOracle initiates the oracle creation request
14-
func (k Keeper) CreateOracle(ctx sdk.Context, participants []string, threshold uint32) error {
15-
oracle := types.DLCOracle{
14+
func (k Keeper) CreateOracle(ctx sdk.Context, participants []string, threshold uint32) (*types.DLCOracle, error) {
15+
oracle := &types.DLCOracle{
1616
Id: k.IncrementOracleId(ctx),
1717
Participants: participants,
1818
Threshold: threshold,
1919
Time: ctx.BlockTime(),
2020
Status: types.DLCOracleStatus_Oracle_Status_Pending,
2121
}
2222

23-
k.SetOracle(ctx, &oracle)
23+
k.SetOracle(ctx, oracle)
2424

25-
return nil
25+
return oracle, nil
2626
}
2727

2828
// SubmitOraclePubKey performs the oracle public key submission

x/dlc/types/events.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package types
2+
3+
// DLC module event types
4+
const (
5+
EventTypeCreateOracle = "create_oracle"
6+
EventTypeCreateAgency = "create_agency"
7+
8+
AttributeKeyId = "id"
9+
AttributeKeyParticipants = "participants"
10+
AttributeKeyThreshold = "threshold"
11+
AttributeKeyExpirationTime = "expiration_time"
12+
)

0 commit comments

Comments
 (0)