Files
prysm/encoding/ssz/query/ssz_object.go
Jun Song 5a897dfa6b SSZ-QL: Add endpoints (BeaconState/BeaconBlock) (#15888)
* Move ssz_query objects into testing folder (ensuring test objects only used in test environment)

* Add containers for response

* Export sszInfo

* Add QueryBeaconState/Block

* Add comments and few refactor

* Fix merge conflict issues

* Return 500 when calculate offset fails

* Add test for QueryBeaconState

* Add test for QueryBeaconBlock

* Changelog :)

* Rename `QuerySSZRequest` to `SSZQueryRequest`

* Fix middleware hooks for RPC to accept JSON from client and return SSZ

* Convert to `SSZObject` directly from proto

* Move marshalling/calculating hash tree root part after `CalculateOffsetAndLength`

* Make nogo happy

* Add informing comment for using proto unsafe conversion

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2025-10-20 16:24:06 +00:00

24 lines
609 B
Go

package query
import "errors"
type SSZObject interface {
HashTreeRoot() ([32]byte, error)
SizeSSZ() int
}
// HashTreeRoot calls the HashTreeRoot method on the stored interface if it implements SSZObject.
// Returns the 32-byte hash tree root or an error if the interface doesn't support hashing.
func (info *SszInfo) HashTreeRoot() ([32]byte, error) {
if info == nil {
return [32]byte{}, errors.New("SszInfo is nil")
}
if info.source == nil {
return [32]byte{}, errors.New("SszInfo.source is nil")
}
// Check if the value implements the Hashable interface
return info.source.HashTreeRoot()
}