I was debugging my code which fetches UserWallets from database and then generates addresses for them by connecting with external REST API. Now I have a subscribe nested inside another subscribe but I read it's bad solution (It actually doesn't work and I think that's the reason).
userWalletDao.getUnregisteredUserWallets()
.subscribe(nextWallet -> {
log.info("Fetched next wallet for registration {}", nextWallet);
blockchainIntegration.registerUserWallet(nextWallet.getUserId())
.subscribe(address -> {
nextWallet.setAddress(address);
userWalletDao.persistUserWalletAddress(nextWallet);
log.info("Registered wallet {} with address {}.", nextWallet, address);
});
});
I was trying to make it in one subscribe, but if I flatMap wallets to addresses I lose a UserWallet object to set an fetched address for it and persist it back in the database.
How can I fetch wallets and then call an API to generate an address for it with one subscribe?
getUnregisteredUserWallets() returns Observable<UserWallet> and registerUserWallet() returns Single<String>.