Skip to content

Commit

Permalink
feat(plugin): publish validator-pubkey events
Browse files Browse the repository at this point in the history
Closes: #402
  • Loading branch information
Thomasvdam committed Nov 14, 2024
1 parent 8c097d0 commit ad87014
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/indexing/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/sedaprotocol/seda-chain/plugins/indexing/log"
oracleprogram "github.com/sedaprotocol/seda-chain/plugins/indexing/oracle-program"
"github.com/sedaprotocol/seda-chain/plugins/indexing/pluginaws"
"github.com/sedaprotocol/seda-chain/plugins/indexing/pubkey"
"github.com/sedaprotocol/seda-chain/plugins/indexing/types"
)

Expand Down Expand Up @@ -93,6 +94,8 @@ func (p *IndexerPlugin) extractUpdate(change *storetypes.StoreKVPair) (*types.Me
// Enable when indexer supports these messages
// case staking.StoreKey:
// return staking.ExtractUpdate(p.block, p.cdc, p.logger, change)
case pubkey.StoreKey:
return pubkey.ExtractUpdate(p.block, p.cdc, p.logger, change)
case dataproxy.StoreKey:
return dataproxy.ExtractUpdate(p.block, p.cdc, p.logger, change)
case batching.StoreKey:
Expand Down
55 changes: 55 additions & 0 deletions plugins/indexing/pubkey/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package pubkey

import (
"bytes"
"encoding/hex"

"cosmossdk.io/collections"
storetypes "cosmossdk.io/store/types"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"

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

"github.com/sedaprotocol/seda-chain/plugins/indexing/log"
"github.com/sedaprotocol/seda-chain/plugins/indexing/types"
pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types"
)

const StoreKey = pubkeytypes.StoreKey

var validatorAddressCodec = authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())

func ExtractUpdate(ctx *types.BlockContext, _ codec.Codec, logger *log.Logger, change *storetypes.StoreKVPair) (*types.Message, error) {
if keyBytes, found := bytes.CutPrefix(change.Key, pubkeytypes.PubKeysPrefix); found {
_, key, err := collections.PairKeyCodec(collections.BytesKey, collections.Uint32Key).Decode(keyBytes)
if err != nil {
return nil, err
}

validatorAddr, err := validatorAddressCodec.BytesToString(key.K1())
if err != nil {
return nil, err
}

pubKey, err := collections.BytesValue.Decode(change.Value)
if err != nil {
return nil, err
}

data := struct {
ValidatorAddress string `json:"validator_address"`
PubKey string `json:"pub_key"`
Index uint32 `json:"index"`
}{
ValidatorAddress: validatorAddr,
PubKey: hex.EncodeToString(pubKey),
Index: key.K2(),
}

return types.NewMessage("validator-pubkey", data, ctx), nil
}

logger.Trace("skipping change", "change", change)
return nil, nil
}

0 comments on commit ad87014

Please sign in to comment.