No way to check if this really an interesting block at this point.
 Might lead to an amplification attack, need to track this proto and
 judge usefulness.
354780
def receive_newblockhashes(proto, newblockhashes)
      logger.debug 'received newblockhashes', num: newblockhashes.size, proto: proto

      newblockhashes = newblockhashes.select {|h| !@chainservice.knows_block(h) }

      known = @protocols.include?(proto)
      if !known || newblockhashes.empty? || @synctask
        logger.debug 'discarding', known: known, synctask: syncing?, num: newblockhashes.size
        return
      end

      if newblockhashes.size != 1
        logger.warn 'supporting only one newblockhash', num: newblockhashes.size
      end
      blockhash = newblockhashes[0]

      logger.debug 'starting synctask for newblockhashes', blockhash: Utils.encode_hex(blockhash)
      @synctask = SyncTask.new self, proto, blockhash, 0, true
    end
1090135
private void checkFullBlock() throws BitcoinBlockReadException {
	// now we can check that we have a full block
		try {
			this.bin.mark(this.maxSizeBitcoinBlock);
			// skip maigc
			long skipMagic=this.bin.skip(4);
			if (skipMagic!=4) {
				 throw new BitcoinBlockReadException("Error: Cannot seek to a block start, because no valid block found. Cannot skip forward magic");
			}
		}
		catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		// read size
		// blocksize
		byte[] blockSizeArray = new byte[4];
		try {
			
			int maxByteRead=4;
			int totalByteRead=0;
			int readByte;
			while ((readByte=this.bin.read(blockSizeArray,totalByteRead,maxByteRead-totalByteRead))>-1) {
					totalByteRead+=readByte;
					if (totalByteRead>=maxByteRead) {
						break;
					}
			}
			if (totalByteRead!=maxByteRead) {
				throw new BitcoinBlockReadException("Error: Cannot seek to a block start, because no valid block found. Cannot read size of block");
			} 
		}
		catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}		
		long blockSize=BitcoinUtil.getSize(blockSizeArray);
		if (this.maxSizeBitcoinBlock<blockSize) {
			throw new BitcoinBlockReadException("Error: Cannot seek to a block start, because no valid block found. Max bitcoin block size is smaller than current block size.");
		}
		int blockSizeInt=(int)blockSize;
		byte[] blockRead=new byte[blockSizeInt];
		int totalByteRead=0;
		int readByte;
		try {
		while ((readByte=this.bin.read(blockRead,totalByteRead,blockSizeInt-totalByteRead))>-1) {
			totalByteRead+=readByte;
			if (totalByteRead>=blockSize) { 
				break;
			}
		}
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		if (totalByteRead!=blockSize) {
			 throw new BitcoinBlockReadException("Error: Cannot seek to a block start, because no valid block found. Cannot skip to end of block");
		}
		try {
			this.bin.reset();
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		// it is a full block
}
586376
private boolean processBlockSignature(ReadBuffer readBuffer) {
        if (this.mapFileHeader.getMapFileInfo().debugFile) {
            // get and check the block signature
            String signatureBlock = readBuffer.readUTF8EncodedString(SIGNATURE_LENGTH_BLOCK);
            if (!signatureBlock.startsWith("###TileStart")) {
                LOGGER.warning("invalid block signature: " + signatureBlock);
                return false;
            }
        }
        return true;
    }
564811
bbBlock findBlockForWrite(Object caller, int version, bbBlock curr, int pos)
    {
        assert mutation_in_progress(caller, version);
        assert (pos >= 0 && "invalid position, positions must be >= 0".length() > 0);
        if (pos > this._buf_limit + 1) {
            throw new BlockedBufferException("writes must be contiguous");
        }
        assert _validate();
        if (curr != null && curr.hasRoomToWrite(pos, 1) == true) {
            if (curr._offset + curr._limit == pos && curr._idx < this._next_block_position) {
                bbBlock b = this._blocks.get(curr._idx + 1);
                if (b.containsForWrite(pos)) {
                    curr = b;
                }
            }
            return curr;
        }
        // we're not going to write into curr, so find out the right block
        bbBlock block;
        if (pos == this._buf_limit) {
            // if we're at the limit the only possible (existing) block
            // will be the very last block - shortcut to optimize append
            assert this._next_block_position > 0;
            block = this._blocks.get(this._next_block_position - 1);
        }
        else if (curr != null && pos == curr._offset + curr._limit) {
            // if our current position is exactly at the end (and we already know
            // we can't write into this block if we can write at all we'll have
            // to write into the next block (inner blocks can't be 0 bytes long)
            block = this._blocks.get(curr._idx + 1);
        }
        else {
            // since we're not at the limit and we don't have a current block
            // we'll go find the block in the list (this is an abnormal case)
            // since append if usual for writing
            block = findBlockHelper(pos, 0, this._next_block_position);
        }
        assert block != null;
        assert block.containsForWrite(pos);
        // chech our candidate block to see if it's the one we'd write into
        if (block.hasRoomToWrite(pos, 1)) {
            return block;
        }
        // at this point, we can't use _curr in any event so we can just
        // move on to the next block since findHelper will have returned
        // either the right block (which it didn't) or the one just in
        // front of the right block - so let's see if there is an allocated
        // block just following this
        if (block._idx < this._next_block_position - 1) {
            block = this._blocks.get(block._idx + 1);
            return block;
        }
        // there wasn't a following block (actually a common case when
        // you're appending) so we have to go ahead an actually add a new block
        int newIdx = block._idx + 1;
        assert newIdx == this._next_block_position;
        bbBlock ret =  this.addBlock(caller
                            ,version
                            ,newIdx
                            ,pos
                            ,this.nextBlockSize(caller, version)
               );
        return ret;
    }
708473
JCBlock block(int pos, long flags) {
        accept(LBRACE);
        List<JCStatement> stats = blockStatements();
        JCBlock t = F.at(pos).Block(flags, stats);
        while (token.kind == CASE || token.kind == DEFAULT) {
            syntaxError("orphaned", token.kind);
            switchBlockStatementGroups();
        }
        // the Block node has a field "endpos" for first char of last token, which is
        // usually but not necessarily the last char of the last token.
        t.endpos = token.pos;
        accept(RBRACE);
        return toP(t);
    }
1149938
function cleanBogus( block ) {
			var bogus = [];
			var last = getLast( block ), node, previous;

			if ( last ) {
				// Check for bogus at the end of this block.
				// e.g. <p>foo<br /></p>
				maybeBogus( last, 1 ) && bogus.push( last );

				while ( last ) {
					// Check for bogus at the end of any pseudo block contained.
					if ( isBlockBoundary( last ) && ( node = getPrevious( last ) ) && maybeBogus( node ) ) {
						// Bogus must have inline proceeding, instead single BR between two blocks,
						// is considered as filler, e.g. <hr /><br /><hr />
						if ( ( previous = getPrevious( node ) ) && !isBlockBoundary( previous ) )
							bogus.push( node );
						// Convert the filler into appropriate form.
						else {
							createFiller( isOutput ).insertAfter( node );
							node.remove();
						}
					}

					last = last.previous;
				}
			}

			// Now remove all bogus collected from above.
			for ( var i = 0 ; i < bogus.length ; i++ )
				bogus[ i ].remove();
		}
45391
function isBlockBlockHashAccess (node) {
  return isSpecialVariableAccess(node, specialVariables.BLOCKHASH) || isBuiltinFunctionCall(node) && getLocalCallName(node) === 'blockhash'
}
719319
int insert(Object caller, int version, bbBlock curr, int pos, int len)
    {
        assert mutation_in_progress(caller, version);
        // DEBUG: int amountMoved = 0;
        // DEBUG: int before = this._buf_limit;
        // DEBUG: assert _validate();
        // if there's room in the current block - just
        // move the "trailing" bytes down and we're done
        int neededSpace = len - curr.unusedBlockCapacity();
        if (neededSpace <= 0) {
            // we have all the space we need in the current block
            // DEBUG: amountMoved =
            insertInCurrOnly(caller, version, curr, pos, len);
        }
        else {
            // we'll need at least some additional space beyond the curr
            // block, see if there's room in the
            // next one, otherwise we'll make more (blocks)
            bbBlock next = null;
            if (curr._idx < this._next_block_position - 1) {
                // if there is another block
                next = this._blocks.get(curr._idx + 1);
            }
            if (next != null &&
                (neededSpace <= next.unusedBlockCapacity())
            ) {
                // with the addition of the free space in the following block we have enough
                // DEBUG: amountMoved =
                insertInCurrAndNext(caller, version, curr, pos, len, next);
            }
            else {
                // we'll have to make one or more new blocks
                // first figure out much will be in the first
                // and last blocks (i.e. ignoring the whole
                // blocks
                int lenNeededInLastAddedBlock = neededSpace % _blockSizeUpperLimit;
                int tailLen = curr.bytesAvailableToRead(pos);
                if (lenNeededInLastAddedBlock < tailLen) lenNeededInLastAddedBlock = tailLen;
                if (lenNeededInLastAddedBlock < neededSpace
                 && neededSpace < this._blockSizeUpperLimit) {
                    // if we need less than the largest block then we should
                    // make *one* block with all of the needed space
                    lenNeededInLastAddedBlock = neededSpace;
                }
                bbBlock newblock = insertMakeNewTailBlock(caller, version, curr, lenNeededInLastAddedBlock);
                // now see if the curr block and this newblock have enough
                // available space to do the job, and if there's some trailing
                // data from curr that will end up staying in curr
                if (len <= (curr.unusedBlockCapacity()
                           + newblock.unusedBlockCapacity())
                ) {
                    // insert this as a zero length block immediately  after _curr
                    // insertBlock also adjusts the trailing blocks idx values
                    insertBlock(newblock);
                    // now pretend we just have the "push into the next block" case
                    // DEBUG: amountMoved =
                    insertInCurrAndNext(caller, version, curr, pos, len, newblock);
                }
                else {
                    // and last we have the case of having to insert more than 1 block
                    // which means all of the trailing bytes in _curr move into the last
                    // block
                    // DEBUG: amountMoved =
                    insertAsManyBlocksAsNeeded(caller, version, curr, pos, len, newblock);
                }
            }
        }
        // DEBUG: if (this._buf_limit - before != len
        // DEBUG: || amountMoved != len) {
        // DEBUG: throw new BlockedBufferException("insert went wrong #1 !!!");
        // DEBUG: }
        assert _validate();
        return len;
    }
293610
function(e) {
    var blockA = this.getInputTargetBlock('A');
    var blockB = this.getInputTargetBlock('B');
    // Disconnect blocks that existed prior to this change if they don't match.
    if (blockA && blockB &&
        !blockA.outputConnection.checkType_(blockB.outputConnection)) {
      // Mismatch between two inputs.  Disconnect previous and bump it away.
      // Ensure that any disconnections are grouped with the causing event.
      Blockly.Events.setGroup(e.group);
      for (var i = 0; i < this.prevBlocks_.length; i++) {
        var block = this.prevBlocks_[i];
        if (block === blockA || block === blockB) {
          block.unplug();
          block.bumpNeighbours_();
        }
      }
      Blockly.Events.setGroup(false);
    }
    this.prevBlocks_[0] = blockA;
    this.prevBlocks_[1] = blockB;
  }
441670
function isIPv6(val) {
  const ipv6Block = /^[0-9A-F]{1,4}$/i;
  var blocks = val.split(':');
  var foundOmissionBlock = false; // marker to indicate ::

  // At least some OS accept the last 32 bits of an IPv6 address
  // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says
  // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses,
  // and '::a.b.c.d' is deprecated, but also valid.
  var foundIPv4TransitionBlock = isIPv4(blocks[blocks.length - 1]);
  var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8;

  if (blocks.length > expectedNumberOfBlocks)
    return false;

  // initial or final ::
  if (val === '::') {
    return true;
  } else if (val.substr(0, 2) === '::') {
    blocks.shift();
    blocks.shift();
    foundOmissionBlock = true;
  } else if (val.substr(val.length - 2) === '::') {
    blocks.pop();
    blocks.pop();
    foundOmissionBlock = true;
  }

  for (var i = 0; i < blocks.length; ++i) {
    // test for a :: which can not be at the string start/end
    // since those cases have been handled above
    if (blocks[i] === '' && i > 0 && i < blocks.length -1) {
      if (foundOmissionBlock)
        return false; // multiple :: in address
      foundOmissionBlock = true;
    } else if (foundIPv4TransitionBlock && i == blocks.length - 1) {
      // it has been checked before that the last
      // block is a valid IPv4 address
    } else if (!ipv6Block.test(blocks[i])) {
      return false;
    }
  }

  if (foundOmissionBlock) {
    return blocks.length >= 1;
  }
  return blocks.length === expectedNumberOfBlocks;
}
845937
def block_is_left_aligned?(ciphertext,redundant_test_blocks)
      total_blocks = ciphertext.length / block_size
      uniq_blocks  = CryptBuffer(ciphertext).chunks_of(block_size).map(&:bytes).uniq.length

      (total_blocks - uniq_blocks ) == (redundant_test_blocks -1) 
    end
672748
def reject(&blk)
      if block_given?
        Thresholds.new(@thresholds.reject(&blk))
      else
        Thresholds.new(@thresholds.reject)
      end
    end
372776
def check_tx_output_types(outputs, block_height):
    
    # for now, we do not allow nonstandard outputs (all outputs must be p2pkh or p2sh outputs)
    # this excludes bech32 outputs, for example.
    supported_output_types = get_epoch_btc_script_types(block_height)
    for out in outputs:
        out_type = virtualchain.btc_script_classify(out['script'])
        if out_type not in supported_output_types:
            log.warning('Unsupported output type {} ({})'.format(out_type, out['script']))
            return False

    return True
464031
function checkBadness() {
    var b, b1, bad, big, bw, count, h, x, y;
    bad = bw = count = 0;

    // Blocks of same colour.
    for (y = 0; y < width - 1; y++) {
      for (x = 0; x < width - 1; x++) {
            // All foreground colour.
        if ((frameBuffer[x + width * y] &&
             frameBuffer[(x + 1) + width * y] &&
             frameBuffer[x + width * (y + 1)] &&
             frameBuffer[(x + 1) + width * (y + 1)]) ||
            // All background colour.
            !(frameBuffer[x + width * y] ||
              frameBuffer[(x + 1) + width * y] ||
              frameBuffer[x + width * (y + 1)] ||
              frameBuffer[(x + 1) + width * (y + 1)])) {
          bad += N2;
        }
      }
    }

    // X runs.
    for (y = 0; y < width; y++) {
      badBuffer[0] = 0;

      for (h = b = x = 0; x < width; x++) {
        if ((b1 = frameBuffer[x + width * y]) === b) {
          badBuffer[h]++;
        } else {
          badBuffer[++h] = 1;
        }

        b   = b1;
        bw += b ? 1 : -1;
      }

      bad += getBadRuns(h);
    }

    if (bw < 0) bw = -bw;

    big   = bw;
    big  += big << 2;
    big <<= 1;

    while (big > width * width) {
      big -= width * width;
      count++;
    }

    bad += count * N4;

    // Y runs.
    for (x = 0; x < width; x++) {
      badBuffer[0] = 0;

      for (h = b = y = 0; y < width; y++) {
        if ((b1 = frameBuffer[x + width * y]) === b) {
          badBuffer[h]++;
        } else {
          badBuffer[++h] = 1;
        }

        b = b1;
      }

      bad += getBadRuns(h);
    }

    return bad;
  }
621158
private byte[] skipBlocksNotInFilter() throws IOException {
		byte[] magicNo=new byte[4];
		byte[] blockSizeByte=new byte[4];
		// mark bytestream so we can peak into it
		this.bin.mark(8);
		// read magic
		int maxByteRead=4;
		int totalByteRead=0;
		int readByte;
		while ((readByte=this.bin.read(magicNo,totalByteRead,maxByteRead-totalByteRead))>-1) {
				totalByteRead+=readByte;
				if (totalByteRead>=maxByteRead) {
					break;
				}
		}
		if (totalByteRead!=maxByteRead) {
			return new byte[0];
		} 
		
		// read blocksize
	
		maxByteRead=4;
		totalByteRead=0;
		while ((readByte=this.bin.read(blockSizeByte,totalByteRead,maxByteRead-totalByteRead))>-1) {
				totalByteRead+=readByte;
				if (totalByteRead>=maxByteRead) {
					break;
				}
		}
		if (totalByteRead!=maxByteRead) {
			return new byte[0];
		} 
		
		long blockSize=BitcoinUtil.getSize(blockSizeByte)+8;
		// read the full block
		this.bin.reset();
		//filter by magic numbers?
		if (filterSpecificMagic) {
			for (int i=0;i<specificMagicByteArray.length;i++) {
				byte[] currentFilter=specificMagicByteArray[i];
				boolean doesMatchOneMagic=BitcoinUtil.compareMagics(currentFilter,magicNo);
				// correspond to filter? read it!
				if (doesMatchOneMagic) {
					return blockSizeByte;
				}
			}
			// Skip block if not found
			if (this.bin.skip(blockSize)!=blockSize) {
					LOG.error("Cannot skip block in InputStream");
			}
			return new byte[0];
		
		} else {
			return blockSizeByte;
		}
}
160328
private void checkBlockDefinitionsComplete() throws MiniTemplator.TemplateSyntaxException {
        for (int blockNo = 0; blockNo < blockTabCnt; blockNo++) {
            BlockTabRec btr = blockTab[blockNo];
            if (btr.definitionIsOpen) {
                throw new MiniTemplator.TemplateSyntaxException(
                        "Missing $EndBlock command in template for block \"" + btr.blockName + "\".");
            }
        }
        if (currentNestingLevel != 0) {
            throw new MiniTemplator.TemplateSyntaxException("Block nesting level error at end of template.");
        }
    }
1058571
function checkBlockTag(blockTag) {
    if (blockTag == null) {
        return 'latest';
    }
    if (blockTag === 'earliest') {
        return '0x0';
    }
    if (blockTag === 'latest' || blockTag === 'pending') {
        return blockTag;
    }
    if (typeof (blockTag) === 'number') {
        return bytes_1.hexStripZeros(bytes_1.hexlify(blockTag));
    }
    if (bytes_1.isHexString(blockTag)) {
        return bytes_1.hexStripZeros(blockTag);
    }
    throw new Error('invalid blockTag');
}