{ return connector.toString(); }
/** * Processes a received block and tries to add it to the chain. If there's something wrong with the block an * exception is thrown. If the block is OK but cannot be connected to the chain at this time, returns false. * If the block can be connected to the chain, returns true. * Accessing block's transactions in another thread while this method runs may result in undefined behavior. */ public boolean add(Block block) throws VerificationException, PrunedException { try { return add(block, true, null, null); } catch (BlockStoreException e) { // TODO: Figure out a better way to propagate this exception to the user. throw new RuntimeException(e); } catch (VerificationException e) { try { notSettingChainHead(); } catch (BlockStoreException e1) { throw new RuntimeException(e1); } throw new VerificationException("Could not verify block:\n" + block.toString(), e); } }
/** * Processes a received block and tries to add it to the chain. If there's something wrong with the block an * exception is thrown. If the block is OK but cannot be connected to the chain at this time, returns false. * If the block can be connected to the chain, returns true. * Accessing block's transactions in another thread while this method runs may result in undefined behavior. */ public boolean add(Block block) throws VerificationException, PrunedException { try { return add(block, true, null, null); } catch (BlockStoreException e) { // TODO: Figure out a better way to propagate this exception to the user. throw new RuntimeException(e); } catch (VerificationException e) { try { notSettingChainHead(); } catch (BlockStoreException e1) { throw new RuntimeException(e1); } throw new VerificationException("Could not verify block:\n" + block.toString(), e); } }
/** * Processes a received block and tries to add it to the chain. If there's something wrong with the block an * exception is thrown. If the block is OK but cannot be connected to the chain at this time, returns false. * If the block can be connected to the chain, returns true. * Accessing block's transactions in another thread while this method runs may result in undefined behavior. */ public boolean add(Block block) throws VerificationException, PrunedException { try { return add(block, true, null, null); } catch (BlockStoreException e) { // TODO: Figure out a better way to propagate this exception to the user. throw new RuntimeException(e); } catch (VerificationException e) { try { notSettingChainHead(); } catch (BlockStoreException e1) { throw new RuntimeException(e1); } throw new VerificationException("Could not verify block:\n" + block.toString(), e); } }
@Override public String toString() { return String.format(Locale.US, "Block %s at height %d: %s", getHeader().getHashAsString(), getHeight(), getHeader().toString()); } }
@Override public String toString() { return String.format(Locale.US, "Block %s at height %d: %s", getHeader().getHashAsString(), getHeight(), getHeader().toString()); } }
/** * Processes a received block and tries to add it to the chain. If there's something wrong with the block an * exception is thrown. If the block is OK but cannot be connected to the chain at this time, returns false. * If the block can be connected to the chain, returns true. * Accessing block's transactions in another thread while this method runs may result in undefined behavior. */ public boolean add(Block block) throws VerificationException, PrunedException { try { return add(block, true, null, null); } catch (BlockStoreException e) { // TODO: Figure out a better way to propagate this exception to the user. throw new RuntimeException(e); } catch (VerificationException e) { try { notSettingChainHead(); } catch (BlockStoreException e1) { throw new RuntimeException(e1); } throw new VerificationException("Could not verify block:\n" + block.toString(), e); } }
@Override public String toString() { return String.format(Locale.US, "Block %s at height %d: %s", getHeader().getHashAsString(), getHeight(), getHeader().toString()); } }
@Override public String toString() { return String.format(Locale.US, "Block %s at height %d: %s", getHeader().getHashAsString(), getHeight(), getHeader().toString()); } }
@Override protected void parse() throws ProtocolException { long numHeaders = readVarInt(); if (numHeaders > MAX_HEADERS) throw new ProtocolException("Too many headers: got " + numHeaders + " which is larger than " + MAX_HEADERS); blockHeaders = new ArrayList<Block>(); final BitcoinSerializer serializer = this.params.getSerializer(true); for (int i = 0; i < numHeaders; ++i) { final Block newBlockHeader = serializer.makeBlock(payload, cursor, UNKNOWN_LENGTH); if (newBlockHeader.hasTransactions()) { throw new ProtocolException("Block header does not end with a null byte"); } cursor += newBlockHeader.optimalEncodingMessageSize; blockHeaders.add(newBlockHeader); } if (length == UNKNOWN_LENGTH) { length = cursor - offset; } if (log.isDebugEnabled()) { for (int i = 0; i < numHeaders; ++i) { log.debug(this.blockHeaders.get(i).toString()); } } }
@Override protected void parse() throws ProtocolException { long numHeaders = readVarInt(); if (numHeaders > MAX_HEADERS) throw new ProtocolException("Too many headers: got " + numHeaders + " which is larger than " + MAX_HEADERS); blockHeaders = new ArrayList<>(); final BitcoinSerializer serializer = this.params.getSerializer(true); for (int i = 0; i < numHeaders; ++i) { final Block newBlockHeader = serializer.makeBlock(payload, cursor, UNKNOWN_LENGTH); if (newBlockHeader.hasTransactions()) { throw new ProtocolException("Block header does not end with a null byte"); } cursor += newBlockHeader.optimalEncodingMessageSize; blockHeaders.add(newBlockHeader); } if (length == UNKNOWN_LENGTH) { length = cursor - offset; } if (log.isDebugEnabled()) { for (int i = 0; i < numHeaders; ++i) { log.debug(this.blockHeaders.get(i).toString()); } } }
@Override protected void parse() throws ProtocolException { long numHeaders = readVarInt(); if (numHeaders > MAX_HEADERS) throw new ProtocolException("Too many headers: got " + numHeaders + " which is larger than " + MAX_HEADERS); blockHeaders = new ArrayList<Block>(); final BitcoinSerializer serializer = this.params.getSerializer(true); for (int i = 0; i < numHeaders; ++i) { final Block newBlockHeader = serializer.makeBlock(payload, cursor, UNKNOWN_LENGTH); if (newBlockHeader.hasTransactions()) { throw new ProtocolException("Block header does not end with a null byte"); } cursor += newBlockHeader.optimalEncodingMessageSize; blockHeaders.add(newBlockHeader); } if (length == UNKNOWN_LENGTH) { length = cursor - offset; } if (log.isDebugEnabled()) { for (int i = 0; i < numHeaders; ++i) { log.debug(this.blockHeaders.get(i).toString()); } } }
@Override protected void parse() throws ProtocolException { long numHeaders = readVarInt(); if (numHeaders > MAX_HEADERS) throw new ProtocolException("Too many headers: got " + numHeaders + " which is larger than " + MAX_HEADERS); blockHeaders = new ArrayList<>(); final BitcoinSerializer serializer = this.params.getSerializer(true); for (int i = 0; i < numHeaders; ++i) { final Block newBlockHeader = serializer.makeBlock(payload, cursor, UNKNOWN_LENGTH); if (newBlockHeader.hasTransactions()) { throw new ProtocolException("Block header does not end with a null byte"); } cursor += newBlockHeader.optimalEncodingMessageSize; blockHeaders.add(newBlockHeader); } if (length == UNKNOWN_LENGTH) { length = cursor - offset; } if (log.isDebugEnabled()) { for (int i = 0; i < numHeaders; ++i) { log.debug(this.blockHeaders.get(i).toString()); } } }