I use bitcoinj to create the following method to broadcast a raw transacion in testnet, and I did see on bitcoin explorer that it has been broadcast. But even the transaction has been already broadcast, it always return false message, please help me to solve this issue, I don't know if there is a problem when sync with the peer or if my broadcast method is wrong.
//sync with the peer
static WalletAppKit kit = new WalletAppKit(params, new File("."), "sendrequest-example");
kit.startAsync();
kit.awaitRunning();
//transaction broadcast method
public static boolean broadcastTransaction (Transaction tx) {
System.out.println("Broadcast transaction: ");
System.out.println(tx);
try {
TransactionBroadcast broadcast = kit.peerGroup().broadcastTransaction(tx);
broadcast.future().get(20,TimeUnit.SECONDS);
System.out.println(tx.getHash() + "broadcasted successfully!");
return true;
} catch (Exception e) {
System.out.println("e.getMessage() = " + e.getMessage());
}
return false;
}
The false message is always as following, although the transaction has been indeed broadcast.
e.getMessage() = Waited 20 seconds (plus 1985971 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@20d525[status=PENDING]
e.getMessage() = Waited 20 seconds (plus 4214583 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@38afe297[status=PENDING]