github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/builder/collection/tx_lookup.go (about)

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