/** * Asks the connected peer for the block of the given hash, and returns a future representing the answer. * If you want the block right away and don't mind waiting for it, just call .get() on the result. Your thread * will block until the peer answers. */ @SuppressWarnings("unchecked") // The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning // ListenableFuture instead of ListenableFuture<Block>. This is okay as sendSingleGetData() actually returns // ListenableFuture<Block> in this context. Note that sendSingleGetData() is also used for Transactions. public ListenableFuture<Block> getBlock(Sha256Hash blockHash) { // This does not need to be locked. log.info("Request to fetch block {}", blockHash); GetDataMessage getdata = new GetDataMessage(params); if (vPeerVersionMessage.isWitnessSupported()) getdata.addWitnessBlock(blockHash); else getdata.addBlock(blockHash); return sendSingleGetData(getdata); }
/** * Asks the connected peer for the given transaction from its memory pool. Transactions in the chain cannot be * retrieved this way because peers don't have a transaction ID to transaction-pos-on-disk index, and besides, * in future many peers will delete old transaction data they don't need. */ @SuppressWarnings("unchecked") // The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning // ListenableFuture instead of ListenableFuture<Transaction>. This is okay as sendSingleGetData() actually returns // ListenableFuture<Transaction> in this context. Note that sendSingleGetData() is also used for Blocks. public ListenableFuture<Transaction> getPeerMempoolTransaction(Sha256Hash hash) { // This does not need to be locked. // TODO: Unit test this method. log.info("Request to fetch peer mempool tx {}", hash); GetDataMessage getdata = new GetDataMessage(params); if (vPeerVersionMessage.isWitnessSupported()) getdata.addWitnessTransaction(hash); else getdata.addTransaction(hash); return sendSingleGetData(getdata); }
for (Peer peer : peers) { try { if (peer.getPeerVersionMessage().isWitnessSupported()) peer.sendMessage(tx); else
log.info("{}: Requesting {} transactions for depth {} dep resolution", getAddress(), needToRequest.size(), depth + 1); for (Sha256Hash hash : needToRequest) { if (vPeerVersionMessage.isWitnessSupported()) getdata.addWitnessTransaction(hash); else
} else { log.debug("{}: getdata on tx {}", getAddress(), item.hash); getdata.addItem(vPeerVersionMessage.isWitnessSupported() ? item.toWitnessItem() : item); pingAfterGetData = true; } else { getdata.addItem(vPeerVersionMessage.isWitnessSupported() ? item.toWitnessItem() : item);
} else { log.debug("{}: getdata on tx {}", getAddress(), item.hash); getdata.addItem(vPeerVersionMessage.isWitnessSupported() ? item.toWitnessItem() : item); pingAfterGetData = true; } else { getdata.addItem(vPeerVersionMessage.isWitnessSupported() ? item.toWitnessItem() : item);