Skip to content

Commit

Permalink
RNS events (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Oct 3, 2024
2 parents 52cdab2 + 23cacec commit c5c13f8
Show file tree
Hide file tree
Showing 23 changed files with 477 additions and 8 deletions.
8 changes: 8 additions & 0 deletions x/notifications/keeper/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ func (k Keeper) SetBlock(ctx sdk.Context, block types.Block) {
block.Address,
block.BlockedAddress,
), b)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventBlock,
sdk.NewAttribute(types.AttributeBlocker, block.Address),
sdk.NewAttribute(types.AttributeBlockee, block.BlockedAddress),
),
)
}

// IsBlocked returns if a user is blocked
Expand Down
7 changes: 7 additions & 0 deletions x/notifications/keeper/msg_server_block_senders.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ func (k msgServer) BlockSenders(goCtx context.Context, msg *types.MsgBlockSender

}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventBlockSenders,
sdk.NewAttribute(types.AttributeSigner, msg.Creator),
),
)

return &types.MsgBlockSendersResponse{}, nil
}
7 changes: 7 additions & 0 deletions x/notifications/keeper/msg_server_create_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@ func (k msgServer) CreateNotification(goCtx context.Context, msg *types.MsgCreat

k.SetNotification(ctx, noti)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventCreateNotification,
sdk.NewAttribute(types.AttributeSigner, msg.Creator),
),
)

return &types.MsgCreateNotificationResponse{}, nil
}
7 changes: 7 additions & 0 deletions x/notifications/keeper/msg_server_delete_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ func (k msgServer) DeleteNotification(goCtx context.Context, msg *types.MsgDelet

k.RemoveNotification(ctx, msg.Creator, msg.From, msg.Time)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveNotification,
sdk.NewAttribute(types.AttributeSigner, msg.Creator),
),
)

return &types.MsgDeleteNotificationResponse{}, nil
}
18 changes: 18 additions & 0 deletions x/notifications/keeper/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ func (k Keeper) SetNotification(ctx sdk.Context, notification types.Notification
notification.From,
notification.Time,
), b)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventSetNotification,
sdk.NewAttribute(types.AttributeTo, notification.To),
sdk.NewAttribute(types.AttributeFrom, notification.From),
sdk.NewAttribute(types.AttributeWhen, fmt.Sprintf("%d", notification.Time)),
),
)
}

// GetNotification returns a notification from its index
Expand Down Expand Up @@ -55,6 +64,15 @@ func (k Keeper) RemoveNotification(
from,
timeStamp,
))

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveNotification,
sdk.NewAttribute(types.AttributeTo, to),
sdk.NewAttribute(types.AttributeFrom, from),
sdk.NewAttribute(types.AttributeWhen, fmt.Sprintf("%d", timeStamp)),
),
)
}

// GetAllNotifications returns all notifications
Expand Down
17 changes: 17 additions & 0 deletions x/notifications/types/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package types

const (
EventBlockSenders = "block_senders"
EventBlock = "block"
EventRemoveNotification = "notification_removed"
EventCreateNotification = "create_notification"
EventSetNotification = "set_notification"

AttributeBlocker = "blocker"
AttributeBlockee = "blockee"
AttributeTo = "to"
AttributeFrom = "from"
AttributeWhen = "when"

AttributeSigner = "signer"
)
8 changes: 8 additions & 0 deletions x/rns/keeper/bids.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ func (k Keeper) SetBids(ctx sdk.Context, bids types.Bids) {
store.Set(types.BidsKey(
bids.Index,
), b)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventSetBid,
sdk.NewAttribute(types.AttributeName, bids.Name),
sdk.NewAttribute(types.AttributeBidder, bids.Bidder),
),
)
}

// GetBids returns a bids from its index
Expand Down
16 changes: 16 additions & 0 deletions x/rns/keeper/forsale.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func (k Keeper) SetForsale(ctx sdk.Context, forsale types.Forsale) {
store.Set(types.ForsaleKey(
forsale.Name,
), b)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventSetSale,
sdk.NewAttribute(types.AttributeName, forsale.Name),
sdk.NewAttribute(types.AttributeOwner, forsale.Owner),
sdk.NewAttribute(types.AttributePrice, forsale.Price),
),
)
}

// GetForsale returns a forsale from its index
Expand Down Expand Up @@ -42,6 +51,13 @@ func (k Keeper) RemoveForsale(
store.Delete(types.ForsaleKey(
name,
))

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveSale,
sdk.NewAttribute(types.AttributeName, name),
),
)
}

// GetAllForsale returns all forsale
Expand Down
30 changes: 30 additions & 0 deletions x/rns/keeper/msg_server_accept_bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ func (k Keeper) AcceptOneBid(ctx sdk.Context, sender string, name string, bidder
// Write whois information to the store
k.SetNames(ctx, whois)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventAcceptBid,
sdk.NewAttribute(types.AttributeName, fmt.Sprintf("%s.%s", whois.Name, whois.Tld)),
sdk.NewAttribute(types.AttributeBidder, bid.Bidder),
sdk.NewAttribute(types.AttributeOwner, whois.Value),
),
)

return nil
}

Expand All @@ -75,5 +84,26 @@ func (k msgServer) AcceptBid(goCtx context.Context, msg *types.MsgAcceptBid) (*t

err := k.AcceptOneBid(ctx, msg.Creator, msg.Name, msg.From)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventAcceptBid,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return &types.MsgAcceptBidResponse{}, err
}
23 changes: 23 additions & 0 deletions x/rns/keeper/msg_server_add_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,28 @@ func (k msgServer) AddRecord(goCtx context.Context, msg *types.MsgAddRecord) (*t

k.SetNames(ctx, whois)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventAddRecord,
sdk.NewAttribute(types.AttributeName, msg.Name),
sdk.NewAttribute(types.AttributeOwner, msg.Creator),
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

return &types.MsgAddRecordResponse{}, nil
}
21 changes: 21 additions & 0 deletions x/rns/keeper/msg_server_bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,26 @@ func (k msgServer) Bid(goCtx context.Context, msg *types.MsgBid) (*types.MsgBidR

err := k.AddBid(ctx, msg.Creator, msg.Name, msg.Bid.String())

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventSetBid,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return &types.MsgBidResponse{}, err
}
29 changes: 29 additions & 0 deletions x/rns/keeper/msg_server_buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (k Keeper) BuyName(ctx sdk.Context, sender string, nm string) error {
name.Data = "{}"
k.SetNames(ctx, name)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventBuyName,
sdk.NewAttribute(types.AttributeName, nm),
sdk.NewAttribute(types.AttributeOwner, sender),
),
)

return nil
}

Expand All @@ -75,5 +83,26 @@ func (k msgServer) Buy(goCtx context.Context, msg *types.MsgBuy) (*types.MsgBuyR

err := k.BuyName(ctx, msg.Creator, msg.Name)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventBuyName,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return &types.MsgBuyResponse{}, err
}
29 changes: 29 additions & 0 deletions x/rns/keeper/msg_server_cancel_bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func (k Keeper) CancelOneBid(ctx sdk.Context, sender string, name string) error

k.RemoveBids(ctx, fmt.Sprintf("%s%s", sender, name))

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveBid,
sdk.NewAttribute(types.AttributeName, name),
sdk.NewAttribute(types.AttributeOwner, sender),
),
)

return nil
}

Expand All @@ -44,5 +52,26 @@ func (k msgServer) CancelBid(goCtx context.Context, msg *types.MsgCancelBid) (*t

err := k.CancelOneBid(ctx, msg.Creator, msg.Name)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveBid,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return &types.MsgCancelBidResponse{}, err
}
29 changes: 29 additions & 0 deletions x/rns/keeper/msg_server_del_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,34 @@ func (k msgServer) DelRecord(goCtx context.Context, msg *types.MsgDelRecord) (*t
val.Subdomains = dms
k.SetNames(ctx, val)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveRecord,
sdk.NewAttribute(types.AttributeName, msg.Name),
sdk.NewAttribute(types.AttributeOwner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveRecord,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return &types.MsgDelRecordResponse{}, nil
}
21 changes: 21 additions & 0 deletions x/rns/keeper/msg_server_delist.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,26 @@ func (k msgServer) Delist(goCtx context.Context, msg *types.MsgDelist) (*types.M

k.RemoveForsale(ctx, mname)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeJackalMessage,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventRemoveSale,
sdk.NewAttribute(types.AttributeKeySigner, msg.Creator),
),
)

return &types.MsgDelistResponse{}, nil
}
Loading

0 comments on commit c5c13f8

Please sign in to comment.