Skip to content

Commit

Permalink
chore(data-proxy): emit events on TXs and endblock changes
Browse files Browse the repository at this point in the history
Part-of: #316
  • Loading branch information
Thomasvdam committed Aug 22, 2024
1 parent 146e1be commit c8b5a9a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
9 changes: 8 additions & 1 deletion x/data-proxy/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package keeper

import (
"encoding/hex"

"cosmossdk.io/collections"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sedaprotocol/seda-chain/x/data-proxy/types"
)

func (k *Keeper) EndBlock(ctx sdk.Context) (err error) {
Expand Down Expand Up @@ -48,7 +52,10 @@ func (k *Keeper) ProcessFeeUpdates(ctx sdk.Context) error {
return err
}

// TODO emit events
pubKeyHex := hex.EncodeToString(pubkey)
ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeFeeUpdate,
sdk.NewAttribute(types.AttributePubKey, pubKeyHex),
sdk.NewAttribute(types.AttributeFee, proxyConfig.Fee.String())))
}
return nil
}
30 changes: 30 additions & 0 deletions x/data-proxy/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (m msgServer) RegisterDataProxy(goCtx context.Context, msg *types.MsgRegist
return nil, err
}

emitProxyConfigEvent(ctx, types.EventTypeRegisterProxy, msg.PubKey, &proxyConfig)

return &types.MsgRegisterDataProxyResponse{}, nil
}

Expand Down Expand Up @@ -131,6 +133,8 @@ func (m msgServer) EditDataProxy(goCtx context.Context, msg *types.MsgEditDataPr
return nil, err
}

emitProxyConfigEvent(ctx, types.EventTypeEditProxy, msg.PubKey, &proxyConfig)

return &types.MsgEditDataProxyResponse{}, nil
}

Expand All @@ -156,11 +160,32 @@ func (m msgServer) EditDataProxy(goCtx context.Context, msg *types.MsgEditDataPr
return nil, err
}

emitProxyConfigEvent(ctx, types.EventTypeEditProxy, msg.PubKey, &proxyConfig)

return &types.MsgEditDataProxyResponse{
FeeUpdateHeight: updateHeight,
}, nil
}

func emitProxyConfigEvent(ctx sdk.Context, eventType string, pubKey string, proxyConfig *types.ProxyConfig) {
event := sdk.NewEvent(eventType,
sdk.NewAttribute(types.AttributePubKey, pubKey),
sdk.NewAttribute(types.AttributePayoutAddress, proxyConfig.PayoutAddress),
sdk.NewAttribute(types.AttributeFee, proxyConfig.Fee.String()),
sdk.NewAttribute(types.AttributeMemo, proxyConfig.Memo),
sdk.NewAttribute(types.AttributeAdminAddress, proxyConfig.AdminAddress),
)

if proxyConfig.FeeUpdate != nil {
event.AppendAttributes(
sdk.NewAttribute(types.AttributeNewFee, proxyConfig.FeeUpdate.String()),
sdk.NewAttribute(types.AttributeNewFeeHeight, fmt.Sprintf("%d", proxyConfig.FeeUpdate.UpdateHeight)),
)
}

ctx.EventManager().EmitEvent(event)
}

func (m msgServer) TransferAdmin(goCtx context.Context, msg *types.MsgTransferAdmin) (*types.MsgTransferAdminResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

Expand Down Expand Up @@ -192,6 +217,11 @@ func (m msgServer) TransferAdmin(goCtx context.Context, msg *types.MsgTransferAd
return nil, err
}

ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeTransferAdmin,
sdk.NewAttribute(types.AttributePubKey, msg.PubKey),
sdk.NewAttribute(types.AttributeAdminAddress, proxyConfig.AdminAddress),
))

return &types.MsgTransferAdminResponse{}, nil
}

Expand Down
13 changes: 12 additions & 1 deletion x/data-proxy/types/events.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package types

const (
EventTypeRegisterProxy = "register_proxy"
EventTypeRegisterProxy = "register_data_proxy"
EventTypeEditProxy = "edit_data_proxy"
EventTypeFeeUpdate = "fee_update"
EventTypeTransferAdmin = "transfer_admin"

AttributePubKey = "pub_key"
AttributePayoutAddress = "payout_address"
AttributeFee = "fee"
AttributeMemo = "memo"
AttributeAdminAddress = "admin_address"
AttributeNewFee = "new_fee"
AttributeNewFeeHeight = "new_fee_height"
)

0 comments on commit c8b5a9a

Please sign in to comment.