From 74b839573b5a775686d5eecea8137bad5d818630 Mon Sep 17 00:00:00 2001 From: Thomas van Dam Date: Thu, 28 Nov 2024 15:14:11 +0100 Subject: [PATCH] chore(plugin): update batch tree entry messages Part-of: #423 --- plugins/indexing/batching/module.go | 42 +++++++++++++++++++--- proto/sedachain/batching/v1/batching.proto | 3 +- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/plugins/indexing/batching/module.go b/plugins/indexing/batching/module.go index b9fa86fe..fdbc513b 100644 --- a/plugins/indexing/batching/module.go +++ b/plugins/indexing/batching/module.go @@ -6,6 +6,7 @@ import ( "strconv" "time" + // "cosmossdk.io/collections" "cosmossdk.io/collections" storetypes "cosmossdk.io/store/types" @@ -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 diff --git a/proto/sedachain/batching/v1/batching.proto b/proto/sedachain/batching/v1/batching.proto index 70f9003b..dfaf0a4e 100644 --- a/proto/sedachain/batching/v1/batching.proto +++ b/proto/sedachain/batching/v1/batching.proto @@ -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" ];