Skip to content

Commit

Permalink
add events for updateOperators
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 15, 2024
1 parent 29f98d9 commit c7e5755
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
12 changes: 9 additions & 3 deletions light-clients/lcp/types/events.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package types

const (
EventTypeRegisteredEnclaveKey = "registered_enclave_key"
EventTypeRegisterEnclaveKey = "register_enclave_key"
AttributeKeyEnclaveKey = "enclave_key"
AttributeKeyExpiredAt = "expired_at"
AttributeKeyOperator = "operator"

AttributeKeyEnclaveKey = "enclave_key"
AttributeExpiredAt = "expired_at"
EventTypeUpdateOperators = "update_operators"
AttributeKeyNonce = "nonce"
AttributeKeyNewOperators = "new_operators"
AttributeKeyThresholdNumerator = "threshold_numerator"
AttributeKeyThresholdDenominator = "threshold_denominator"
)
31 changes: 26 additions & 5 deletions light-clients/lcp/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"bytes"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -213,7 +214,7 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client
case *RegisterEnclaveKeyMessage:
return cs.registerEnclaveKey(ctx, clientStore, clientMsg)
case *UpdateOperatorsMessage:
return cs.updateOperators(cdc, clientStore, clientMsg)
return cs.updateOperators(ctx, cdc, clientStore, clientMsg)
default:
panic(errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "unknown client message %T", clientMsg))
}
Expand Down Expand Up @@ -259,27 +260,47 @@ func (cs ClientState) registerEnclaveKey(ctx sdk.Context, clientStore storetypes
if err := cs.ensureEKInfoMatch(clientStore, ek, operator, expiredAt); err != nil {
panic(err)
}
return nil
} else {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypeRegisteredEnclaveKey,
EventTypeRegisterEnclaveKey,
sdk.NewAttribute(AttributeKeyEnclaveKey, ek.Hex()),
sdk.NewAttribute(AttributeExpiredAt, expiredAt.String()),
sdk.NewAttribute(AttributeKeyExpiredAt, expiredAt.String()),
sdk.NewAttribute(AttributeKeyOperator, operator.Hex()),
),
)
return nil
}
if err := cs.SetEKInfo(clientStore, ek, operator, expiredAt); err != nil {
panic(err)
}
return nil
}

func (cs ClientState) updateOperators(cdc codec.BinaryCodec, clientStore storetypes.KVStore, message *UpdateOperatorsMessage) []exported.Height {
func (cs ClientState) updateOperators(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, message *UpdateOperatorsMessage) []exported.Height {
cs.Operators = message.NewOperators
cs.OperatorsThresholdNumerator = message.NewOperatorsThresholdNumerator
cs.OperatorsThresholdDenominator = message.NewOperatorsThresholdDenominator
cs.OperatorsNonce = message.Nonce
setClientState(clientStore, cdc, &cs)

newOperators, err := message.GetNewOperators()
if err != nil {
panic(err)
}
newOperatorsJSON, err := json.Marshal(newOperators)
if err != nil {
panic(err)
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypeUpdateOperators,
sdk.NewAttribute(AttributeKeyNonce, fmt.Sprint(message.Nonce)),
sdk.NewAttribute(AttributeKeyNewOperators, string(newOperatorsJSON)),
sdk.NewAttribute(AttributeKeyThresholdNumerator, fmt.Sprint(message.NewOperatorsThresholdNumerator)),
sdk.NewAttribute(AttributeKeyThresholdDenominator, fmt.Sprint(message.NewOperatorsThresholdDenominator)),
),
)
return nil
}

Expand Down

0 comments on commit c7e5755

Please sign in to comment.