Skip to content

Commit

Permalink
update decode into decodeuint64 (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marketen authored Dec 11, 2024
1 parent 7ac7b2b commit 6eee383
Showing 1 changed file with 2 additions and 15 deletions.
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

0 comments on commit 6eee383

Please sign in to comment.