public static PartialMerkleTree buildFromLeaves ( NetworkParameters params , byte [ ] includeBits , List < Sha256Hash > allLeafHashes ) { // Calculate height of the tree. int height = 0 ; while ( getTreeWidth ( allLeafHashes . size ( ) , height ) > 1 ) height ++ ; List < Boolean > bitList = new ArrayList <> ( ) ; List < Sha256Hash > hashes = new ArrayList <> ( ) ; traverseAndBuild ( height , 0 , allLeafHashes , includeBits , bitList , hashes ) ; byte [ ] bits = new byte [ ( int ) Math . ceil ( bitList . size ( ) / 8.0 ) ] ; for ( int i = 0 ; i < bitList . size ( ) ; i ++ ) if ( bitList . get ( i ) ) Utils . setBitLE ( bits , i ) ; return new PartialMerkleTree ( params , bits , hashes , allLeafHashes . size ( ) ) ; }
Calculates a PMT given the list of leaf hashes and which leaves need to be included . The relevant interior hashes are calculated and a new PMT returned .