GRPCClient implements HLAPI { @Override public void registerTrunkListener(TrunkListener listener) throws HLAPIException { observer.subscribeToBlocks(listener); } GRPCClient(String host, int port, int observerPort); @Override String getClientVersion(); @Override String getServerVersion(); @Override long ping(long nonce); @Override void addAlertListener(AlertListener listener); @Override void removeAlertListener(AlertListener listener); @Override int getChainHeight(); @Override HLAPIHeader getBlockHeader(BID hash); @Override HLAPIBlock getBlock(BID hash); @Override HLAPITransaction getTransaction(TID hash); @Override void sendTransaction(Transaction transaction); @Override void registerRejectListener(RejectListener rejectListener); @Override void removeRejectListener(RejectListener rejectListener); @Override void sendBlock(Block block); @Override void registerTransactionListener(TransactionListener listener); @Override void removeTransactionListener(TransactionListener listener); @Override void registerTrunkListener(TrunkListener listener); @Override void removeTrunkListener(TrunkListener listener); @Override void catchUp(List<BID> inventory, int limit, boolean headers, TrunkListener listener);  }
@Test public void trunkListener() throws HLAPIException, InterruptedException, ExecutionException { MeasurableTransaction tx1 = new MeasurableTransaction(TransactionTest.randomTx(), unlimited); MeasurableTransaction tx2 = new MeasurableTransaction(TransactionTest.randomTx(), unlimited); client.registerTrunkListener(added -> { for (HLAPIBlock block : added) { boolean listenerCalled = false; if (block.getTransactions().contains(tx1.tx)) { listenerCalled = true; tx1.complete(); } if (block.getTransactions().contains(tx2.tx)) { listenerCalled = true; tx2.complete(); } if (!listenerCalled) { fail("Block containing no known transaction"); } } }); tx1.send(client); tx2.send(client); tx1.get(); tx2.get(); }