2016-01-07 00:03:17 +03:00
|
|
|
package btcdnotify
|
|
|
|
|
2016-12-25 03:42:13 +03:00
|
|
|
import "github.com/lightningnetwork/lnd/chainntnfs"
|
|
|
|
|
2016-08-04 08:13:10 +03:00
|
|
|
// confEntry represents an entry in the min-confirmation heap. .
|
2016-01-07 00:03:17 +03:00
|
|
|
type confEntry struct {
|
|
|
|
*confirmationsNotification
|
|
|
|
|
2016-12-25 03:42:13 +03:00
|
|
|
initialConfDetails *chainntnfs.TxConfirmation
|
|
|
|
|
2016-01-07 00:03:17 +03:00
|
|
|
triggerHeight uint32
|
|
|
|
}
|
|
|
|
|
2016-08-04 08:13:10 +03:00
|
|
|
// confirmationHeap is a list of confEntries sorted according to nearest
|
|
|
|
// "confirmation" height.Each entry within the min-confirmation heap is sorted
|
|
|
|
// according to the smallest dleta from the current blockheight to the
|
|
|
|
// triggerHeight of the next entry confirmationHeap
|
2016-01-07 00:03:17 +03:00
|
|
|
type confirmationHeap struct {
|
|
|
|
items []*confEntry
|
|
|
|
}
|
|
|
|
|
2016-08-04 08:13:10 +03:00
|
|
|
// newConfirmationHeap returns a new confirmationHeap with zero items.
|
2016-01-07 00:03:17 +03:00
|
|
|
func newConfirmationHeap() *confirmationHeap {
|
|
|
|
var confItems []*confEntry
|
|
|
|
return &confirmationHeap{confItems}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len returns the number of items in the priority queue. It is part of the
|
|
|
|
// heap.Interface implementation.
|
|
|
|
func (c *confirmationHeap) Len() int { return len(c.items) }
|
|
|
|
|
|
|
|
// Less returns whether the item in the priority queue with index i should sort
|
|
|
|
// before the item with index j. It is part of the heap.Interface implementation.
|
|
|
|
func (c *confirmationHeap) Less(i, j int) bool {
|
|
|
|
return c.items[i].triggerHeight < c.items[j].triggerHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap swaps the items at the passed indices in the priority queue. It is
|
|
|
|
// part of the heap.Interface implementation.
|
|
|
|
func (c *confirmationHeap) Swap(i, j int) {
|
|
|
|
c.items[i], c.items[j] = c.items[j], c.items[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push pushes the passed item onto the priority queue. It is part of the
|
|
|
|
// heap.Interface implementation.
|
|
|
|
func (c *confirmationHeap) Push(x interface{}) {
|
|
|
|
c.items = append(c.items, x.(*confEntry))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop removes the highest priority item (according to Less) from the priority
|
|
|
|
// queue and returns it. It is part of the heap.Interface implementation.
|
|
|
|
func (c *confirmationHeap) Pop() interface{} {
|
|
|
|
n := len(c.items)
|
|
|
|
x := c.items[n-1]
|
2016-02-27 03:27:32 +03:00
|
|
|
c.items[n-1] = nil
|
2016-01-07 00:03:17 +03:00
|
|
|
c.items = c.items[0 : n-1]
|
|
|
|
return x
|
|
|
|
}
|