Skip to content
Open
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 @@ -311,15 +312,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 @@ -424,13 +425,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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we consider what happens when err is not nil?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we can safely assume that transactionRecord.Digest is going to be valid

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can safely assume it is always there. The thing that I want to check is if the core node currently assumes this to be a base64 string when getting events, if that's the case, we need to make a small change in core as well. cc @stackman27

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok let's wait for his input

Copy link
Contributor

@stackman27 stackman27 Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both fields are expected as bytes, i think decoded hex is better

type Head struct {
	Height string
	Hash   []byte
	// Timestamp is in Unix time
	Timestamp uint64
}

type Sequence struct {
	// This way we can retrieve past/future sequences (EVM log events) very granularly, but still hide the chain detail.
	Cursor string
	TxHash []byte
	Head
	Data any
}


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