-
Notifications
You must be signed in to change notification settings - Fork 175
/
tx_lookup.go
42 lines (35 loc) · 1.44 KB
/
tx_lookup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package collection
import "github.com/onflow/flow-go/model/flow"
// transactionLookup encapsulates state and logic for checking chain history
// to avoid transaction duplication while building collections.
type transactionLookup struct {
// set of transaction IDs in finalized ancestry
finalized map[flow.Identifier]struct{}
// set of transaction IDs in unfinalized ancestry
unfinalized map[flow.Identifier]struct{}
}
func newTransactionLookup() *transactionLookup {
lookup := &transactionLookup{
finalized: make(map[flow.Identifier]struct{}),
unfinalized: make(map[flow.Identifier]struct{}),
}
return lookup
}
// note the existence of a transaction in a finalized noteAncestor collection
func (lookup *transactionLookup) addFinalizedAncestor(txID flow.Identifier) {
lookup.finalized[txID] = struct{}{}
}
// note the existence of a transaction in a unfinalized noteAncestor collection
func (lookup *transactionLookup) addUnfinalizedAncestor(txID flow.Identifier) {
lookup.unfinalized[txID] = struct{}{}
}
// checks whether the given transaction ID is in a finalized noteAncestor collection
func (lookup *transactionLookup) isFinalizedAncestor(txID flow.Identifier) bool {
_, exists := lookup.finalized[txID]
return exists
}
// checks whether the given transaction ID is in a unfinalized noteAncestor collection
func (lookup *transactionLookup) isUnfinalizedAncestor(txID flow.Identifier) bool {
_, exists := lookup.unfinalized[txID]
return exists
}