github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/txheap/by_end_time.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package txheap 5 6 import ( 7 "time" 8 9 "github.com/MetalBlockchain/metalgo/ids" 10 "github.com/MetalBlockchain/metalgo/utils/heap" 11 "github.com/MetalBlockchain/metalgo/vms/platformvm/txs" 12 ) 13 14 var _ TimedHeap = (*byEndTime)(nil) 15 16 type TimedHeap interface { 17 Heap 18 19 Timestamp() time.Time 20 } 21 22 type byEndTime struct { 23 txHeap 24 } 25 26 func NewByEndTime() TimedHeap { 27 return &byEndTime{ 28 txHeap: txHeap{ 29 heap: heap.NewMap[ids.ID, heapTx](func(a, b heapTx) bool { 30 aTime := a.tx.Unsigned.(txs.Staker).EndTime() 31 bTime := b.tx.Unsigned.(txs.Staker).EndTime() 32 return aTime.Before(bTime) 33 }), 34 }, 35 } 36 } 37 38 func (h *byEndTime) Timestamp() time.Time { 39 return h.Peek().Unsigned.(txs.Staker).EndTime() 40 }