github.com/dim4egster/coreth@v0.10.2/utils/fork.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package utils
     5  
     6  import "math/big"
     7  
     8  // IsForked returns whether a fork scheduled at block s is active at the given head block.
     9  // Note: [s] and [head] can be either a block number or a block timestamp.
    10  func IsForked(s, head *big.Int) bool {
    11  	if s == nil || head == nil {
    12  		return false
    13  	}
    14  	return s.Cmp(head) <= 0
    15  }
    16  
    17  // IsForkTransition returns true if [fork] activates during the transition from [parent]
    18  // to [current].
    19  // Note: this works for both block number and timestamp activated forks.
    20  func IsForkTransition(fork *big.Int, parent *big.Int, current *big.Int) bool {
    21  	parentForked := IsForked(fork, parent)
    22  	currentForked := IsForked(fork, current)
    23  	return !parentForked && currentForked
    24  }