fix npe on startup without monerod connection

This commit is contained in:
woodser 2022-05-21 07:17:17 -04:00
parent 052180eed7
commit e33d93eee8

View File

@ -229,16 +229,16 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
.ifPresent(errorMsg -> invalidOffers.add(new Tuple2<>(openOffer, errorMsg))));
// process unposted offers
lastUnlockedBalance = xmrWalletService.getWallet().getUnlockedBalance(0);
processUnpostedOffers((transaction) -> {}, (errMessage) -> {
log.warn("Error processing unposted offers on new unlocked balance: " + errMessage);
});
// register to process unposted offers when unlocked balance increases
if (xmrWalletService.getWallet() != null) lastUnlockedBalance = xmrWalletService.getWallet().getUnlockedBalance(0);
xmrWalletService.addWalletListener(new MoneroWalletListener() {
@Override
public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
if (lastUnlockedBalance.compareTo(newUnlockedBalance) < 0) {
if (lastUnlockedBalance == null || lastUnlockedBalance.compareTo(newUnlockedBalance) < 0) {
processUnpostedOffers((transaction) -> {}, (errMessage) -> {
log.warn("Error processing unposted offers on new unlocked balance: " + errMessage);
});
@ -642,6 +642,12 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
private void processUnpostedOffer(OpenOffer openOffer, TransactionResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
try {
// done processing if wallet not initialized
if (xmrWalletService.getWallet() == null) {
resultHandler.handleResult(null);
return;
}
// get offer reserve amount
Coin offerReserveAmountCoin = openOffer.getOffer().getReserveAmount();
BigInteger offerReserveAmount = ParsingUtils.centinerosToAtomicUnits(offerReserveAmountCoin.value);