Skip to content

Commit

Permalink
fix noble decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Jan 24, 2024
1 parent 5ec0776 commit 4c6f4f3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions noble/message_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,26 @@ func txToMessageState(tx *ctypes.ResultTx) ([]*types.MessageState, error) {

var messageStates []*types.MessageState

for i, event := range tx.TxResult.Events {
for _, event := range tx.TxResult.Events {
if event.Type == "circle.cctp.v1.MessageSent" {
//fmt.Printf("Saw cctp message %s - %d:%d\n", tx., i, j)
var parsed bool
var parseErrs error
for _, attr := range event.Attributes {
if attr.Key == "message" {
fmt.Printf("Saw message attribute %s - %d\n", tx.Hash, i)
encoded := attr.Value[1 : len(attr.Value)-1]
rawMessageSentBytes, err := base64.StdEncoding.DecodeString(encoded)
decodedKey, err := base64.StdEncoding.DecodeString(attr.Key)
if err != nil {
parseErrs = errors.Join(parseErrs, fmt.Errorf("failed to decode attribue key: %w", err))
}
if string(decodedKey) == "message" {
// fmt.Printf("Saw message attribute %s - %d\n", tx.Hash, i)
decodedValue, err := base64.StdEncoding.DecodeString(attr.Value)
if err != nil {
parseErrs = errors.Join(parseErrs, fmt.Errorf("error decoding attr.value: %w", err))
continue
}
encoded := decodedValue[1 : len(decodedValue)-1]
// Because we are using cometBFT v0.38, we need to decode the value twice.
rawMessageSentBytes, err := base64.StdEncoding.DecodeString(string(encoded))
if err != nil {
parseErrs = errors.Join(parseErrs, fmt.Errorf("failed to decode message: %w", err))
continue
Expand Down

0 comments on commit 4c6f4f3

Please sign in to comment.