github.com/lbryio/lbcd@v0.22.119/claimtrie/node/hashfork_manager.go (about)

     1  package node
     2  
     3  import (
     4  	"github.com/lbryio/lbcd/chaincfg/chainhash"
     5  	"github.com/lbryio/lbcd/claimtrie/param"
     6  )
     7  
     8  type HashV2Manager struct {
     9  	Manager
    10  }
    11  
    12  func (nm *HashV2Manager) computeClaimHashes(name []byte) (*chainhash.Hash, int32) {
    13  
    14  	n, err := nm.NodeAt(nm.Height(), name)
    15  	if err != nil || n == nil {
    16  		return nil, 0
    17  	}
    18  
    19  	n.SortClaimsByBid()
    20  	claimHashes := make([]*chainhash.Hash, 0, len(n.Claims))
    21  	for _, c := range n.Claims {
    22  		if c.Status == Activated { // TODO: unit test this line
    23  			claimHashes = append(claimHashes, calculateNodeHash(c.OutPoint, n.TakenOverAt))
    24  		}
    25  	}
    26  	if len(claimHashes) > 0 {
    27  		return ComputeMerkleRoot(claimHashes), n.NextUpdate()
    28  	}
    29  	return nil, n.NextUpdate()
    30  }
    31  
    32  func (nm *HashV2Manager) Hash(name []byte) (*chainhash.Hash, int32) {
    33  
    34  	if nm.Height() >= param.ActiveParams.AllClaimsInMerkleForkHeight {
    35  		return nm.computeClaimHashes(name)
    36  	}
    37  
    38  	return nm.Manager.Hash(name)
    39  }