diff --git a/jota/src/main/java/jota/IotaAPI.java b/jota/src/main/java/jota/IotaAPI.java
index 56f4386..56a4c44 100644
--- a/jota/src/main/java/jota/IotaAPI.java
+++ b/jota/src/main/java/jota/IotaAPI.java
@@ -1,7 +1,7 @@
package jota;
import jota.dto.response.*;
-import jota.error.*;
+import jota.error.ArgumentException;
import jota.model.*;
import jota.pow.ICurl;
import jota.pow.SpongeFactory;
@@ -46,10 +46,9 @@ public class IotaAPI extends IotaAPICore {
* @param total Total number of addresses to generate.
* @param returnAll If true, it returns all addresses which were deterministically generated (until findTransactions returns null).
* @return An array of strings with the specifed number of addresses.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public GetNewAddressResponse getNewAddress(final String seed, int security, final int index, final boolean checksum, final int total, final boolean returnAll) throws InvalidSecurityLevelException, InvalidAddressException {
+ public GetNewAddressResponse getNewAddress(final String seed, int security, final int index, final boolean checksum, final int total, final boolean returnAll) throws ArgumentException, ArgumentException {
StopWatch stopWatch = new StopWatch();
@@ -94,15 +93,9 @@ public class IotaAPI extends IotaAPICore {
* @param end Ending key index.
* @param inclusionStates If true, it gets the inclusion states of the transfers.
* @return Bundle of transfers.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
- * @throws ArgumentException is thrown when an invalid argument is provided.
- * @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
- * @throws InvalidSignatureException is thrown when an invalid signature is encountered.
- * @throws NoNodeInfoException is thrown when its not possible to get node info.
- * @throws NoInclusionStatesException when it not possible to get a inclusion state.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public GetTransferResponse getTransfers(String seed, int security, Integer start, Integer end, Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoNodeInfoException, NoInclusionStatesException, InvalidSecurityLevelException, InvalidAddressException {
+ public GetTransferResponse getTransfers(String seed, int security, Integer start, Integer end, Boolean inclusionStates) throws ArgumentException {
// validate seed
if ((!InputValidator.isValidSeed(seed))) {
@@ -129,15 +122,11 @@ public class IotaAPI extends IotaAPICore {
* @param addresses List of addresses.
* @param inclusionStates If true, it gets the inclusion states of the transfers.
* @return A Transaction objects.
- * @throws ArgumentException is thrown when an invalid argument is provided.
- * @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
- * @throws InvalidSignatureException is thrown when an invalid signature is encountered.
- * @throws NoNodeInfoException is thrown when its not possible to get node info.
- * @throws NoInclusionStatesException when it not possible to get a inclusion state.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public Bundle[] bundlesFromAddresses(String[] addresses, final Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoNodeInfoException, NoInclusionStatesException {
+ public Bundle[] bundlesFromAddresses(String[] addresses, final Boolean inclusionStates) throws ArgumentException {
- List trxs = findTransactionObjects(addresses);
+ List trxs = findTransactionObjectsByAddresses(addresses);
// set of tail transactions
List tailTransactions = new ArrayList<>();
List nonTailBundleHashes = new ArrayList<>();
@@ -170,13 +159,9 @@ public class IotaAPI extends IotaAPICore {
// of the tail transactions, and thus the bundles
GetInclusionStateResponse gisr = null;
if (tailTxArray.length != 0 && inclusionStates) {
- try {
gisr = getLatestInclusion(tailTxArray);
- } catch (IllegalAccessError ignored) {
- throw new NoInclusionStatesException();
- }
if (gisr == null || gisr.getStates() == null || gisr.getStates().length == 0) {
- throw new NoInclusionStatesException();
+ throw new IllegalStateException("No inclusion states for transaction");
}
}
final GetInclusionStateResponse finalInclusionStates = gisr;
@@ -200,7 +185,7 @@ public class IotaAPI extends IotaAPICore {
finalBundles.add(gbr);
}
// If error returned from getBundle, simply ignore it because the bundle was most likely incorrect
- } catch (InvalidBundleException | ArgumentException | InvalidSignatureException e) {
+ } catch (ArgumentException e) {
log.warn("GetBundleError: ", e);
}
}
@@ -219,15 +204,18 @@ public class IotaAPI extends IotaAPICore {
*
* @param trytes The trytes.
* @return A StoreTransactionsResponse.
- * @throws BroadcastAndStoreException is thrown if its not possible to broadcast and store.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public StoreTransactionsResponse broadcastAndStore(final String... trytes) throws BroadcastAndStoreException {
+ public StoreTransactionsResponse broadcastAndStore(final String... trytes) throws ArgumentException {
+
+ if (!InputValidator.isArrayOfAttachedTrytes(trytes)) {
+ throw new ArgumentException("Invalid trytes provided");
+ }
try {
broadcastTransactions(trytes);
} catch (Exception e) {
- log.error("Impossible to broadcastAndStore, aborting.", e);
- throw new BroadcastAndStoreException();
+ throw new ArgumentException(e.toString());
}
return storeTransactions(trytes);
}
@@ -239,9 +227,9 @@ public class IotaAPI extends IotaAPICore {
* @param depth The depth.
* @param minWeightMagnitude The minimum weight magnitude.
* @return Transactions objects.
- * @throws InvalidTrytesException is thrown when invalid trytes is provided.
+ * @throws ArgumentException is thrown when invalid trytes is provided.
*/
- public List sendTrytes(final String[] trytes, final int depth, final int minWeightMagnitude) throws InvalidTrytesException {
+ public List sendTrytes(final String[] trytes, final int depth, final int minWeightMagnitude) throws ArgumentException {
final GetTransactionsToApproveResponse txs = getTransactionsToApprove(depth);
// attach to tangle - do pow
@@ -249,7 +237,7 @@ public class IotaAPI extends IotaAPICore {
try {
broadcastAndStore(res.getTrytes());
- } catch (BroadcastAndStoreException e) {
+ } catch (ArgumentException e) {
return new ArrayList<>();
}
@@ -268,7 +256,7 @@ public class IotaAPI extends IotaAPICore {
* @param hashes The hashes
* @return Transaction objects.
**/
- public List getTransactionsObjects(String[] hashes) {
+ public List findTransactionsObjectsByHashes(String[] hashes) throws ArgumentException {
if (!InputValidator.isArrayOfHashes(hashes)) {
throw new IllegalStateException("Not an Array of Hashes: " + Arrays.toString(hashes));
@@ -286,34 +274,71 @@ public class IotaAPI extends IotaAPICore {
/**
* Wrapper function for findTransactions, getTrytes and transactionObjects.
- * Returns the transactionObject of a transaction hash. The input can be a valid findTransactions input.
+ * Returns the transactionObject of a transaction hash. The input can be a list of valid addresses.
*
- * @param input The inputs.
+ * @param addresses The addresses.
* @return Transactions.
**/
- public List findTransactionObjects(String[] input) {
- FindTransactionResponse ftr = findTransactions(input, null, null, null);
+ public List findTransactionObjectsByAddresses(String[] addresses) throws ArgumentException {
+ List addressesWithoutChecksum = new ArrayList<>();
+
+ for (String address : addresses) {
+ String addressO = Checksum.removeChecksum(address);
+ addressesWithoutChecksum.add(addressO);
+ }
+
+ FindTransactionResponse ftr = findTransactions(addressesWithoutChecksum.toArray(new String[]{}), null, null, null);
if (ftr == null || ftr.getHashes() == null)
return new ArrayList<>();
// get the transaction objects of the transactions
- return getTransactionsObjects(ftr.getHashes());
+ return findTransactionsObjectsByHashes(ftr.getHashes());
}
/**
* Wrapper function for findTransactions, getTrytes and transactionObjects.
- * Returns the transactionObject of a transaction hash. The input can be a valid.
- * findTransactions input
+ * Returns the transactionObject of a transaction hash. The input can be a list of valid tags.
*
- * @param input The inputs.
+ * @param tags The tags.
* @return Transactions.
**/
- public List findTransactionObjectsByBundle(String[] input) {
- FindTransactionResponse ftr = findTransactions(null, null, null, input);
+ public List findTransactionObjectsByTag(String[] tags) throws ArgumentException {
+ FindTransactionResponse ftr = findTransactions(null, tags, null, null);
+ if (ftr == null || ftr.getHashes() == null)
+ return new ArrayList<>();
+ // get the transaction objects of the transactions
+ return findTransactionsObjectsByHashes(ftr.getHashes());
+ }
+
+ /**
+ * Wrapper function for findTransactions, getTrytes and transactionObjects.
+ * Returns the transactionObject of a transaction hash. The input can be a list of valid approvees.
+ *
+ * @param approvees The approvees.
+ * @return Transactions.
+ **/
+ public List findTransactionObjectsByApprovees(String[] approvees) throws ArgumentException {
+ FindTransactionResponse ftr = findTransactions(null, null, approvees, null);
+ if (ftr == null || ftr.getHashes() == null)
+ return new ArrayList<>();
+ // get the transaction objects of the transactions
+ return findTransactionsObjectsByHashes(ftr.getHashes());
+ }
+
+ /**
+ * Wrapper function for findTransactions, getTrytes and transactionObjects.
+ * Returns the transactionObject of a transaction hash. The input can be a list of valid bundles.
+ * findTransactions input
+ *
+ * @param bundles The bundles.
+ * @return Transactions.
+ **/
+ public List findTransactionObjectsByBundle(String[] bundles) throws ArgumentException {
+ FindTransactionResponse ftr = findTransactions(null, null, null, bundles);
if (ftr == null || ftr.getHashes() == null)
return new ArrayList<>();
// get the transaction objects of the transactions
- return getTransactionsObjects(ftr.getHashes());
+ return findTransactionsObjectsByHashes(ftr.getHashes());
}
/**
@@ -326,12 +351,9 @@ public class IotaAPI extends IotaAPICore {
* @param inputs The inputs.
* @param validateInputs whether or not to validate the balances of the provided inputs
* @return Returns bundle trytes.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
- * @throws NotEnoughBalanceException is thrown when a transfer fails because their is not enough balance to perform the transfer.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
- * @throws InvalidTransferException is thrown when an invalid transfer is provided.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public List prepareTransfers(String seed, int security, final List transfers, String remainder, List inputs, boolean validateInputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException, InvalidTransferException {
+ public List prepareTransfers(String seed, int security, final List transfers, String remainder, List inputs, boolean validateInputs) throws ArgumentException {
// validate seed
if ((!InputValidator.isValidSeed(seed))) {
@@ -339,12 +361,12 @@ public class IotaAPI extends IotaAPICore {
}
if (security < 1) {
- throw new InvalidSecurityLevelException();
+ throw new ArgumentException("Invalid security level provided");
}
// Input validation of transfers object
if (!InputValidator.isTransfersCollectionValid(transfers)) {
- throw new InvalidTransferException();
+ throw new ArgumentException("Invalid transfers provided");
}
// Create a new bundle
@@ -494,10 +516,9 @@ public class IotaAPI extends IotaAPICore {
* @param start Starting key index.
* @param end Ending key index.
* @param threshold Min balance required.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified input is not valid.
**/
- public GetBalancesAndFormatResponse getInputs(String seed, int security, int start, int end, long threshold) throws InvalidSecurityLevelException, InvalidAddressException {
+ public GetBalancesAndFormatResponse getInputs(String seed, int security, int start, int end, long threshold) throws ArgumentException, ArgumentException {
// validate the seed
if ((!InputValidator.isValidSeed(seed))) {
@@ -505,7 +526,7 @@ public class IotaAPI extends IotaAPICore {
}
if (security < 1) {
- throw new InvalidSecurityLevelException();
+ throw new ArgumentException("Invalid security level provided");
}
// If start value bigger than end, return error
@@ -552,12 +573,12 @@ public class IotaAPI extends IotaAPICore {
* @param stopWatch the stopwatch.
* @param security The security level of private key / seed.
* @return Inputs object.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified security level is not valid.
**/
- public GetBalancesAndFormatResponse getBalanceAndFormat(final List addresses, long threshold, int start, StopWatch stopWatch, int security) throws InvalidSecurityLevelException {
+ public GetBalancesAndFormatResponse getBalanceAndFormat(final List addresses, long threshold, int start, StopWatch stopWatch, int security) throws ArgumentException, IllegalStateException {
if (security < 1) {
- throw new InvalidSecurityLevelException();
+ throw new ArgumentException("Invalid security level provided");
}
GetBalancesResponse getBalancesResponse = getBalances(100, addresses);
@@ -601,11 +622,13 @@ public class IotaAPI extends IotaAPICore {
*
* @param transaction The transaction encoded in trytes.
* @return an array of bundle, if there are multiple arrays it means that there are conflicting bundles.
- * @throws ArgumentException is thrown when an invalid argument is provided.
- * @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
- * @throws InvalidSignatureException is thrown when an invalid signature is encountered.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public GetBundleResponse getBundle(String transaction) throws ArgumentException, InvalidBundleException, InvalidSignatureException {
+ public GetBundleResponse getBundle(String transaction) throws ArgumentException {
+
+ if (!InputValidator.isHash(transaction)) {
+ throw new ArgumentException("Invalid hash provided");
+ }
Bundle bundle = traverseBundle(transaction, null, new Bundle());
if (bundle == null) {
@@ -657,17 +680,18 @@ public class IotaAPI extends IotaAPICore {
}
// Check for total sum, if not equal 0 return error
- if (totalSum != 0) throw new InvalidBundleException("Invalid Bundle Sum");
+ if (totalSum != 0) throw new ArgumentException("Invalid Bundle Sum");
int[] bundleFromTrxs = new int[243];
curl.squeeze(bundleFromTrxs);
String bundleFromTxString = Converter.trytes(bundleFromTrxs);
// Check if bundle hash is the same as returned by tx object
- if (!bundleFromTxString.equals(bundleHash)) throw new InvalidBundleException("Invalid Bundle Hash");
+ if (!bundleFromTxString.equals(bundleHash))
+ throw new ArgumentException("Invalid Bundle Hash");
// Last tx in the bundle should have currentIndex === lastIndex
bundle.setLength(bundle.getTransactions().size());
if (!(bundle.getTransactions().get(bundle.getLength() - 1).getCurrentIndex() == (bundle.getTransactions().get(bundle.getLength() - 1).getLastIndex())))
- throw new InvalidBundleException("Invalid Bundle");
+ throw new ArgumentException("Invalid Bundle");
// Validate the signatures
for (Signature aSignaturesToValidate : signaturesToValidate) {
@@ -675,7 +699,7 @@ public class IotaAPI extends IotaAPICore {
String address = aSignaturesToValidate.getAddress();
boolean isValidSignature = new Signing(customCurl.clone()).validateSignatures(address, signatureFragments, bundleHash);
- if (!isValidSignature) throw new InvalidSignatureException();
+ if (!isValidSignature) throw new ArgumentException("Invalid Signatures!");
}
return GetBundleResponse.create(bundle.getTransactions(), stopWatch.getElapsedTimeMili());
@@ -694,18 +718,9 @@ public class IotaAPI extends IotaAPICore {
* @param end Ending key index.
* @param inclusionStates If true, it gets the inclusion states of the transfers.
* @param threshold Min balance required.
- * @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
- * @throws ArgumentException is thrown when an invalid argument is provided.
- * @throws InvalidSignatureException is thrown when an invalid signature is encountered.
- * @throws InvalidTrytesException is thrown when invalid trytes is provided.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
- * @throws NoInclusionStatesException is thrown when it not possible to get a inclusion state.
- * @throws NoNodeInfoException is thrown when its not possible to get node info.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public GetAccountDataResponse getAccountData(String seed, int security, int index, boolean checksum, int total, boolean returnAll, int start, int end, boolean inclusionStates, long threshold)
- throws InvalidBundleException, ArgumentException, InvalidSignatureException,
- InvalidTrytesException, InvalidSecurityLevelException, InvalidAddressException, NoInclusionStatesException, NoNodeInfoException {
+ public GetAccountDataResponse getAccountData(String seed, int security, int index, boolean checksum, int total, boolean returnAll, int start, int end, boolean inclusionStates, long threshold) throws ArgumentException {
if (start > end || end > (start + 1000)) {
throw new ArgumentException("Invalid inputs provided");
@@ -727,11 +742,14 @@ public class IotaAPI extends IotaAPICore {
* @param depth The depth.
* @param minWeightMagnitude The minimum weight magnitude.
* @return Analyzed Transaction objects.
- * @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
- * @throws ArgumentException is thrown when an invalid argument is provided.
- * @throws InvalidSignatureException is thrown when an invalid signature is encountered.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public ReplayBundleResponse replayBundle(String transaction, int depth, int minWeightMagnitude) throws InvalidBundleException, ArgumentException, InvalidSignatureException, InvalidTrytesException {
+ public ReplayBundleResponse replayBundle(String transaction, int depth, int minWeightMagnitude) throws ArgumentException {
+
+ if (!InputValidator.isHash(transaction)) {
+ throw new ArgumentException("Invalid tail hash provided");
+ }
+
StopWatch stopWatch = new StopWatch();
List bundleTrytes = new ArrayList<>();
@@ -764,11 +782,9 @@ public class IotaAPI extends IotaAPICore {
*
* @param hashes The hashes.
* @return Inclusion state.
- * @throws NoNodeInfoException is thrown when its not possible to get node info.
*/
- public GetInclusionStateResponse getLatestInclusion(String[] hashes) throws NoNodeInfoException {
+ public GetInclusionStateResponse getLatestInclusion(String[] hashes) throws ArgumentException {
GetNodeInfoResponse getNodeInfoResponse = getNodeInfo();
- if (getNodeInfoResponse == null) throw new NoNodeInfoException();
String[] latestMilestone = {getNodeInfoResponse.getLatestSolidSubtangleMilestone()};
@@ -787,14 +803,9 @@ public class IotaAPI extends IotaAPICore {
* @param remainderAddress If defined, this remainderAddress will be used for sending the remainder value (of the inputs) to.
* @param validateInputs Whether or not to validate the balances of the provided inputs
* @return Array of valid Transaction objects.
- * @throws InvalidAddressException is thrown when the specified remainderAddress is not an valid remainderAddress.
- * @throws NotEnoughBalanceException is thrown when a transfer fails because their is not enough balance to perform the transfer.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
- * @throws InvalidTrytesException is thrown when invalid trytes is provided.
- * @throws InvalidAddressException is thrown when the specified remainderAddress is not an valid remainderAddress.
- * @throws InvalidTransferException is thrown when an invalid transfer is provided.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List transfers, List inputs, String remainderAddress, boolean validateInputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
+ public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List transfers, List inputs, String remainderAddress, boolean validateInputs) throws ArgumentException {
StopWatch stopWatch = new StopWatch();
@@ -820,7 +831,7 @@ public class IotaAPI extends IotaAPICore {
* @param bundleHash The bundle hashes.
* @param bundle List of bundles to be populated.
* @return Transaction objects.
- * @throws ArgumentException is thrown when an invalid argument is provided.
+ * @throws ArgumentException is thrown when an invalid input is provided.
*/
public Bundle traverseBundle(String trunkTx, String bundleHash, Bundle bundle) throws ArgumentException {
GetTrytesResponse gtr = getTrytes(trunkTx);
@@ -872,24 +883,24 @@ public class IotaAPI extends IotaAPICore {
* @param inputAddress Array of input addresses as well as the securitySum.
* @param remainderAddress Has to be generated by the cosigners before initiating the transfer, can be null if fully spent.
* @return Bundle of transaction objects.
- * @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when an invalid argument is provided.
+ * @throws IllegalStateException is thrown when a transfer fails because their is not enough balance to perform the transfer.
*/
public List initiateTransfer(int securitySum, final String inputAddress, String remainderAddress,
- final List transfers, boolean testMode) throws InvalidAddressException, InvalidBundleException, InvalidTransferException {
+ final List transfers, boolean testMode) throws ArgumentException {
// validate input address
if (!InputValidator.isAddress(inputAddress))
- throw new InvalidAddressException();
+ throw new ArgumentException("Invalid addresses provided");
// validate remainder address
if (remainderAddress != null && !InputValidator.isAddress(remainderAddress)) {
- throw new InvalidBundleException();
+ throw new ArgumentException("Invalid remainder addresses provided");
}
// Input validation of transfers object
if (!InputValidator.isTransfersCollectionValid(transfers)) {
- throw new InvalidTransferException();
+ throw new ArgumentException("Invalid transfers provided");
}
// Create a new bundle
@@ -964,7 +975,7 @@ public class IotaAPI extends IotaAPICore {
// Get inputs if we are sending tokens
if (totalValue != 0) {
- GetBalancesResponse balancesResponse = getBalances(100, new String[]{inputAddress});
+ GetBalancesResponse balancesResponse = getBalances(100, Collections.singletonList(inputAddress));
String[] balances = balancesResponse.getBalances();
long totalBalance = 0;
@@ -1028,9 +1039,8 @@ public class IotaAPI extends IotaAPICore {
* @param totalValue The total value.
* @param remainderAddress If defined, this address will be used for sending the remainder value (of the inputs) to.
* @param signatureFragments The signature fragments.
- * @throws NotEnoughBalanceException is thrown when a transfer fails because their is not enough balance to perform the transfer.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when an invalid argument is provided.
+ * @throws IllegalStateException is thrown when a transfer fails because their is not enough balance to perform the transfer.
*/
public List addRemainder(final String seed,
final int security,
@@ -1039,7 +1049,7 @@ public class IotaAPI extends IotaAPICore {
final String tag,
final long totalValue,
final String remainderAddress,
- final List signatureFragments) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException {
+ final List signatureFragments) throws ArgumentException {
long totalTransferValue = totalValue;
for (int i = 0; i < inputs.size(); i++) {
@@ -1083,7 +1093,7 @@ public class IotaAPI extends IotaAPICore {
totalTransferValue -= thisBalance;
}
}
- throw new NotEnoughBalanceException();
+ throw new IllegalStateException("Not enough balance");
}
public static class Builder extends IotaAPICore.Builder {
diff --git a/jota/src/main/java/jota/IotaAPICore.java b/jota/src/main/java/jota/IotaAPICore.java
index 0921e9e..b7765a8 100644
--- a/jota/src/main/java/jota/IotaAPICore.java
+++ b/jota/src/main/java/jota/IotaAPICore.java
@@ -2,9 +2,9 @@ package jota;
import jota.dto.request.*;
import jota.dto.response.*;
-import jota.error.InvalidApiVersionException;
-import jota.error.InvalidTrytesException;
+import jota.error.ArgumentException;
import jota.model.Transaction;
+import jota.utils.Checksum;
import jota.utils.InputValidator;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
@@ -19,6 +19,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@@ -57,20 +58,23 @@ public class IotaAPICore {
try {
final Response res = call.execute();
+ String error = "";
+
+ if (res.errorBody() != null) {
+ error = res.errorBody().string();
+ }
+
if (res.code() == 400) {
- if (res.errorBody().string().contains("Invalid API Version")) {
- try {
- throw new InvalidApiVersionException();
- } catch (InvalidApiVersionException e) {
- e.printStackTrace();
- }
- } else {
- throw new IllegalAccessError("400 " + res.errorBody().string());
+ try {
+ throw new ArgumentException(error);
+ } catch (ArgumentException e) {
+ e.printStackTrace();
}
+
} else if (res.code() == 401) {
- throw new IllegalAccessError("401 " + res.errorBody().string());
+ throw new IllegalAccessError("401 " + error);
} else if (res.code() == 500) {
- throw new IllegalAccessError("500 " + res.errorBody().string());
+ throw new IllegalAccessError("500 " + error);
}
return res;
} catch (IOException e) {
@@ -203,8 +207,15 @@ public class IotaAPICore {
* @param addresses A List of addresses.
* @return The transaction hashes which are returned depend on the input.
*/
- public FindTransactionResponse findTransactionsByAddresses(final String... addresses) {
- return findTransactions(addresses, null, null, null);
+ public FindTransactionResponse findTransactionsByAddresses(final String... addresses) throws ArgumentException {
+ List addressesWithoutChecksum = new ArrayList<>();
+
+ for (String address : addresses) {
+ String addressO = Checksum.removeChecksum(address);
+ addressesWithoutChecksum.add(addressO);
+ }
+
+ return findTransactions(addressesWithoutChecksum.toArray(new String[addressesWithoutChecksum.size()]), null, null, null);
}
/**
@@ -247,7 +258,17 @@ public class IotaAPICore {
* @param tips ThelList of tips (including milestones) you want to search for the inclusion state.
* @return The inclusion states of a set of transactions.
*/
- public GetInclusionStateResponse getInclusionStates(String[] transactions, String[] tips) {
+ public GetInclusionStateResponse getInclusionStates(String[] transactions, String[] tips) throws ArgumentException {
+
+ if (!InputValidator.isArrayOfHashes(transactions)) {
+ throw new ArgumentException("Invalid hash provided");
+ }
+
+ if (!InputValidator.isArrayOfHashes(tips)) {
+ throw new ArgumentException("Invalid hash provided");
+ }
+
+
final Call res = service.getInclusionStates(IotaGetInclusionStateRequest
.createGetInclusionStateRequest(transactions, tips));
return wrapCheckedException(res).body();
@@ -259,12 +280,16 @@ public class IotaAPICore {
* @param hashes The of transaction hashes of which you want to get trytes from.
* @return The the raw transaction data (trytes) of a specific transaction.
*/
- public GetTrytesResponse getTrytes(String... hashes) {
+ public GetTrytesResponse getTrytes(String... hashes) throws ArgumentException {
+
+ if (!InputValidator.isArrayOfHashes(hashes)) {
+ throw new ArgumentException("Invalid hash provided");
+ }
+
final Call res = service.getTrytes(IotaGetTrytesRequest.createGetTrytesRequest(hashes));
return wrapCheckedException(res).body();
}
-
/**
* Tip selection which returns trunkTransaction and branchTransaction. The input value is the latest coordinator milestone, as provided through the getNodeInfo API call.
*
@@ -283,7 +308,7 @@ public class IotaAPICore {
* @param addresses The array list of addresses you want to get the confirmed balance from.
* @return The confirmed balance which a list of addresses have at the latest confirmed milestone.
*/
- public GetBalancesResponse getBalances(Integer threshold, String[] addresses) {
+ private GetBalancesResponse getBalances(Integer threshold, String[] addresses) {
final Call res = service.getBalances(IotaGetBalancesRequest.createIotaGetBalancesRequest(threshold, addresses));
return wrapCheckedException(res).body();
}
@@ -295,8 +320,15 @@ public class IotaAPICore {
* @param addresses The list of addresses you want to get the confirmed balance from.
* @return The confirmed balance which a list of addresses have at the latest confirmed milestone.
*/
- public GetBalancesResponse getBalances(Integer threshold, List addresses) {
- return getBalances(threshold, addresses.toArray(new String[]{}));
+ public GetBalancesResponse getBalances(Integer threshold, List addresses) throws ArgumentException {
+
+ List addressesWithoutChecksum = new ArrayList<>();
+
+ for (String address : addresses) {
+ String addressO = Checksum.removeChecksum(address);
+ addressesWithoutChecksum.add(addressO);
+ }
+ return getBalances(threshold, addressesWithoutChecksum.toArray(new String[]{}));
}
/**
@@ -307,9 +339,18 @@ public class IotaAPICore {
* @param minWeightMagnitude The Proof of Work intensity.
* @param trytes A List of trytes (raw transaction data) to attach to the tangle.
*/
- public GetAttachToTangleResponse attachToTangle(String trunkTransaction, String branchTransaction, Integer minWeightMagnitude, String... trytes) throws InvalidTrytesException {
+ public GetAttachToTangleResponse attachToTangle(String trunkTransaction, String branchTransaction, Integer minWeightMagnitude, String... trytes) throws ArgumentException {
+
+ if (!InputValidator.isHash(trunkTransaction)) {
+ throw new ArgumentException("Invalid hash provided");
+ }
+
+ if (!InputValidator.isHash(branchTransaction)) {
+ throw new ArgumentException("Invalid hash provided");
+ }
+
if (!InputValidator.isArrayOfTrytes(trytes)) {
- throw new InvalidTrytesException();
+ throw new ArgumentException("Invalid trytes provided");
}
if (localPoW != null) {
@@ -347,7 +388,12 @@ public class IotaAPICore {
*
* @param trytes The list of raw data of transactions to be rebroadcast.
*/
- public BroadcastTransactionsResponse broadcastTransactions(String... trytes) {
+ public BroadcastTransactionsResponse broadcastTransactions(String... trytes) throws ArgumentException {
+
+ if (!InputValidator.isArrayOfAttachedTrytes(trytes)) {
+ throw new ArgumentException("Invalid trytes provided");
+ }
+
final Call res = service.broadcastTransactions(IotaBroadcastTransactionRequest.createBroadcastTransactionsRequest(trytes));
return wrapCheckedException(res).body();
}
diff --git a/jota/src/main/java/jota/error/BroadcastAndStoreException.java b/jota/src/main/java/jota/error/BroadcastAndStoreException.java
deleted file mode 100644
index 8ad2c20..0000000
--- a/jota/src/main/java/jota/error/BroadcastAndStoreException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exceptions occurs if its not possible to broadcast and store.
- *
- * @author Adrian
- */
-public class BroadcastAndStoreException extends BaseException {
-
- /**
- * Initializes a new instance of the BroadcastAndStoreException.
- */
- public BroadcastAndStoreException() {
- super("Impossible to broadcastAndStore, aborting.");
- }
-}
\ No newline at end of file
diff --git a/jota/src/main/java/jota/error/InvalidAddressException.java b/jota/src/main/java/jota/error/InvalidAddressException.java
deleted file mode 100644
index 9c6b591..0000000
--- a/jota/src/main/java/jota/error/InvalidAddressException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when an invalid address is provided.
- *
- * @author Adrian
- */
-public class InvalidAddressException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidAddressException.
- */
- public InvalidAddressException() {
- super("Invalid Address!");
- }
-}
diff --git a/jota/src/main/java/jota/error/InvalidApiVersionException.java b/jota/src/main/java/jota/error/InvalidApiVersionException.java
deleted file mode 100644
index e5776af..0000000
--- a/jota/src/main/java/jota/error/InvalidApiVersionException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
- /**
- * This exception occurs when invalid api version is provided.
- *
- * @author pinpong
- */
- public class InvalidApiVersionException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidApiVersionException.
- */
- public InvalidApiVersionException() {
- super("Invalid api version");
- }
-}
diff --git a/jota/src/main/java/jota/error/InvalidBundleException.java b/jota/src/main/java/jota/error/InvalidBundleException.java
deleted file mode 100644
index 55da93b..0000000
--- a/jota/src/main/java/jota/error/InvalidBundleException.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package jota.error;
-
-/**
- * This exceptions occurs if an invalid bundle was found or provided.
- *
- * @author Adrian
- */
-public class InvalidBundleException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidBundleException.
- */
- public InvalidBundleException() {
- super("Invalid Bundle");
- }
-
- /**
- * Initializes a new instance of the InvalidBundleException.
- */
- public InvalidBundleException(String msg) {
- super(msg);
- }
-}
diff --git a/jota/src/main/java/jota/error/InvalidSecurityLevelException.java b/jota/src/main/java/jota/error/InvalidSecurityLevelException.java
deleted file mode 100644
index b48e6af..0000000
--- a/jota/src/main/java/jota/error/InvalidSecurityLevelException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when an invalid security level is provided.
- *
- * @author pinpong
- */
-public class InvalidSecurityLevelException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidSecurityLevelException.
- */
- public InvalidSecurityLevelException() {
- super("Invalid security level");
- }
-}
diff --git a/jota/src/main/java/jota/error/InvalidSignatureException.java b/jota/src/main/java/jota/error/InvalidSignatureException.java
deleted file mode 100644
index 79944ea..0000000
--- a/jota/src/main/java/jota/error/InvalidSignatureException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when an invalid signature is encountered.
- *
- * @author Adrian
- */
-public class InvalidSignatureException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidSignatureException.
- */
- public InvalidSignatureException() {
- super("Invalid Signatures!");
- }
-}
diff --git a/jota/src/main/java/jota/error/InvalidTransferException.java b/jota/src/main/java/jota/error/InvalidTransferException.java
deleted file mode 100644
index 0da3d9b..0000000
--- a/jota/src/main/java/jota/error/InvalidTransferException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when an invalid transfer is provided.
- *
- * @author pinpong
- */
-public class InvalidTransferException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidTransferException.
- */
- public InvalidTransferException() {
- super("Invalid Transfer!");
- }
-}
diff --git a/jota/src/main/java/jota/error/InvalidTrytesException.java b/jota/src/main/java/jota/error/InvalidTrytesException.java
deleted file mode 100644
index de97ff0..0000000
--- a/jota/src/main/java/jota/error/InvalidTrytesException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when invalid trytes is provided.
- *
- * @author Adrian
- */
-public class InvalidTrytesException extends BaseException {
-
- /**
- * Initializes a new instance of the InvalidTrytesException.
- */
- public InvalidTrytesException() {
- super("Invalid input trytes");
- }
-}
\ No newline at end of file
diff --git a/jota/src/main/java/jota/error/NoInclusionStatesException.java b/jota/src/main/java/jota/error/NoInclusionStatesException.java
deleted file mode 100644
index 65dd2d4..0000000
--- a/jota/src/main/java/jota/error/NoInclusionStatesException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when it not possible to get a inclusion state.
- *
- * @author Adrian
- */
-public class NoInclusionStatesException extends BaseException {
-
- /**
- * Initializes a new instance of the NoInclusionStatesException.
- */
- public NoInclusionStatesException() {
- super("No inclusion states for the provided seed");
- }
-}
diff --git a/jota/src/main/java/jota/error/NoNodeInfoException.java b/jota/src/main/java/jota/error/NoNodeInfoException.java
deleted file mode 100644
index fba5f37..0000000
--- a/jota/src/main/java/jota/error/NoNodeInfoException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when its not possible to get node info.
- *
- * @author Adrian
- */
-public class NoNodeInfoException extends BaseException {
-
- /**
- * Initializes a new instance of the NoNodeInfoException.
- */
- public NoNodeInfoException() {
- super("Node info could not be retrieved");
- }
-}
\ No newline at end of file
diff --git a/jota/src/main/java/jota/error/NotEnoughBalanceException.java b/jota/src/main/java/jota/error/NotEnoughBalanceException.java
deleted file mode 100644
index 3abe9f8..0000000
--- a/jota/src/main/java/jota/error/NotEnoughBalanceException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package jota.error;
-
-/**
- * This exception occurs when a transfer fails because their is not enough balance to perform the transfer.
- *
- * @author Adrian
- */
-public class NotEnoughBalanceException extends BaseException {
-
- /**
- * Serial version UID
- */
- private static final long serialVersionUID = -3807270816402226476L;
-
- /**
- * Initializes a new instance of the NotEnoughBalanceException.
- */
- public NotEnoughBalanceException() {
- super("Not enough balance");
- }
-}
diff --git a/jota/src/main/java/jota/utils/Checksum.java b/jota/src/main/java/jota/utils/Checksum.java
index 516a007..8fd9134 100644
--- a/jota/src/main/java/jota/utils/Checksum.java
+++ b/jota/src/main/java/jota/utils/Checksum.java
@@ -1,6 +1,6 @@
package jota.utils;
-import jota.error.InvalidAddressException;
+import jota.error.ArgumentException;
import jota.pow.ICurl;
import jota.pow.JCurl;
import jota.pow.SpongeFactory;
@@ -17,9 +17,9 @@ public class Checksum {
*
* @param address The address without checksum.
* @return The address with the appended checksum.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when the specified address is not an valid address.
**/
- public static String addChecksum(String address) throws InvalidAddressException {
+ public static String addChecksum(String address) throws ArgumentException {
InputValidator.checkAddress(address);
String addressWithChecksum = address;
addressWithChecksum += calculateChecksum(address);
@@ -31,15 +31,15 @@ public class Checksum {
*
* @param address The address with checksum.
* @return The address without checksum.
- * @throws InvalidAddressException is thrown when the specified address is not an address with checksum.
+ * @throws ArgumentException is thrown when the specified address is not an address with checksum.
**/
- public static String removeChecksum(String address) throws InvalidAddressException {
+ public static String removeChecksum(String address) throws ArgumentException {
if (isAddressWithChecksum(address)) {
return removeChecksumFromAddress(address);
} else if (isAddressWithoutChecksum(address)) {
return address;
}
- throw new InvalidAddressException();
+ throw new ArgumentException("Invalid addresses provided");
}
private static String removeChecksumFromAddress(String addressWithChecksum) {
@@ -51,9 +51,9 @@ public class Checksum {
*
* @param addressWithChecksum The address with checksum.
* @return true if the specified address with checksum has a valid checksum [the specified address with checksum]; otherwise, false.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when the specified address is not an valid address.
**/
- public static boolean isValidChecksum(String addressWithChecksum) throws InvalidAddressException {
+ public static boolean isValidChecksum(String addressWithChecksum) throws ArgumentException {
String addressWithoutChecksum = removeChecksum(addressWithChecksum);
String addressWithRecalculateChecksum = addressWithoutChecksum += calculateChecksum(addressWithoutChecksum);
return addressWithRecalculateChecksum.equals(addressWithChecksum);
@@ -64,9 +64,9 @@ public class Checksum {
*
* @param address The address to check.
* @return true if the specified address is with checksum ; otherwise, false.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when the specified address is not an valid address.
**/
- public static boolean isAddressWithChecksum(String address) throws InvalidAddressException {
+ public static boolean isAddressWithChecksum(String address) throws ArgumentException {
return InputValidator.checkAddress(address) && address.length() == Constants.ADDRESS_LENGTH_WITH_CHECKSUM;
}
@@ -75,9 +75,9 @@ public class Checksum {
*
* @param address The address to check.
* @return true if the specified address is without checksum ; otherwise, false.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when the specified address is not an valid address.
**/
- public static boolean isAddressWithoutChecksum(String address) throws InvalidAddressException {
+ public static boolean isAddressWithoutChecksum(String address) throws ArgumentException {
return InputValidator.checkAddress(address) && address.length() == Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM;
}
diff --git a/jota/src/main/java/jota/utils/InputValidator.java b/jota/src/main/java/jota/utils/InputValidator.java
index 0f29499..21b0f03 100644
--- a/jota/src/main/java/jota/utils/InputValidator.java
+++ b/jota/src/main/java/jota/utils/InputValidator.java
@@ -1,6 +1,6 @@
package jota.utils;
-import jota.error.InvalidAddressException;
+import jota.error.ArgumentException;
import jota.model.Transfer;
import org.apache.commons.lang3.math.NumberUtils;
@@ -30,7 +30,7 @@ public class InputValidator {
* @param addresses The address list to validate.
* @return true if the specified addresses are valid; otherwise, false.
**/
- public static boolean isAddressesCollectionValid(final List addresses) throws InvalidAddressException {
+ public static boolean isAddressesCollectionValid(final List addresses) throws ArgumentException {
for (final String address : addresses) {
if (!checkAddress(address)) {
return false;
@@ -44,11 +44,11 @@ public class InputValidator {
*
* @param address The address to validate.
* @return true if the specified string is an address; otherwise, false.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
+ * @throws ArgumentException is thrown when the specified input is not valid.
**/
- public static boolean checkAddress(String address) throws InvalidAddressException {
+ public static boolean checkAddress(String address) throws ArgumentException {
if (!isAddress(address)) {
- throw new InvalidAddressException();
+ throw new ArgumentException("Invalid addresses provided");
}
return true;
}
@@ -82,7 +82,7 @@ public class InputValidator {
* @return true the specified string represents an integer value; otherwise, false.
**/
public static boolean isValue(final String value) {
- return NumberUtils.isNumber(value);
+ return NumberUtils.isCreatable(value);
}
/**
@@ -132,11 +132,11 @@ public class InputValidator {
* @param transfers The transfers list to validate.
* @return true if the specified transfers are valid; otherwise, false.
**/
- public static boolean isTransfersCollectionValid(final List transfers) {
+ public static boolean isTransfersCollectionValid(final List transfers) throws ArgumentException {
// Input validation of transfers object
if (transfers == null || transfers.isEmpty()) {
- throw new IllegalArgumentException("No transfer provided");
+ throw new ArgumentException("No transfer provided");
}
for (final Transfer transfer : transfers) {
@@ -186,4 +186,57 @@ public class InputValidator {
public static boolean isValidSeed(String seed) {
return isTrytes(seed, seed.length());
}
+
+ /**
+ * Checks if input is correct hashes.
+ *
+ * @param hashes The hashes list to validate.
+ * @return true if the specified hashes are valid; otherwise, false.
+ **/
+ public static boolean isHashes(List hashes) {
+ for (String hash : hashes) {
+ if (!isTrytes(hash, 81)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Checks if input is correct hash.
+ *
+ * @param hash The hash to validate.
+ * @return true if the specified hash are valid; otherwise, false.
+ **/
+ public static boolean isHash(String hash) {
+ if (!isTrytes(hash, 81)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Checks if attached trytes if last 241 trytes are non-zero
+ *
+ * @param trytes The trytes.
+ * @return true if the specified trytes are valid; otherwise, false.
+ **/
+ public static boolean isArrayOfAttachedTrytes(String[] trytes) {
+
+ for (String tryteValue : trytes) {
+
+ // Check if correct 2673 trytes
+ if (!isTrytes(tryteValue, 2673)) {
+ return false;
+ }
+
+ String lastTrytes = tryteValue.substring(2673 - (3 * 81));
+
+ if (lastTrytes.matches("[9]+")) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
diff --git a/jota/src/main/java/jota/utils/IotaAPIUtils.java b/jota/src/main/java/jota/utils/IotaAPIUtils.java
index bea27c7..134a490 100644
--- a/jota/src/main/java/jota/utils/IotaAPIUtils.java
+++ b/jota/src/main/java/jota/utils/IotaAPIUtils.java
@@ -1,7 +1,6 @@
package jota.utils;
-import jota.error.InvalidAddressException;
-import jota.error.InvalidSecurityLevelException;
+import jota.error.ArgumentException;
import jota.model.Bundle;
import jota.model.Input;
import jota.model.Transaction;
@@ -28,13 +27,12 @@ public class IotaAPIUtils {
* @param checksum The adds 9-tryte address checksum
* @param curl The curl instance.
* @return An String with address.
- * @throws InvalidAddressException is thrown when the specified address is not an valid address.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified input is not valid.
*/
- public static String newAddress(String seed, int security, int index, boolean checksum, ICurl curl) throws InvalidAddressException, InvalidSecurityLevelException {
+ public static String newAddress(String seed, int security, int index, boolean checksum, ICurl curl) throws ArgumentException {
if (security < 1) {
- throw new InvalidSecurityLevelException();
+ throw new ArgumentException("Invalid security level provided");
}
Signing signing = new Signing(curl);
@@ -53,7 +51,7 @@ public class IotaAPIUtils {
public static List signInputsAndReturn(final String seed,
final List inputs,
final Bundle bundle,
- final List signatureFragments, ICurl curl) throws InvalidSecurityLevelException {
+ final List signatureFragments, ICurl curl) throws ArgumentException {
bundle.finalize(curl);
bundle.addTrytes(signatureFragments);
diff --git a/jota/src/main/java/jota/utils/Multisig.java b/jota/src/main/java/jota/utils/Multisig.java
index e3c82a8..96e0474 100644
--- a/jota/src/main/java/jota/utils/Multisig.java
+++ b/jota/src/main/java/jota/utils/Multisig.java
@@ -1,6 +1,6 @@
package jota.utils;
-import jota.error.InvalidSecurityLevelException;
+import jota.error.ArgumentException;
import jota.model.Bundle;
import jota.pow.ICurl;
import jota.pow.SpongeFactory;
@@ -36,9 +36,9 @@ public class Multisig {
* @param security Secuirty level of private key / seed.
* @param index Key index to start search from. If the index is provided, the generation of the address is not deterministic.
* @return trytes
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified security level is not valid.
**/
- public String getDigest(String seed, int security, int index) throws InvalidSecurityLevelException {
+ public String getDigest(String seed, int security, int index) throws ArgumentException {
int[] key = signingInstance.key(Converter.trits(seed, 243), index, security);
return Converter.trytes(signingInstance.digests(key));
}
@@ -75,10 +75,10 @@ public class Multisig {
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred
* @param index Key index to start search from. If the index is provided, the generation of the address is not deterministic.
* @return trytes.
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified security level is not valid.
**/
- public String getKey(String seed, int index, int security) throws InvalidSecurityLevelException {
+ public String getKey(String seed, int index, int security) throws ArgumentException {
return Converter.trytes(signingInstance.key(Converter.trits(seed, 81 * security), index, security));
}
diff --git a/jota/src/main/java/jota/utils/Signing.java b/jota/src/main/java/jota/utils/Signing.java
index 37bd519..ea79d4e 100644
--- a/jota/src/main/java/jota/utils/Signing.java
+++ b/jota/src/main/java/jota/utils/Signing.java
@@ -1,6 +1,6 @@
package jota.utils;
-import jota.error.InvalidSecurityLevelException;
+import jota.error.ArgumentException;
import jota.model.Bundle;
import jota.model.Transaction;
import jota.pow.ICurl;
@@ -36,11 +36,11 @@ public class Signing {
* @param index
* @param security
* @return
- * @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
+ * @throws ArgumentException is thrown when the specified security level is not valid.
*/
- public int[] key(final int[] inSeed, final int index, int security) throws InvalidSecurityLevelException {
+ public int[] key(final int[] inSeed, final int index, int security) throws ArgumentException {
if (security < 1) {
- throw new InvalidSecurityLevelException();
+ throw new ArgumentException("Invalid security level provided");
}
int[] seed = inSeed.clone();
diff --git a/jota/src/test/java/jota/ChecksumTest.java b/jota/src/test/java/jota/ChecksumTest.java
index 9e4a1ff..4c5d00b 100644
--- a/jota/src/test/java/jota/ChecksumTest.java
+++ b/jota/src/test/java/jota/ChecksumTest.java
@@ -1,6 +1,6 @@
package jota;
-import jota.error.InvalidAddressException;
+import jota.error.ArgumentException;
import jota.utils.Checksum;
import org.junit.Test;
@@ -15,17 +15,17 @@ public class ChecksumTest {
private static final String TEST_ADDRESS_WITH_CHECKSUM = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
@Test
- public void shouldAddChecksum() throws InvalidAddressException {
+ public void shouldAddChecksum() throws ArgumentException {
assertEquals(Checksum.addChecksum(TEST_ADDRESS_WITHOUT_CHECKSUM), TEST_ADDRESS_WITH_CHECKSUM);
}
@Test
- public void shouldRemoveChecksum() throws InvalidAddressException {
+ public void shouldRemoveChecksum() throws ArgumentException {
assertEquals(Checksum.removeChecksum(TEST_ADDRESS_WITH_CHECKSUM), TEST_ADDRESS_WITHOUT_CHECKSUM);
}
@Test
- public void shouldIsValidChecksum() throws InvalidAddressException {
+ public void shouldIsValidChecksum() throws ArgumentException {
assertEquals(Checksum.isValidChecksum(TEST_ADDRESS_WITH_CHECKSUM), true);
}
}
diff --git a/jota/src/test/java/jota/InputValidatorTest.java b/jota/src/test/java/jota/InputValidatorTest.java
index 89ff32d..087a29e 100644
--- a/jota/src/test/java/jota/InputValidatorTest.java
+++ b/jota/src/test/java/jota/InputValidatorTest.java
@@ -1,6 +1,6 @@
package jota;
-import jota.error.InvalidAddressException;
+import jota.error.ArgumentException;
import jota.model.Transfer;
import jota.utils.InputValidator;
import org.junit.Test;
@@ -28,7 +28,7 @@ public class InputValidatorTest {
}
@Test
- public void shouldCheckAddress() throws InvalidAddressException {
+ public void shouldCheckAddress() throws ArgumentException {
assertEquals(InputValidator.checkAddress(TEST_ADDRESS_WITHOUT_CHECKSUM), true);
}
@@ -48,7 +48,7 @@ public class InputValidatorTest {
}
@Test
- public void shouldIsTransfersCollectionCorrect() {
+ public void shouldIsTransfersCollectionCorrect() throws ArgumentException {
List transfers = new ArrayList<>();
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, "", ""));
diff --git a/jota/src/test/java/jota/IotaAPITest.java b/jota/src/test/java/jota/IotaAPITest.java
index ac84c7c..4a72b8b 100644
--- a/jota/src/test/java/jota/IotaAPITest.java
+++ b/jota/src/test/java/jota/IotaAPITest.java
@@ -2,7 +2,7 @@ package jota;
import com.google.gson.Gson;
import jota.dto.response.*;
-import jota.error.*;
+import jota.error.ArgumentException;
import jota.model.Bundle;
import jota.model.Input;
import jota.model.Transaction;
@@ -37,7 +37,7 @@ public class IotaAPITest {
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_3 = "ASCZZOBQDMNHLELQKWJBMRETMHBTF9V9TNKYDIFW9PDXPUHPVVGHMSWPVMNJHSJF99QFCMNTPCPGS9DT9";
private static final String TEST_HASH = "BKBALUPMEECOGEYQU9OHXTFTHV9OKEVUGHAUNNQCNETAQWIRJIKDGWSWXY9RSIMZJBPIPEIQEFEIA9999";
private static final String TEST_INVALID_TRYTES = "BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWR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PAGMT9CAYIIMTTBCPKWTYHOJIIY9GYNPAJNUJ9BKYYXSV9JSPEXYMCFAIKTGNRSQGUNIYZCRT9FOWENSZQPD9ALUPYYAVICHVYELYFPUYDTWUSWNIYFXPX9MICCCOOZIWRNJIDALWGWRATGLJXNAYTNIZWQ9YTVDBOFZRKO9CFWRPAQQRXTPACOWCPRLYRYSJARRKSQPR9TCFXDVIXLP9XVL99ERRDSOHBFJDJQQGGGCZNDQ9NYCTQJWVZIAELCRBJJFDMCNZU9FIZRPGNURTXOCDSQGXTQHKHUECGWFUUYS9J9NYQ9U9P9UUP9YMZHWWWCIASCFLCMSKTELZWUGCDE9YOKVOVKTAYPHDF9ZCCQAYPJIJNGSHUIHHCOSSOOBUDOKE9CJZGYSSGNCQJVBEFTZFJ9SQUHOASKRRGBSHWKBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCH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CYRHMJWPIKJYAYTALAAZROZYCMQKWBSFUGHFSOGGTCQDHWJU9VJGCAHJLHSORFKVJKV9RSZHLJZTDJJGOXTRLKNJORWYPW9UKRZROJONZQWJNUEPBZZJYBJJNCAQOEYTHFWVUBACCFTREABOZKQEKSMDAFECVGMGELNZUFZJHWHNXLBOSHLNBPGSQDVLZLBUXWINABWYBDMZNIYNVPYLRKUULTMNNKZUFNQOQKROJSXWYTBRDSJQKTOUXLMXVCVIXEYPZWBSMEXMBGUIVACRTGKDEIYZKP9KQCQXPWRXNLGQOATRHCXJFQINXFYQIDTPUJVXKUYVRYHWDHWSNLWUFPNNJZVNMRFWPZBJCRRSHMHUG9NKKH9SOXTUJUAXBF9MHYWHJ9ZTJRUQFKRLHMNVPWX9XFXLMVJAGASMWMIFYUZFAUCEIOOYMEYWOIZTNEWFVZKOQFECWEPSMOYFSJJKEJQMPSXGE9WTYRQJVMHUQZFD9MJUFFCNSGAZCTXYPIJFNSXAUCYPGZMNWMQWSWCKAQYKXJTWINSGPPZG9HLDLEAWUWEVCTVRCBDFOXKUROXH9HXXAXVPEJFRSLOGRVGYZASTEBAQNXJJROCYRTDPYFUIQJVDHAKEG9YACV9HCPJUEUKOYFNWDXCCJBIFQKYOXGRDHVTHEQUMHO999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999DNVEZXD99A99999999A99999999BULMKQXROXEBHPBYGKQINYJTHPTL9OGKUFBFAVRHPZSNXBUDMNRJFYIIGWOFVCXSVFQRZMPGCZMZUNKCDDRWDLKTKCZXZFMIZ9CZBWNOJGSXHBKEXCFQPBNFAE9QAVRX9SWGEZQRSYAYNW9TPWVWCJXAUPQHYZ9999NBDPASDXMXDCHLMZJIBHAZREUBOTZZAYGKCWTBSBKKETULAPABDTY9AMPBSXO9KJOLCWJMJSZFKU999999999999999999999999999999999999999999999999999999999999CWJQRPBIJGTWQTCMDUVOCBUAMH";
+ private static final String TEST_TRYTES = "CCWCXCGDEAXCGDEAPCEAHDTCGDHDRAADTCGDGDPCVCTC9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999WITPXKWONPNUPBESJTXQTZTFXFSTDUWVGYHW9VRDULWGBKDVAAJLOSAEPUSCMSOIYLKMIZLPEKAOYAXMWFLDKQJI99999999999999999999UUC9999999999999999FUCK9YOUIVBUGXD99999999999B99999999IDPWGXASJFLLGCDGPQVXYGSNUESCZQCEKVREGLZX9FCYQVUWESEKWSMHZTGMJLGBOLKU9GILFITSJLZBWEHH9RSRNBPSKKUZBBJDSYHYWYHLJUOAFCKMXGTRFTZHKKWSVKGRHHJECSILLLZXKYJAYAQYEOINSZ9999OCYREQNINOB9XMLJOXMDFJDTXYO9PANNXQSW9HPFAAHEPTSPHTNEBOFFNRPKSUQNTKSACROOJPXF99999UUC9999999999999999FUCK9YOUPNMHCEJIE999999999L99999999IGMVBPROUATGVGQTHYIYFVQETRW";
private static final String TEST_MESSAGE = "JUSTANOTHERJOTATEST";
private static final String TEST_TAG = "JOTASPAM9999999999999999999";
private static final int MIN_WEIGHT_MAGNITUDE = 14;
@@ -113,7 +113,7 @@ public class IotaAPITest {
}
@Test
- public void shouldGetInputs() throws InvalidSecurityLevelException, InvalidAddressException {
+ public void shouldGetInputs() throws ArgumentException, ArgumentException {
GetBalancesAndFormatResponse res = iotaAPI.getInputs(TEST_SEED1, 2, 0, 0, 0);
System.out.println(res);
assertThat(res, IsNull.notNullValue());
@@ -122,7 +122,7 @@ public class IotaAPITest {
}
@Test
- public void shouldCreateANewAddressWithChecksum() throws InvalidSecurityLevelException, InvalidAddressException {
+ public void shouldCreateANewAddressWithChecksum() throws ArgumentException, ArgumentException {
final GetNewAddressResponse res1 = iotaAPI.getNewAddress(TEST_SEED1, 1, 0, true, 5, false);
assertThat(res1.getAddresses().get(0), Is.is(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_1));
@@ -134,7 +134,7 @@ public class IotaAPITest {
}
@Test
- public void shouldCreateANewAddressWithoutChecksum() throws InvalidSecurityLevelException, InvalidAddressException {
+ public void shouldCreateANewAddressWithoutChecksum() throws ArgumentException, ArgumentException {
final GetNewAddressResponse res1 = iotaAPI.getNewAddress(TEST_SEED1, 1, 0, false, 5, false);
assertThat(res1.getAddresses().get(0), Is.is(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_1));
@@ -146,13 +146,13 @@ public class IotaAPITest {
}
@Test
- public void shouldCreate100Addresses() throws InvalidSecurityLevelException, InvalidAddressException {
+ public void shouldCreate100Addresses() throws ArgumentException {
GetNewAddressResponse res = iotaAPI.getNewAddress(TEST_SEED1, 2, 0, false, 100, false);
assertEquals(res.getAddresses().size(), 100);
}
@Test
- public void shouldPrepareTransfer() throws InvalidSecurityLevelException, NotEnoughBalanceException, InvalidAddressException, InvalidTransferException {
+ public void shouldPrepareTransfer() throws ArgumentException {
List inputlist = new ArrayList<>();
List transfers = new ArrayList<>();
@@ -173,39 +173,39 @@ public class IotaAPITest {
}
@Test
- public void shouldGetLastInclusionState() throws NoNodeInfoException {
+ public void shouldGetLastInclusionState() throws ArgumentException {
GetInclusionStateResponse res = iotaAPI.getLatestInclusion(new String[]{TEST_HASH});
assertThat(res.getStates(), IsNull.notNullValue());
}
@Test
- public void shouldFindTransactionObjects() {
- List ftr = iotaAPI.findTransactionObjects(TEST_ADDRESSES);
+ public void shouldFindTransactionObjects() throws ArgumentException {
+ List ftr = iotaAPI.findTransactionObjectsByAddresses(TEST_ADDRESSES);
System.out.println(ftr);
assertThat(ftr, IsNull.notNullValue());
}
@Test
- public void shouldGetAccountData() throws NoInclusionStatesException, InvalidTrytesException, NoNodeInfoException, ArgumentException, InvalidBundleException, InvalidSecurityLevelException, InvalidAddressException, InvalidSignatureException {
+ public void shouldGetAccountData() throws ArgumentException {
GetAccountDataResponse gad = iotaAPI.getAccountData(TEST_SEED1, 2, 0, true, 0, true, 0, 0, true, 0);
assertThat(gad, IsNull.notNullValue());
}
- @Test(expected = IllegalAccessError.class)
- public void shouldNotGetBundle() throws InvalidBundleException, ArgumentException, InvalidSignatureException {
+ @Test(expected = ArgumentException.class)
+ public void shouldNotGetBundle() throws ArgumentException {
GetBundleResponse gbr = iotaAPI.getBundle("SADASD");
assertThat(gbr, IsNull.notNullValue());
}
@Test
- public void shouldGetBundle() throws InvalidBundleException, ArgumentException, InvalidSignatureException {
+ public void shouldGetBundle() throws ArgumentException {
GetBundleResponse gbr = iotaAPI.getBundle(TEST_HASH);
System.out.println(gbr);
assertThat(gbr, IsNull.notNullValue());
}
@Test
- public void shouldGetTransfers() throws InvalidBundleException, ArgumentException, InvalidSignatureException, NoInclusionStatesException, NoNodeInfoException, InvalidSecurityLevelException, InvalidAddressException {
+ public void shouldGetTransfers() throws ArgumentException {
GetTransferResponse gtr = iotaAPI.getTransfers(TEST_SEED1, 2, 0, 0, false);
assertThat(gtr.getTransfers(), IsNull.notNullValue());
System.out.println(gtr);
@@ -219,32 +219,36 @@ public class IotaAPITest {
@Ignore
@Test
- public void shouldReplayBundle() throws InvalidTrytesException, InvalidBundleException, InvalidSignatureException, ArgumentException {
+ public void shouldReplayBundle() throws ArgumentException {
ReplayBundleResponse rbr = iotaAPI.replayBundle(TEST_HASH, DEPTH, MIN_WEIGHT_MAGNITUDE);
assertThat(rbr, IsNull.notNullValue());
}
@Ignore
- @Test(expected = InvalidTrytesException.class)
- public void shouldNotSendTrytes() throws InvalidTrytesException {
+ @Test(expected = ArgumentException.class)
+ public void shouldNotSendTrytes() throws ArgumentException {
iotaAPI.sendTrytes(new String[]{TEST_INVALID_TRYTES}, DEPTH, MIN_WEIGHT_MAGNITUDE);
}
@Test()
- public void shouldGetTrytes() throws InvalidTrytesException {
+ public void shouldGetTrytes() throws ArgumentException {
System.out.println(iotaAPI.getTrytes(TEST_HASH));
}
+ @Test()
+ public void shouldBroadcastAndStore() throws ArgumentException {
+ System.out.println(iotaAPI.broadcastAndStore(TEST_TRYTES));
+ }
@Ignore
@Test
- public void shouldSendTrytes() throws InvalidTrytesException {
+ public void shouldSendTrytes() throws ArgumentException {
iotaAPI.sendTrytes(new String[]{TEST_TRYTES}, DEPTH, MIN_WEIGHT_MAGNITUDE);
}
@Ignore
@Test(expected = IllegalStateException.class)
- public void shouldNotSendTransfer() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
+ public void shouldNotSendTransfer() throws ArgumentException {
List transfers = new ArrayList<>();
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 2, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
@@ -254,7 +258,7 @@ public class IotaAPITest {
@Ignore
@Test
- public void shouldSendTransferWithoutInputs() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
+ public void shouldSendTransferWithoutInputs() throws ArgumentException {
List transfers = new ArrayList<>();
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 1, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
@@ -264,7 +268,7 @@ public class IotaAPITest {
@Ignore
@Test
- public void shouldSendTransferWithInputs() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
+ public void shouldSendTransferWithInputs() throws ArgumentException {
List inputlist = new ArrayList<>();
List transfers = new ArrayList<>();
diff --git a/jota/src/test/java/jota/IotaCoreApiTest.java b/jota/src/test/java/jota/IotaCoreApiTest.java
index a75f7fe..3962e26 100644
--- a/jota/src/test/java/jota/IotaCoreApiTest.java
+++ b/jota/src/test/java/jota/IotaCoreApiTest.java
@@ -2,10 +2,13 @@ package jota;
import com.google.gson.Gson;
import jota.dto.response.*;
+import jota.error.ArgumentException;
import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.Test;
+import java.util.Collections;
+
import static org.junit.Assert.assertThat;
/**
@@ -70,7 +73,7 @@ public class IotaCoreApiTest {
}
@Test
- public void shouldFindTransactionsByAddresses() {
+ public void shouldFindTransactionsByAddresses() throws ArgumentException {
FindTransactionResponse trans = proxy.findTransactionsByAddresses(TEST_ADDRESS_WITH_CHECKSUM);
assertThat(trans.getHashes(), IsNull.notNullValue());
}
@@ -94,21 +97,20 @@ public class IotaCoreApiTest {
}
@Test
- public void shouldGetTrytes() {
+ public void shouldGetTrytes() throws ArgumentException {
GetTrytesResponse res = proxy.getTrytes(TEST_HASH);
assertThat(res.getTrytes(), IsNull.notNullValue());
}
- @Test(expected = IllegalAccessError.class)
- public void shouldNotGetInclusionStates() {
- GetInclusionStateResponse res = proxy.getInclusionStates(new String[]{"DBPECSH9YLSSTQDGERUHJBBJTKVUDBMTJLG9WPHBINGHIFOSJMDJLARTVOXXWEFQJLLBINOHCZGYFSMUEXWPPMTOFW"}, new String[]{"EJDQOQHMLJGBMFWB9WJSPRCYIGNPO9WRHDCEQXIMPVPIJ9JV9RJGVHNX9EPGXFOOKBABCVMMAAX999999"});
- assertThat(res.getStates(), IsNull.notNullValue());
+ @Test(expected = ArgumentException.class)
+ public void shouldNotGetInclusionStates() throws ArgumentException {
+ proxy.getInclusionStates(new String[]{TEST_HASH}, new String[]{"ZIJGAJ9AADLRPWNCYNNHUHRRAC9QOUDATEDQUMTNOTABUVRPTSTFQDGZKFYUUIE9ZEBIVCCXXXLKX9999"});
}
@Test
- public void shouldGetInclusionStates() {
- GetInclusionStateResponse res = proxy.getInclusionStates(new String[]{TEST_ADDRESS_WITH_CHECKSUM}, new String[]{proxy.getNodeInfo().getLatestSolidSubtangleMilestone()});
+ public void shouldGetInclusionStates() throws ArgumentException {
+ GetInclusionStateResponse res = proxy.getInclusionStates(new String[]{TEST_HASH}, new String[]{proxy.getNodeInfo().getLatestSolidSubtangleMilestone()});
assertThat(res.getStates(), IsNull.notNullValue());
}
@@ -127,8 +129,8 @@ public class IotaCoreApiTest {
}
@Test
- public void shouldGetBalances() {
- GetBalancesResponse res = proxy.getBalances(100, new String[]{TEST_ADDRESS_WITH_CHECKSUM});
+ public void shouldGetBalances() throws ArgumentException {
+ GetBalancesResponse res = proxy.getBalances(100, Collections.singletonList(TEST_ADDRESS_WITH_CHECKSUM));
assertThat(res.getBalances(), IsNull.notNullValue());
assertThat(res.getMilestone(), IsNull.notNullValue());
assertThat(res.getMilestoneIndex(), IsNull.notNullValue());
diff --git a/jota/src/test/java/jota/IotaLocalPoWTest.java b/jota/src/test/java/jota/IotaLocalPoWTest.java
index 24ac2c0..93ffdf4 100644
--- a/jota/src/test/java/jota/IotaLocalPoWTest.java
+++ b/jota/src/test/java/jota/IotaLocalPoWTest.java
@@ -2,7 +2,7 @@ package jota;
import cfb.pearldiver.PearlDiverLocalPoW;
import jota.dto.response.SendTransferResponse;
-import jota.error.*;
+import jota.error.ArgumentException;
import jota.model.Transfer;
import org.hamcrest.core.IsNull;
import org.junit.Before;
@@ -35,7 +35,7 @@ public class IotaLocalPoWTest {
@Ignore
@Test
- public void shouldSendTransfer() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
+ public void shouldSendTransfer() throws ArgumentException {
List transfers = new ArrayList<>();
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 0, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
diff --git a/jota/src/test/java/jota/IotaMultisigTest.java b/jota/src/test/java/jota/IotaMultisigTest.java
index 9adfde7..82435ff 100644
--- a/jota/src/test/java/jota/IotaMultisigTest.java
+++ b/jota/src/test/java/jota/IotaMultisigTest.java
@@ -1,9 +1,6 @@
package jota;
-import jota.error.InvalidAddressException;
-import jota.error.InvalidBundleException;
-import jota.error.InvalidSecurityLevelException;
-import jota.error.InvalidTransferException;
+import jota.error.ArgumentException;
import jota.model.Bundle;
import jota.model.Transaction;
import jota.model.Transfer;
@@ -38,8 +35,7 @@ public class IotaMultisigTest {
}
@Test
- public void basicMultiSigTest() throws InvalidBundleException, InvalidTransferException, InvalidAddressException, InvalidSecurityLevelException {
-
+ public void basicMultiSigTest() throws ArgumentException {
Multisig ms = new Multisig();
// First co-signer uses security level 3 and index 0 for the private key
diff --git a/jota/src/test/java/jota/SendMessageTest.java b/jota/src/test/java/jota/SendMessageTest.java
index 71da9fc..642d148 100644
--- a/jota/src/test/java/jota/SendMessageTest.java
+++ b/jota/src/test/java/jota/SendMessageTest.java
@@ -1,7 +1,7 @@
package jota;
import jota.dto.response.SendTransferResponse;
-import jota.error.*;
+import jota.error.ArgumentException;
import jota.model.Transfer;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.core.IsNull;
@@ -33,7 +33,7 @@ public class SendMessageTest {
@Ignore
@Test
- public void shouldSendMessage() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
+ public void shouldSendMessage() throws ArgumentException {
List transfers = new ArrayList<>();
// for each 2187 trytes in a message one transfer is necessary
diff --git a/jota/src/test/java/jota/SigningTest.java b/jota/src/test/java/jota/SigningTest.java
index b9d6792..b2c95f3 100644
--- a/jota/src/test/java/jota/SigningTest.java
+++ b/jota/src/test/java/jota/SigningTest.java
@@ -1,7 +1,6 @@
package jota;
-import jota.error.InvalidAddressException;
-import jota.error.InvalidSecurityLevelException;
+import jota.error.ArgumentException;
import jota.model.Bundle;
import jota.pow.ICurl;
import jota.pow.SpongeFactory;
@@ -25,13 +24,13 @@ public class SigningTest {
private static final String SIGNATURE2 = "URKFKLNXFEKDOGSQVMAOPEDIWSMTCKJZ9KEVWYALY9JAO9KHUGNDTMGQLKQJUIPWDIVMPEDSVPLFMDCIXDDT9WBBRTFQENL9AXLSBYHINXCDYBFGRNKJDYHAQVJKWCV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{
+ public void testAddressGeneration() throws ArgumentException {
assertEquals(FIRST_ADDR, IotaAPIUtils.newAddress(TEST_SEED, 2, 0, true, null));
assertEquals(SIXTH_ADDR, IotaAPIUtils.newAddress(TEST_SEED, 2, 5, true, null));
}
@Test
- public void testLongSeedKeyGeneration() throws InvalidSecurityLevelException {
+ public void testLongSeedKeyGeneration() throws ArgumentException {
ICurl curl = SpongeFactory.create(SpongeFactory.Mode.KERL);
Signing signing = new Signing(curl);
String seed = "EV9QRJFJZVFNLYUFXWKXMCRRPNAZYQVEYB9VEPUHQNXJCWKZFVUCTQJFCUAMXAHMMIUQUJDG9UGGQBPIY";
@@ -47,7 +46,7 @@ public class SigningTest {
}
@Test
- public void testSigning() throws InvalidAddressException, InvalidSecurityLevelException {
+ public void testSigning() throws ArgumentException {
// we can sign any hash, so for convenience we will sign the first
// address of our test seed
// (but remove the checksum) with the key of our fifth address
@@ -62,7 +61,7 @@ public class SigningTest {
}
@Test
- public void testKeyLength() throws InvalidSecurityLevelException {
+ public void testKeyLength() throws ArgumentException {
Signing signing = new Signing(null);
int[] key = signing.key(Converter.trits(TEST_SEED), 5, 1);
assertEquals(Signing.KEY_LENGTH, key.length);
@@ -73,11 +72,11 @@ public class SigningTest {
}
@Test
- public void testVerifying() throws InvalidAddressException {
+ public void testVerifying() throws ArgumentException {
assertTrue(new Signing(null).validateSignatures(removeChecksum(SIXTH_ADDR), new String[]{SIGNATURE1, SIGNATURE2}, removeChecksum(FIRST_ADDR)));
}
- private String removeChecksum(String address) throws InvalidAddressException {
+ private String removeChecksum(String address) throws ArgumentException {
assertTrue(Checksum.isValidChecksum(address));
return address.substring(0, Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM);
}