diff options
Diffstat (limited to 'core/types/block.go')
-rw-r--r-- | core/types/block.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/types/block.go b/core/types/block.go index 217ea73..61b6535 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -87,3 +87,18 @@ func (b ByHash) Less(i int, j int) bool { func (b ByHash) Swap(i int, j int) { b[i], b[j] = b[j], b[i] } + +// ByHeight is the helper type for sorting slice of blocks by height. +type ByHeight []*Block + +func (b ByHeight) Len() int { + return len(b) +} + +func (b ByHeight) Less(i int, j int) bool { + return b[i].Height < b[j].Height +} + +func (b ByHeight) Swap(i int, j int) { + b[i], b[j] = b[j], b[i] +} |