Skip to content

Commit

Permalink
chore(plugin): update batch tree entry messages
Browse files Browse the repository at this point in the history
Part-of: #423
  • Loading branch information
Thomasvdam committed Nov 28, 2024
1 parent 55956f0 commit 74b8395
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
42 changes: 37 additions & 5 deletions plugins/indexing/batching/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"time"

// "cosmossdk.io/collections"
"cosmossdk.io/collections"
storetypes "cosmossdk.io/store/types"

Expand Down Expand Up @@ -103,23 +104,54 @@ func ExtractUpdate(ctx *types.BlockContext, cdc codec.Codec, logger *log.Logger,
}

return types.NewMessage("dr-batch-assignment", data, ctx), nil
} else if keyBytes, found := bytes.CutPrefix(change.Key, batchingtypes.BatchSignaturesKeyPrefix); found {
_, key, err := collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey).Decode(keyBytes)
if err != nil {
return nil, err
}

val, err := codec.CollValue[batchingtypes.BatchSignatures](cdc).Decode(change.Value)
if err != nil {
return nil, err
}

data := struct {
BatchNumber string `json:"batch_number"`
ValidatorAddress string `json:"validator_address"`
Secp256K1Signature string `json:"secpk256k1_signature"`
}{
BatchNumber: strconv.FormatUint(key.K1(), 10),
ValidatorAddress: val.ValidatorAddress.String(),
Secp256K1Signature: hex.EncodeToString(val.Secp256K1Signature),
}

return types.NewMessage("batch-signatures", data, ctx), nil
} else if keyBytes, found := bytes.CutPrefix(change.Key, batchingtypes.ValidatorTreeEntriesKeyPrefix); found {
_, key, err := collections.Uint64Key.Decode(keyBytes)
_, key, err := collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey).Decode(keyBytes)
if err != nil {
return nil, err
}

// The second part of the key is empty for data result entries, we index those separately.
if len(key.K2()) == 0 {
return nil, nil
}

valEntry, err := codec.CollValue[batchingtypes.ValidatorTreeEntry](cdc).Decode(change.Value)
if err != nil {
return nil, err
}

data := struct {
BatchNumber string `json:"batch_number"`
ValidatorTreeEntry batchingtypes.ValidatorTreeEntry `json:"validator_tree_entry"`
BatchNumber string `json:"batch_number"`
ValidatorAddress string `json:"validator_address"`
VotingPowerPercent uint32 `json:"voting_power_percent"`
EthAddress string `json:"eth_address"`
}{
BatchNumber: strconv.FormatUint(key, 10),
ValidatorTreeEntry: valEntry,
BatchNumber: strconv.FormatUint(key.K1(), 10),
ValidatorAddress: valEntry.ValidatorAddress.String(),
VotingPowerPercent: valEntry.VotingPowerPercent,
EthAddress: hex.EncodeToString(valEntry.EthAddress),
}

return types.NewMessage("batch-validator-entry", data, ctx), nil
Expand Down
3 changes: 2 additions & 1 deletion proto/sedachain/batching/v1/batching.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ message DataResult {
string version = 4 [ (gogoproto.jsontag) = "version" ];
// block_height is the height at which the data request was tallied.
uint64 block_height = 5 [ (gogoproto.jsontag) = "block_height" ];
// block_timestamp is the unix timestamp in seconds of when the data request was tallied.
// block_timestamp is the unix timestamp in seconds of when the data request
// was tallied.
uint64 block_timestamp = 6 [ (gogoproto.jsontag) = "block_timestamp" ];
// exit_code is the exit code of the tally wasm binary execution.
uint32 exit_code = 7 [ (gogoproto.jsontag) = "exit_code" ];
Expand Down

0 comments on commit 74b8395

Please sign in to comment.