use of org.bitcoinj.wallet.Wallet.CompletionException in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsOfflineTask method sendCoinsOffline.
public final void sendCoinsOffline(final SendRequest sendRequest) {
backgroundHandler.post(new Runnable() {
@Override
public void run() {
org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
try {
log.info("sending: {}", sendRequest);
// can take long
final Transaction transaction = wallet.sendCoinsOffline(sendRequest);
log.info("send successful, transaction committed: {}", transaction.getHashAsString());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onSuccess(transaction);
}
});
} catch (final InsufficientMoneyException x) {
final Coin missing = x.missing;
if (missing != null)
log.info("send failed, {} missing", missing.toFriendlyString());
else
log.info("send failed, insufficient coins");
callbackHandler.post(new Runnable() {
@Override
public void run() {
onInsufficientMoney(x.missing);
}
});
} catch (final ECKey.KeyIsEncryptedException x) {
log.info("send failed, key is encrypted: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onFailure(x);
}
});
} catch (final KeyCrypterException x) {
log.info("send failed, key crypter exception: {}", x.getMessage());
final boolean isEncrypted = wallet.isEncrypted();
callbackHandler.post(new Runnable() {
@Override
public void run() {
if (isEncrypted)
onInvalidEncryptionKey();
else
onFailure(x);
}
});
} catch (final CouldNotAdjustDownwards x) {
log.info("send failed, could not adjust downwards: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onEmptyWalletFailed();
}
});
} catch (final CompletionException x) {
log.info("send failed, cannot complete: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onFailure(x);
}
});
}
}
});
}
Aggregations