diff --git a/docs/iota-java/checkConsistency.md b/docs/iota-java/checkConsistency.md deleted file mode 100644 index 9d30b11c..00000000 --- a/docs/iota-java/checkConsistency.md +++ /dev/null @@ -1,38 +0,0 @@ - -# [checkConsistency](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/IotaAPICore.java#L628) - [CheckConsistencyResponse](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/dto/response/CheckConsistencyResponse.java) checkConsistency(String[] tails) - -Checks the consistency of the subtangle formed by the provided tails. -> **Important note:** This API is currently in Beta and is subject to change. Use of these APIs in production applications is not supported. - -## Input -| Parameter | Type | Required or Optional | Description | -|:---------------|:--------|:--------| :--------| -| tails | String[] | Required | The tails describing the subtangle. | - -## Output -[CheckConsistencyResponse](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/dto/response/CheckConsistencyResponse.java), which contains the following fields: -| Return type | Description | -|--|--| -| Long duration | Gets the duration. | -| boolean state | Gets the state. | -| String info | If state is false, this provides information on the cause of the inconsistency. | - -## Exceptions -| Exceptions | Description | -|:---------------|:--------| -| [ArgumentException](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/error/ArgumentException.java) | when a tail hash is invalid | - - - ## Example - - ```Java - IotaAPI iotaAPI = new IotaAPI.Builder().build(); - -try { - CheckConsistencyResponse response = iotaAPI.checkConsistency(new String[]{"ZRJMXSYCCYEOASWAQ9IUBBMQJWGQERRMHDSUEJUNFUMYIOLJBALPYUBPCRPOFUFDLNTFXIEEAVBXHRGTX", "BNSOYBRJVWUQEYSBCZSEHYNWFLMDJ9KIUUSATBNAELQQHSSAGHHZJDVYETGGCODLEEIZOFYEJMABEVWUI"}); -} catch (ArgumentException e) { - // Handle error - e.printStackTrace(); -} - ``` diff --git a/docs/iota-java/isPromotable.md b/docs/iota-java/isPromotable.md index 176e5484..074b2b09 100644 --- a/docs/iota-java/isPromotable.md +++ b/docs/iota-java/isPromotable.md @@ -16,14 +16,7 @@ Checks if a transaction hash is promotable | boolean | `true` if it is, otherwise `false` | ## Exceptions -| Exceptions | Description | -|:---------------|:--------| -| [ArgumentException](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/error/ArgumentException.java) | when we can't get the consistency of this transaction | - -## Related APIs (link to other product documentation) -| API | Description | -|:---------------|:--------| -| [checkConsistency(String...)](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/IotaAPICore.java#L628) | Checks the consistency of the subtangle formed by the provided tails. | +None ## Example diff --git a/docs/iota-java/promoteTransaction.md b/docs/iota-java/promoteTransaction.md index 888aefc5..54647bc4 100644 --- a/docs/iota-java/promoteTransaction.md +++ b/docs/iota-java/promoteTransaction.md @@ -47,7 +47,6 @@ List<[Transaction](https://github.com/iotaledger/iota-java/blob/master/jota/src/ ## Related APIs (link to other product documentation) | API | Description | |:---------------|:--------| -| [checkConsistency(String...)](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/IotaAPICore.java#L628) | Checks the consistency of the subtangle formed by the provided tails. | | [getTransactionsToApprove(Integer, String)](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/IotaAPICore.java#L423) | Tip selection which returns `trunkTransaction` and `branchTransaction`. The input value `depth` determines how many milestones to go back for finding the transactions to approve. The higher your `depth` value, the more work you have to do as you are confirming more transactions. If the `depth` is too large (usually above 15, it depends on the node's configuration) an error will be returned. The `reference` is an optional hash of a transaction you want to approve. If it can't be found at the specified `depth` then an error will be returned. | | [attachToTangle(String, String, Integer, String...)](https://github.com/iotaledger/iota-java/blob/master/jota/src/main/java/org/iota/jota/IotaAPICore.java#L673) | Prepares the specified transactions (trytes) for attachment to the Tangle by doing Proof of Work. You need to supply `branchTransaction` as well as `trunkTransaction`. These are the tips which you're going to validate and reference with this transaction. These are obtainable by the `getTransactionsToApprove` API call. The returned value is a different set of tryte values which you can input into `broadcastTransactions` and `storeTransactions`. diff --git a/jota/src/main/java/org/iota/jota/IotaAPI.java b/jota/src/main/java/org/iota/jota/IotaAPI.java index e547407b..60e2eab3 100644 --- a/jota/src/main/java/org/iota/jota/IotaAPI.java +++ b/jota/src/main/java/org/iota/jota/IotaAPI.java @@ -1,11 +1,23 @@ package org.iota.jota; -import static java.util.stream.Collectors.toList; - import org.apache.commons.lang3.StringUtils; import org.iota.jota.builder.AddressRequest; import org.iota.jota.builder.ApiBuilder; -import org.iota.jota.dto.response.*; +import org.iota.jota.dto.response.BroadcastTransactionsResponse; +import org.iota.jota.dto.response.FindTransactionResponse; +import org.iota.jota.dto.response.GetAccountDataResponse; +import org.iota.jota.dto.response.GetAttachToTangleResponse; +import org.iota.jota.dto.response.GetBalancesAndFormatResponse; +import org.iota.jota.dto.response.GetBalancesResponse; +import org.iota.jota.dto.response.GetBundleResponse; +import org.iota.jota.dto.response.GetInclusionStateResponse; +import org.iota.jota.dto.response.GetNewAddressResponse; +import org.iota.jota.dto.response.GetTransactionsToApproveResponse; +import org.iota.jota.dto.response.GetTransferResponse; +import org.iota.jota.dto.response.GetTrytesResponse; +import org.iota.jota.dto.response.ReplayBundleResponse; +import org.iota.jota.dto.response.SendTransferResponse; +import org.iota.jota.dto.response.WereAddressesSpentFromResponse; import org.iota.jota.error.ArgumentException; import org.iota.jota.error.BaseException; import org.iota.jota.error.NotPromotableException; @@ -14,14 +26,27 @@ import org.iota.jota.model.Transaction; import org.iota.jota.model.Transfer; import org.iota.jota.pow.SpongeFactory; -import org.iota.jota.utils.*; +import org.iota.jota.utils.BundleValidator; +import org.iota.jota.utils.Checksum; +import org.iota.jota.utils.Constants; +import org.iota.jota.utils.InputValidator; +import org.iota.jota.utils.IotaAPIUtils; +import org.iota.jota.utils.Parallel; +import org.iota.jota.utils.StopWatch; import org.iota.mddoclet.Document; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; import java.util.stream.IntStream; +import static java.util.stream.Collectors.toList; + /** * IotaAPI Builder. Usage: *
@@ -30,13 +55,12 @@ * {@code .nodeAddress("localhost")} * {@code .port(12345)} * {@code .build();} - * + *
* {@code GetNodeInfoResponse response = api.getNodeInfo();} - * */ public class IotaAPI extends IotaAPICore { - private static final Logger log = LoggerFactory.getLogger(IotaAPI.class); + private static final Logger LOGGER = LoggerFactory.getLogger(IotaAPI.class); protected IotaAPI(ApiOptions options) { super(options); @@ -49,7 +73,7 @@ protected IotaAPI(Builder builder) { /** * Generates new addresses, meaning addresses which were not spend from, according to the connected node. * Stops when {@link AddressRequest#getAmount()} of unspent addresses are found, starting from {@link AddressRequest#getIndex()} - * + *
* If {@link AddressRequest#getAmount()} is set to 0, we will generate until the first unspent address is found, and stop.
*
* @param addressRequest {@link AddressRequest}
@@ -122,7 +146,7 @@ private Listamount
of addresses, starting from index
* This does not mean that these addresses are safe to use (unspent)
- *
+ *
* @param addressRequest {@link AddressRequest}
* @return {@link GetNewAddressResponse}
* @throws ArgumentException is thrown when the specified input is not valid.
@@ -141,15 +165,15 @@ public GetNewAddressResponse getAddressesUnchecked(AddressRequest addressRequest
/**
* Finds all the bundles for all the addresses based on this seed and security.
- *
+ *
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred.
* @param security Security level to be used for the private key / address. Can be 1, 2 or 3.
* @param start Starting key index, must be at least 0.
* @param end Ending key index, must be bigger then start
* @param inclusionStates If true
, it also gets the inclusion states of the transfers.
* @return {@link GetTransferResponse}
- * @throws ArgumentException when start and end are more then 500 apart
- * @throws ArgumentException Invalid security index
+ * @throws ArgumentException when start and end are more then 500 apart
+ * @throws ArgumentException Invalid security index
* @throws IllegalStateException When the seed is invalid
*/
@Document
@@ -163,7 +187,7 @@ public GetTransferResponse getTransfers(String seed, int security, Integer start
if (start < 0 || start > end || end > (start + 500)) {
throw new ArgumentException(Constants.INVALID_INPUT_ERROR);
}
-
+
if (!InputValidator.isValidSecurityLevel(security)) {
throw new ArgumentException(Constants.INVALID_SECURITY_LEVEL_INPUT_ERROR);
}
@@ -191,7 +215,7 @@ public GetTransferResponse getTransfers(String seed, int security, Integer start
* @param addresses If true
, it also gets the inclusion state of each bundle.
* @param inclusionStates Array of addresses.
* @return All the transaction bundles for the addresses, or null
when our thread gets interrupted
- * @throws ArgumentException When the addresses are invalid
+ * @throws ArgumentException When the addresses are invalid
* @throws IllegalStateException When inclusion state/confirmed could not be determined (null returned)
*/
@Document
@@ -237,7 +261,7 @@ public Bundle[] bundlesFromAddresses(Boolean inclusionStates, String... addresse
}
final GetInclusionStateResponse finalInclusionStates = gisr;
try {
- Parallel.of(Arrays.asList(tailTxArray), tailTx -> {
+ Parallel.of(Arrays.asList(tailTxArray), tailTx -> {
try {
GetBundleResponse bundleResponse = getBundle(tailTx);
Bundle gbr = new Bundle(bundleResponse.getTransactions(), bundleResponse.getTransactions().size());
@@ -256,7 +280,7 @@ public Bundle[] bundlesFromAddresses(Boolean inclusionStates, String... addresse
// If error returned from getBundle, simply ignore it because the bundle was most likely incorrect
} catch (ArgumentException e) {
if (!Thread.interrupted()) {
- log.warn(Constants.GET_BUNDLE_RESPONSE_ERROR);
+ LOGGER.warn(Constants.GET_BUNDLE_RESPONSE_ERROR);
}
}
});
@@ -323,13 +347,9 @@ public List
* Runs getInclusionStates - * + * * @param hashes The hashes. * @return {@link GetInclusionStateResponse} * @throws ArgumentException when one of the hashes is invalid @@ -1074,7 +1088,7 @@ private ReplayBundleResponse replayBundle(Bundle bundle, int depth, int minWeigh public GetInclusionStateResponse getLatestInclusion(String... hashes) throws ArgumentException { return getInclusionStates(hashes); } - + /** *
* Get the inclusion states of a set of transactions. @@ -1084,10 +1098,10 @@ public GetInclusionStateResponse getLatestInclusion(String... hashes) throws Arg * This API call returns a list of boolean values in the same order as the submitted transactions. * Boolean values will be true for confirmed transactions, otherwise false. *
- * - * This is command does the same as {@link #getInclusionStates(String...)} but a copy exists + *
+ * This is command does the same as {@link #getInclusionStates(String...)} but a copy exists
* for readability.
- *
+ *
* @param hashes The transaction hashes to check for
* @return {@link GetInclusionStateResponse}
* @throws ArgumentException when one of the hashes is invalid
@@ -1102,23 +1116,23 @@ public GetInclusionStateResponse isConfirmed(String... hashes) throws ArgumentEx
* Wrapper function: Runs prepareTransfers, as well as attachToTangle.
* We then broadcasts this and and store the transactions on the node.
*
- * @param seed The tryte-encoded seed. It should be noted that this seed is not transferred.
- * @param security Security level to be used for the private key / address. Can be 1, 2 or 3.
- * @param depth The depth for getting transactions to approve
- * @param minWeightMagnitude The minimum weight magnitude for doing proof of work
- * @param transfers List of {@link Transfer} objects.
- * @param inputs List of {@link Input} used for funding the transfer.
- * @param remainderAddress If defined, this remainderAddress will be used for sending the remainder value (of the inputs) to.
- * When this is not defined, but a remaining exists, the next free address is used.
- * @param validateInputs Whether or not to validate the balances of the provided inputs.
- * @param validateInputAddresses Whether or not to validate if the destination address is already use.
- * If a key reuse is detect or it's send to inputs.
- * @param tips The starting points we walk back from to find the balance of the addresses
- * If multiple tips are supplied, only the first tip is used for {@link #getTransactionsToApprove(Integer, String)}
+ * @param seed The tryte-encoded seed. It should be noted that this seed is not transferred.
+ * @param security Security level to be used for the private key / address. Can be 1, 2 or 3.
+ * @param depth The depth for getting transactions to approve
+ * @param minWeightMagnitude The minimum weight magnitude for doing proof of work
+ * @param transfers List of {@link Transfer} objects.
+ * @param inputs List of {@link Input} used for funding the transfer.
+ * @param remainderAddress If defined, this remainderAddress will be used for sending the remainder value (of the inputs) to.
+ * When this is not defined, but a remaining exists, the next free address is used.
+ * @param validateInputs Whether or not to validate the balances of the provided inputs.
+ * @param validateInputAddresses Whether or not to validate if the destination address is already use.
+ * If a key reuse is detect or it's send to inputs.
+ * @param tips The starting points we walk back from to find the balance of the addresses
+ * If multiple tips are supplied, only the first tip is used for {@link #getTransactionsToApprove(Integer, String)}
* @return {@link SendTransferResponse}
- * @throws ArgumentException If the seed is invalid
- * @throws ArgumentException If the security level is wrong.
- * @throws ArgumentException When validateInputAddresses is true, if validateTransfersAddresses has an error.
+ * @throws ArgumentException If the seed is invalid
+ * @throws ArgumentException If the security level is wrong.
+ * @throws ArgumentException When validateInputAddresses is true, if validateTransfersAddresses has an error.
* @throws IllegalStateException If the transfers are not all valid
* @throws IllegalStateException If there is not enough balance in the inputs to supply to the transfers
* @see #prepareTransfers(String, int, List, String, List, List, boolean)
@@ -1126,25 +1140,25 @@ public GetInclusionStateResponse isConfirmed(String... hashes) throws ArgumentEx
* @see #validateTransfersAddresses(String, int, List)
*/
@Document
- public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude,
- List
* Prepares the specified transactions (trytes) for attachment to the Tangle by doing Proof of Work.
@@ -733,7 +748,7 @@ public GetAttachToTangleResponse attachToTangle(String trunkTransaction, String
public GetAttachToTangleResponse attachToTangleLocalPow(String trunkTransaction, String branchTransaction,
Integer minWeightMagnitude, IotaPoW pow, String... trytes) {
if (pow == null) {
- log.warn("Called local POW without POW defined, switching to remote POW");
+ LOGGER.warn("Called local POW without POW defined, switching to remote POW");
return attachToTangle(trunkTransaction, branchTransaction, minWeightMagnitude, trytes);
}
@@ -754,20 +769,20 @@ public GetAttachToTangleResponse attachToTangleLocalPow(String trunkTransaction,
try {
for (int i = 0; i < resultTrytes.length; i++) {
- Transaction txn = new Transaction(trytes[i]);
- txn.setTrunkTransaction(previousTransaction == null ? trunkTransaction : previousTransaction);
- txn.setBranchTransaction(previousTransaction == null ? branchTransaction : trunkTransaction);
+ Transaction transaction = new Transaction.Builder().buildWithTrytes(trytes[i]);
+ transaction.setTrunkTransaction(previousTransaction == null ? trunkTransaction : previousTransaction);
+ transaction.setBranchTransaction(previousTransaction == null ? branchTransaction : trunkTransaction);
- if (txn.getTag().isEmpty() || txn.getTag().matches("9*")) {
- txn.setTag(txn.getObsoleteTag());
+ if (transaction.getTag().isEmpty() || transaction.getTag().matches("9*")) {
+ transaction.setTag(transaction.getObsoleteTag());
}
- txn.setAttachmentTimestamp(System.currentTimeMillis());
- txn.setAttachmentTimestampLowerBound(0);
- txn.setAttachmentTimestampUpperBound(3_812_798_742_493L);
+ transaction.setAttachmentTimestamp(System.currentTimeMillis());
+ transaction.setAttachmentTimestampLowerBound(0);
+ transaction.setAttachmentTimestampUpperBound(3_812_798_742_493L);
- resultTrytes[i] = pow.performPoW(txn.toTrytes(), minWeightMagnitude);
- previousTransaction = new Transaction(resultTrytes[i], SpongeFactory.create(SpongeFactory.Mode.CURL_P81)).getHash();
+ resultTrytes[i] = pow.performPoW(transaction.toTrytes(), minWeightMagnitude);
+ previousTransaction = new Transaction.Builder().buildWithTrytes(resultTrytes[i]).getHash();
}
Collections.reverse(Arrays.asList(resultTrytes));
} catch (Exception e) {
diff --git a/jota/src/main/java/org/iota/jota/IotaAccount.java b/jota/src/main/java/org/iota/jota/IotaAccount.java
index 175e3605..8e0b031d 100644
--- a/jota/src/main/java/org/iota/jota/IotaAccount.java
+++ b/jota/src/main/java/org/iota/jota/IotaAccount.java
@@ -1,16 +1,5 @@
package org.iota.jota;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.atomic.AtomicLong;
-
import org.apache.commons.lang3.StringUtils;
import org.iota.jota.account.Account;
import org.iota.jota.account.AccountBalanceCache;
@@ -18,6 +7,7 @@
import org.iota.jota.account.AccountState;
import org.iota.jota.account.AccountStateManager;
import org.iota.jota.account.AccountStore;
+import org.iota.jota.account.addressgenerator.AddressGeneratorService;
import org.iota.jota.account.addressgenerator.AddressGeneratorServiceImpl;
import org.iota.jota.account.condition.ExpireCondition;
import org.iota.jota.account.deposits.ConditionalDepositAddress;
@@ -53,7 +43,6 @@
import org.iota.jota.model.Input;
import org.iota.jota.model.Transaction;
import org.iota.jota.model.Transfer;
-import org.iota.jota.pow.SpongeFactory;
import org.iota.jota.types.Address;
import org.iota.jota.types.Hash;
import org.iota.jota.types.Recipient;
@@ -68,31 +57,37 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.util.stream.Collectors.toList;
public class IotaAccount implements Account, EventListener {
- private static final String ACC_START_FAILED = "Failed to load accounts. Check the error log";
-
- private static final Logger log = LoggerFactory.getLogger(IotaAccount.class);
-
- private AccountOptions options;
-
- private EventManager eventManager;
-
- List
* {@inheritDoc}
*/
@Override
public Future
* {@inheritDoc}
*/
@Override
public Future
* The IotaAccount is still using the original account state
+ *
* @return a clone of the account state. or g
@@ -66,7 +62,7 @@ public interface IotaNodeHTTPService {
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call
@@ -200,16 +196,6 @@ public interface IotaNodeHTTPService {
@POST("./")
Call
- * {@code curl http://localhost:14265 -X POST -H 'X-IOTA-API-Version: 1.4.1' -H 'Content-Type: application/json'}
- * {@code -d '{"command": "checkConsistency", "tails": ["AYHLOYXFXYNBX9L9TLS9LGKPGJCTHVPEVYNMZEEIPVBVLSIBZEJRKXYYOW9NXKTNQSVFBMGUKVYOZ9999"]}'}
- */
- @Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
- @POST("./")
- Call
@@ -219,7 +205,7 @@ public interface IotaNodeHTTPService {
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call.get()
on the future in order to start this transfer.
- *
+ *
* @param address The receiver of this transfer
- * @param amount The amount we are sending to the address
+ * @param amount The amount we are sending to the address
* @param message An optional message for this transfer
- * @param tag An optional tag for this transfer
+ * @param tag An optional tag for this transfer
* @return The bundle we sent
*/
@Document
- public Futurenull
if it failed
*/
public AccountState exportAccount() {
if (!loaded) {
return null;
}
-
+
try {
return getAccountManager().getAccountState().clone();
} catch (CloneNotSupportedException e) {
@@ -785,10 +761,11 @@ public AccountState exportAccount() {
return null;
}
}
-
+
/**
* Saves the current account state, then replaces it with the one provided.
* Provided state will also be saved to persist
+ *
* @param state the new account state
*/
public void importAccount(AccountState state) {
@@ -798,59 +775,63 @@ public void importAccount(AccountState state) {
}
unload(true);
load(accountId, state);
-
+
this.accountManager.save();
}
}
-
- public SeedProvider getSeed(){
+
+ public SeedProvider getSeed() {
return options.getSeed();
}
-
- private AccountStore getStore(){
+
+ private AccountStore getStore() {
return options.getStore();
}
-
- public IotaAPI getApi(){
+
+ public IotaAPI getApi() {
return options.getApi();
}
-
+
public EventManager getEventManager() {
return eventManager;
}
-
+
public AccountStateManager getAccountManager() {
return accountManager;
}
-
+
+ public boolean isLoaded() {
+ return loaded;
+ }
+
@AccountEvent
private void onError(EventAccountError error) {
if (error.shouldLog()) {
- log.error(error.getMessage(), error.getCause());
+ LOGGER.error(error.getMessage(), error.getCause());
error.getException().printStackTrace();
}
}
-
+
@Override
public String toString() {
StringBuilder builder = new StringBuilder("----------------------");
builder.append(System.getProperty("line.separator"));
builder.append("iota-java accounts configured with the following: ");
-
+
builder.append(System.getProperty("line.separator"));
-
+
builder.append(options.toString());
-
+
return builder.toString();
}
-
+
// Builder here for easy access
public static class Builder extends AccountBuilder {
-
+
public Builder(SeedProvider seed) throws ArgumentException {
super(seed);
}
-
+
public Builder(String seed) throws ArgumentException {
super(seed);
}
diff --git a/jota/src/main/java/org/iota/jota/account/AccountBalanceCache.java b/jota/src/main/java/org/iota/jota/account/AccountBalanceCache.java
index 0c5a8de6..0fae41ef 100644
--- a/jota/src/main/java/org/iota/jota/account/AccountBalanceCache.java
+++ b/jota/src/main/java/org/iota/jota/account/AccountBalanceCache.java
@@ -17,11 +17,10 @@
public class AccountBalanceCache {
- private Map cachedIndexMap;
-
- private AddressGeneratorService addressGenerator;
- private AccountState state;
+ private final AddressGeneratorService addressGenerator;
+ private final AccountState state;
+ private Map cachedIndexMap;
private long totalBalance;
public AccountBalanceCache( AddressGeneratorService addressGenerator, AccountState state, IotaAPI api) {
diff --git a/jota/src/main/java/org/iota/jota/account/addressgenerator/AddressGeneratorServiceImpl.java b/jota/src/main/java/org/iota/jota/account/addressgenerator/AddressGeneratorServiceImpl.java
index 0cb5d807..f37af374 100644
--- a/jota/src/main/java/org/iota/jota/account/addressgenerator/AddressGeneratorServiceImpl.java
+++ b/jota/src/main/java/org/iota/jota/account/addressgenerator/AddressGeneratorServiceImpl.java
@@ -15,7 +15,7 @@ public class AddressGeneratorServiceImpl implements AddressGeneratorService {
// Maybe later: https://github.com/ben-manes/caffeine
private Map
* Example: https://iota.net:14265/node/
- *
+ *
* @param url The url we use
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(String url) throws MalformedURLException {
this(new URL(url));
}
-
+
/**
* Creates an HTTP connector using the default port by creating an {@link OkHttpClient}
- *
+ *
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
+ * @param host The host we use (Domain and optional subdomain)
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(String protocol, String host) throws MalformedURLException {
this(protocol, host, DEFAULT_PORT);
}
-
+
/**
* Creates an HTTP connector using the default timeout by creating an {@link OkHttpClient}
- *
+ *
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
- * @param port The port we use
+ * @param host The host we use (Domain and optional subdomain)
+ * @param port The port we use
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(String protocol, String host, int port) throws MalformedURLException {
this(protocol, host, port, IotaDefaultConfig.Defaults.CONNECTION_TIMEOUT);
}
-
+
/**
* Creates an HTTP connector by creating an {@link OkHttpClient}
- *
+ *
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
- * @param port The port we use
- * @param timeout the connection timeout after a request is sent
+ * @param host The host we use (Domain and optional subdomain)
+ * @param port The port we use
+ * @param timeout the connection timeout after a request is sent
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(String protocol, String host, int port, int timeout) throws MalformedURLException {
this(protocol, host, port, "", timeout);
}
-
+
/**
* Creates an HTTP connector by creating an {@link OkHttpClient}
- *
+ *
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
- * @param port The port we use
- * @param file The file extension of the host (so "/node/" in iota.net/node/)
+ * @param host The host we use (Domain and optional subdomain)
+ * @param port The port we use
+ * @param file The file extension of the host (so "/node/" in iota.net/node/)
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(String protocol, String host, int port, String file) throws MalformedURLException {
this(new URL(protocol, host, port, file));
}
-
+
/**
* Creates an HTTP connector by creating an {@link OkHttpClient}
- *
+ *
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
- * @param port The port we use
- * @param file The file extension of the host (so "node" in iota.net/node)
- * @param timeout the connection timeout after a request is sent
+ * @param host The host we use (Domain and optional subdomain)
+ * @param port The port we use
+ * @param file The file extension of the host (so "node" in iota.net/node)
+ * @param timeout the connection timeout after a request is sent
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(String protocol, String host, int port, String file, int timeout) throws MalformedURLException {
this(new URL(protocol, host, port, file), timeout);
}
-
+
/**
* Creates an HTTP connector using the default timeout by creating an {@link OkHttpClient}
- *
+ *
* @param url The URL we connect to
*/
public HttpConnector(URL url) {
this(url, IotaDefaultConfig.Defaults.CONNECTION_TIMEOUT);
}
-
+
/**
* Creates an HTTP connector by creating an {@link OkHttpClient}
- *
- * @param url The URL we connect to
+ *
+ * @param url The URL we connect to
* @param timeout the connection timeout after a request is sent
*/
public HttpConnector(URL url, int timeout) {
@@ -149,37 +175,37 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
.build();
this.url = url;
}
-
+
/**
* Creates an HTTP connector using the provided HTTP client, with the default port
- *
- * @param client The client we use to send/receive/intercept
+ *
+ * @param client The client we use to send/receive/intercept
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
+ * @param host The host we use (Domain and optional subdomain)
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(OkHttpClient client, String protocol, String host) throws MalformedURLException {
this(client, new URL(protocol, host, DEFAULT_PORT, ""));
}
-
+
/**
* Creates an HTTP connector using the provided HTTP client
- *
- * @param client The client we use to send/receive/intercept
+ *
+ * @param client The client we use to send/receive/intercept
* @param protocol The protocol we use
- * @param host The host we use (Domain and optional subdomain)
- * @param port The port we use
+ * @param host The host we use (Domain and optional subdomain)
+ * @param port The port we use
* @throws MalformedURLException if this is an invalid URL
*/
public HttpConnector(OkHttpClient client, String protocol, String host, int port) throws MalformedURLException {
this(client, new URL(protocol, host, port, ""));
}
-
+
/**
* Creates an HTTP connector using the provided HTTP client
- *
+ *
* @param client The client we use to send/receive/intercept
- * @param url The URL we connect to
+ * @param url The URL we connect to
*/
public HttpConnector(OkHttpClient client, URL url) {
Objects.requireNonNull(client, "Client cannot be null");
@@ -187,12 +213,12 @@ public HttpConnector(OkHttpClient client, URL url) {
this.url = url;
this.client = client;
}
-
+
@Override
public URL url() {
return url;
}
-
+
@Override
public boolean start() {
// use client to create Retrofit service
@@ -201,16 +227,16 @@ public boolean start() {
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
-
+
service = retrofit.create(IotaNodeHTTPService.class);
return true;
}
-
+
@Override
public void stop() {
//does nothing
}
-
+
@Override
public int hashCode() {
final int prime = 31;
@@ -245,7 +271,7 @@ public boolean equals(Object obj) {
public boolean isConnectedToSameNode(Connection other) {
return other.url() != null && other.url().equals(url());
}
-
+
@Override
public String toString() {
return "HttpConnector [url=" + url + "]";
@@ -253,44 +279,49 @@ public String toString() {
protected static