github.com/lbryio/lbcd@v0.22.119/claimtrie/merkletrie/vertex.go (about)

     1  package merkletrie
     2  
     3  import (
     4  	"github.com/lbryio/lbcd/chaincfg/chainhash"
     5  )
     6  
     7  type vertex struct {
     8  	merkleHash *chainhash.Hash
     9  	claimsHash *chainhash.Hash
    10  	childLinks map[byte]*vertex
    11  }
    12  
    13  func newVertex(hash *chainhash.Hash) *vertex {
    14  	return &vertex{childLinks: map[byte]*vertex{}, merkleHash: hash}
    15  }
    16  
    17  // TODO: more professional to use msgpack here?
    18  
    19  // nbuf decodes the on-disk format of a node, which has the following form:
    20  //
    21  //	ch(1B) hash(32B)
    22  //	...
    23  //	ch(1B) hash(32B)
    24  //	vhash(32B)
    25  type nbuf []byte
    26  
    27  func (nb nbuf) entries() int {
    28  	return len(nb) / 33
    29  }
    30  
    31  func (nb nbuf) entry(i int) (byte, *chainhash.Hash) {
    32  	h := chainhash.Hash{}
    33  	copy(h[:], nb[33*i+1:])
    34  	return nb[33*i], &h
    35  }
    36  
    37  func (nb nbuf) hasValue() (bool, *chainhash.Hash) {
    38  	if len(nb)%33 == 0 {
    39  		return false, nil
    40  	}
    41  	h := chainhash.Hash{}
    42  	copy(h[:], nb[len(nb)-32:])
    43  	return true, &h
    44  }