Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update decode into decodeuint64 #79

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
17 changes: 2 additions & 15 deletions internal/adapters/execution/execution_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package execution

import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -57,24 +56,12 @@ func (e *ExecutionAdapter) GetMostRecentBlockNumber() (uint64, error) {
return 0, fmt.Errorf("failed to decode response from execution client: %w", err)
}

// Convert the hexadecimal block number to uint64 using hexutil.Decode
decodedBytes, err := hexutil.Decode(result.Result)
// Convert the hexadecimal block number to uint64 using hexutil.DecodeUint64
blockNumber, err := hexutil.DecodeUint64(result.Result)
if err != nil {
return 0, fmt.Errorf("failed to decode block number from result %s: %w", result.Result, err)
}

// Ensure the decoded byte slice does not exceed 8 bytes for uint64
if len(decodedBytes) > 8 {
return 0, fmt.Errorf("block number too large to fit in uint64: length %d bytes", len(decodedBytes))
}

// Convert the byte slice to uint64
var blockNumber uint64
// If the byte slice is less than 8 bytes, pad it with leading zeros
paddedBytes := make([]byte, 8)
copy(paddedBytes[8-len(decodedBytes):], decodedBytes)
blockNumber = binary.BigEndian.Uint64(paddedBytes)

return blockNumber, nil
}

Expand Down
Loading