43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package vo
|
|
|
|
import "fmt"
|
|
|
|
// BlockHeight is a value object representing a blockchain block height (number).
|
|
// Block heights must be non-negative.
|
|
type BlockHeight struct {
|
|
value int64
|
|
}
|
|
|
|
// NewBlockHeight creates a validated BlockHeight value object.
|
|
func NewBlockHeight(height int64) (BlockHeight, error) {
|
|
if height < 0 {
|
|
return BlockHeight{}, fmt.Errorf("block height must be non-negative, got %d", height)
|
|
}
|
|
return BlockHeight{value: height}, nil
|
|
}
|
|
|
|
// Value returns the underlying int64 value.
|
|
func (h BlockHeight) Value() int64 {
|
|
return h.value
|
|
}
|
|
|
|
// IsGenesis reports whether this is the genesis block (height 0).
|
|
func (h BlockHeight) IsGenesis() bool {
|
|
return h.value == 0
|
|
}
|
|
|
|
// Next returns the next block height.
|
|
func (h BlockHeight) Next() BlockHeight {
|
|
return BlockHeight{value: h.value + 1}
|
|
}
|
|
|
|
// String returns the string representation.
|
|
func (h BlockHeight) String() string {
|
|
return fmt.Sprintf("%d", h.value)
|
|
}
|
|
|
|
// IsValid reports whether the block height is valid (non-negative).
|
|
func (h BlockHeight) IsValid() bool {
|
|
return h.value >= 0
|
|
}
|