Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions relayer/chainreader/indexer/events_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"context"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -331,15 +332,29 @@ eventLoop:
// normalize the data, convert snake case to camel case
normalizedData := convertMapKeysToCamelCase(event.ParsedJson)

// Convert the txDigest to hex
txDigestHex := event.Id.TxDigest
if base64Bytes, err := base64.StdEncoding.DecodeString(txDigestHex); err == nil {
hexTxId := hex.EncodeToString(base64Bytes)
txDigestHex = "0x" + hexTxId
}

blockHashBytes, err := base64.StdEncoding.DecodeString(block.TxDigest)
if err != nil {
eIndexer.logger.Errorw("Failed to decode block hash", "error", err)
// fallback
blockHashBytes = []byte(block.TxDigest)
}

// Convert event to database record
record := database.EventRecord{
EventAccountAddress: selector.Package,
EventHandle: eventHandle,
EventOffset: offset,
TxDigest: event.Id.TxDigest,
TxDigest: txDigestHex,
BlockVersion: 0,
BlockHeight: fmt.Sprintf("%d", block.Height),
BlockHash: []byte(block.TxDigest),
BlockHash: blockHashBytes,
// Sui returns block.Timestamp in ms; convert to seconds for consistency with CCIP readers.
BlockTimestamp: block.Timestamp / 1000,
Data: normalizedData.(map[string]any),
Expand Down
19 changes: 17 additions & 2 deletions relayer/chainreader/indexer/transactions_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"context"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -440,13 +441,27 @@ func (tIndexer *TransactionsIndexer) syncTransmitterTransactions(ctx context.Con
continue
}

// Convert the txDigest to hex
txDigestHex := transactionRecord.Digest
if base64Bytes, err := base64.StdEncoding.DecodeString(txDigestHex); err == nil {
hexTxId := hex.EncodeToString(base64Bytes)
txDigestHex = "0x" + hexTxId
}

blockHashBytes, err := base64.StdEncoding.DecodeString(checkpointResponse.Digest)
if err != nil {
tIndexer.logger.Errorw("Failed to decode block hash", "error", err)
// fallback
blockHashBytes = []byte(checkpointResponse.Digest)
}

record := database.EventRecord{
EventAccountAddress: eventAccountAddress,
EventHandle: eventHandle,
EventOffset: 0,
TxDigest: transactionRecord.Digest,
TxDigest: txDigestHex,
BlockHeight: checkpointResponse.SequenceNumber,
BlockHash: []byte(checkpointResponse.Digest),
BlockHash: blockHashBytes,
BlockTimestamp: blockTimestamp,
Data: executionStateChanged,
}
Expand Down
Loading