From 6d4605cfe673407982e503910faabe2c9e688200 Mon Sep 17 00:00:00 2001 From: AZ Date: Sun, 22 Jan 2017 16:45:27 +0100 Subject: [PATCH] removed brainf***ed piece of code --- src/main/java/jota/IotaAPI.java | 28 ++++++++----------- .../error/BroadcastAndStoreException.java | 11 ++++++++ .../java/jota/error/NoAddressException.java | 11 -------- .../jota/error/NoTransactionExcpection.java | 11 -------- 4 files changed, 23 insertions(+), 38 deletions(-) create mode 100644 src/main/java/jota/error/BroadcastAndStoreException.java delete mode 100644 src/main/java/jota/error/NoAddressException.java delete mode 100644 src/main/java/jota/error/NoTransactionExcpection.java diff --git a/src/main/java/jota/IotaAPI.java b/src/main/java/jota/IotaAPI.java index 18a9279..a657fea 100644 --- a/src/main/java/jota/IotaAPI.java +++ b/src/main/java/jota/IotaAPI.java @@ -92,7 +92,7 @@ public class IotaAPI extends IotaAPICoreProxy { * @property {bool} inclusionStates returns confirmation status of all transactions * @returns {object} success **/ - public GetTransferResponse getTransfers(String seed, Integer start, Integer end, Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoAddressException, NoTransactionExcpection, NoNodeInfoException, NoInclusionStatesExcpection { + public GetTransferResponse getTransfers(String seed, Integer start, Integer end, Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoNodeInfoException, NoInclusionStatesExcpection { StopWatch stopWatch = new StopWatch(); // validate & if needed pad seed if ((seed = InputValidator.validateSeed(seed)) == null) { @@ -100,8 +100,6 @@ public class IotaAPI extends IotaAPICoreProxy { } start = start != null ? 0 : start; - end = end == null ? null : end; - inclusionStates = inclusionStates != null ? inclusionStates : null; if (start > end || end > (start + 500)) { throw new ArgumentException(); @@ -116,10 +114,10 @@ public class IotaAPI extends IotaAPICoreProxy { System.out.println("GetTransfers after bundlesFromAddresses " + sw.getElapsedTimeMili() + " ms"); return GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili()); } - throw new NoAddressException(); + return GetTransferResponse.create(new Bundle[]{}, stopWatch.getElapsedTimeMili()); } - public Bundle[] bundlesFromAddresses(String[] addresses, final Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoTransactionExcpection, NoNodeInfoException, NoInclusionStatesExcpection { + public Bundle[] bundlesFromAddresses(String[] addresses, final Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoNodeInfoException, NoInclusionStatesExcpection { List trxs = findTransactionObjects(addresses); // set of tail transactions @@ -199,13 +197,13 @@ public class IotaAPI extends IotaAPICoreProxy { * @param trytes * @return a StoreTransactionsResponse */ - public StoreTransactionsResponse broadcastAndStore(final String... trytes) { + public StoreTransactionsResponse broadcastAndStore(final String... trytes) throws BroadcastAndStoreException { try { broadcastTransactions(trytes); } catch (Exception e) { log.error("Impossible to broadcastAndStore, aborting.", e); - throw new IllegalStateException("BroadcastAndStore Illegal state Exception"); + throw new BroadcastAndStoreException(); } return storeTransactions(trytes); } @@ -218,7 +216,7 @@ public class IotaAPI extends IotaAPICoreProxy { * @param {int} minWeightMagnitude * @return */ - public List sendTrytes(final String[] trytes, final int depth, final int minWeightMagnitude) { + public List sendTrytes(final String[] trytes, final int depth, final int minWeightMagnitude) { final GetTransactionsToApproveResponse txs = getTransactionsToApprove(depth); // attach to tangle - do pow @@ -226,9 +224,8 @@ public class IotaAPI extends IotaAPICoreProxy { try { broadcastAndStore(res.getTrytes()); - } catch (Exception e) { - log.error("Impossible to sendTrytes, aborting.", e); - throw new IllegalStateException("sendTrytes Illegal state Exception"); + } catch (BroadcastAndStoreException e) { + return new ArrayList<>(); } final List trx = new ArrayList<>(); @@ -275,11 +272,10 @@ public class IotaAPI extends IotaAPICoreProxy { * @returns {function} callback * @returns {object} success **/ - public List findTransactionObjects(String[] input) throws NoTransactionExcpection { + public List findTransactionObjects(String[] input) { FindTransactionResponse ftr = findTransactions(input, null, null, null); if (ftr == null || ftr.getHashes() == null) - throw new NoTransactionExcpection(); - + return new ArrayList<>(); // get the transaction objects of the transactions return getTransactionsObjects(ftr.getHashes()); } @@ -294,10 +290,10 @@ public class IotaAPI extends IotaAPICoreProxy { * @returns {function} callback * @returns {object} success **/ - public List findTransactionObjectsByBundle(String[] input) throws NoTransactionExcpection { + public List findTransactionObjectsByBundle(String[] input) { FindTransactionResponse ftr = findTransactions(null, null, null, input); if (ftr == null || ftr.getHashes() == null) - throw new NoTransactionExcpection(); + return new ArrayList<>(); // get the transaction objects of the transactions return getTransactionsObjects(ftr.getHashes()); diff --git a/src/main/java/jota/error/BroadcastAndStoreException.java b/src/main/java/jota/error/BroadcastAndStoreException.java new file mode 100644 index 0000000..a5b58e6 --- /dev/null +++ b/src/main/java/jota/error/BroadcastAndStoreException.java @@ -0,0 +1,11 @@ +package jota.error; + +/** + * Created by Adrian on 22.01.2017. + */ +public class BroadcastAndStoreException extends BaseException { + + public BroadcastAndStoreException() { + super("Impossible to broadcastAndStore, aborting."); + } +} \ No newline at end of file diff --git a/src/main/java/jota/error/NoAddressException.java b/src/main/java/jota/error/NoAddressException.java deleted file mode 100644 index 93752b8..0000000 --- a/src/main/java/jota/error/NoAddressException.java +++ /dev/null @@ -1,11 +0,0 @@ -package jota.error; - -/** - * Created by Adrian on 22.01.2017. - */ -public class NoAddressException extends BaseException { - - public NoAddressException() { - super("Not address found for the provided seed"); - } -} \ No newline at end of file diff --git a/src/main/java/jota/error/NoTransactionExcpection.java b/src/main/java/jota/error/NoTransactionExcpection.java deleted file mode 100644 index f2b3138..0000000 --- a/src/main/java/jota/error/NoTransactionExcpection.java +++ /dev/null @@ -1,11 +0,0 @@ -package jota.error; - -/** - * Created by Adrian on 22.01.2017. - */ -public class NoTransactionExcpection extends BaseException { - - public NoTransactionExcpection() { - super("Not transactions for the provided seed"); - } -}