mirror of
https://github.com/gosticks/iota.lib.java.git
synced 2026-08-18 23:30:19 +00:00
refactored
This commit is contained in:
@@ -109,8 +109,8 @@ public class IotaAPI extends IotaAPICore {
|
||||
*/
|
||||
public GetTransferResponse getTransfers(String seed, int security, Integer start, Integer end, Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoNodeInfoException, NoInclusionStatesException, InvalidSecurityLevelException, InvalidAddressException {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
// validate & if needed pad seed
|
||||
if ((seed = InputValidator.validateSeed(seed)) == null) {
|
||||
// validate seed
|
||||
if ((!InputValidator.isValidSeed(seed))) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
@@ -344,14 +344,15 @@ public class IotaAPI extends IotaAPICore {
|
||||
public List<String> prepareTransfers(String seed, int security, final List<Transfer> transfers, String remainder, List<Input> inputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException, InvalidTransferException {
|
||||
return prepareTransfers(seed, security, transfers, remainder, inputs, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares transfer by generating bundle, finding and signing inputs.
|
||||
*
|
||||
* @param seed 81-tryte encoded address of recipient.
|
||||
* @param security The security level of private key / seed.
|
||||
* @param transfers Array of transfer objects.
|
||||
* @param remainder If defined, this address will be used for sending the remainder value (of the inputs) to.
|
||||
* @param inputs The inputs.
|
||||
* @param seed 81-tryte encoded address of recipient.
|
||||
* @param security The security level of private key / seed.
|
||||
* @param transfers Array of transfer objects.
|
||||
* @param remainder If defined, this address will be used for sending the remainder value (of the inputs) to.
|
||||
* @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.
|
||||
@@ -366,8 +367,8 @@ public class IotaAPI extends IotaAPICore {
|
||||
throw new InvalidTransferException();
|
||||
}
|
||||
|
||||
// validate & if needed pad seed
|
||||
if ((seed = InputValidator.validateSeed(seed)) == null) {
|
||||
// validate seed
|
||||
if ((!InputValidator.isValidSeed(seed))) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
@@ -438,11 +439,11 @@ public class IotaAPI extends IotaAPICore {
|
||||
|
||||
// Get inputs if we are sending tokens
|
||||
if (totalValue != 0) {
|
||||
if(!validateInputs)
|
||||
if (!validateInputs)
|
||||
return addRemainder(seed, security, inputs, bundle, tag, totalValue, remainder, signatureFragments);
|
||||
// Case 1: user provided inputs
|
||||
// Validate the inputs by calling getBalances
|
||||
if(!validateInputs)
|
||||
if (!validateInputs)
|
||||
return addRemainder(seed, security, inputs, bundle, tag, totalValue, remainder, signatureFragments);
|
||||
if (inputs != null && !inputs.isEmpty()) {
|
||||
|
||||
@@ -524,13 +525,9 @@ public class IotaAPI extends IotaAPICore {
|
||||
**/
|
||||
public GetBalancesAndFormatResponse getInputs(String seed, int security, int start, int end, long threshold) throws InvalidSecurityLevelException, InvalidAddressException {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
// validate the seed
|
||||
if (!InputValidator.isTrytes(seed, 0)) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
// validate & if needed pad seed
|
||||
if ((seed = InputValidator.validateSeed(seed)) == null) {
|
||||
// validate the seed
|
||||
if ((!InputValidator.isValidSeed(seed))) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import jota.IotaAPICommands;
|
||||
|
||||
/**
|
||||
* This class represents the core API request 'attachToTangle'.
|
||||
*
|
||||
* <p>
|
||||
* It is used to attach trytes to the tangle.
|
||||
**/
|
||||
public class IotaAttachToTangleRequest extends IotaCommandRequest {
|
||||
|
||||
@@ -4,7 +4,7 @@ import jota.IotaAPICommands;
|
||||
|
||||
/**
|
||||
* This class represents the core API request 'broadcastTransaction'.
|
||||
*
|
||||
* <p>
|
||||
* Broadcast a list of transactions to all neighbors. The input trytes for this call are provided by attachToTangle
|
||||
**/
|
||||
public class IotaBroadcastTransactionRequest extends IotaCommandRequest {
|
||||
|
||||
@@ -4,7 +4,7 @@ import jota.IotaAPICommands;
|
||||
|
||||
/**
|
||||
* This class represents the core API request 'getTransactionsToApprove'.
|
||||
*
|
||||
* <p>
|
||||
* It stores transactions into the local storage. The trytes to be used for this call are returned by attachToTangle.
|
||||
**/
|
||||
public class IotaStoreTransactionsRequest extends IotaCommandRequest {
|
||||
|
||||
@@ -43,6 +43,7 @@ public class JCurl implements ICurl {
|
||||
stateLow = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Absorbs the specified trits.
|
||||
*
|
||||
|
||||
@@ -9,21 +9,20 @@ import java.util.List;
|
||||
*/
|
||||
public class Converter {
|
||||
|
||||
public static final int HIGH_INTEGER_BITS = 0xFFFFFFFF;
|
||||
public static final long HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFFL;
|
||||
/**
|
||||
* The radix
|
||||
*/
|
||||
private static final int RADIX = 3;
|
||||
|
||||
/**
|
||||
* The maximum trit value
|
||||
*/
|
||||
private static final int MAX_TRIT_VALUE = (RADIX - 1) / 2, MIN_TRIT_VALUE = -MAX_TRIT_VALUE;
|
||||
|
||||
/**
|
||||
* The number of trits in a byte
|
||||
*/
|
||||
private static final int NUMBER_OF_TRITS_IN_A_BYTE = 5;
|
||||
|
||||
/**
|
||||
* The number of trits in a tryte
|
||||
*/
|
||||
@@ -31,9 +30,6 @@ public class Converter {
|
||||
private static final int[][] BYTE_TO_TRITS_MAPPINGS = new int[243][];
|
||||
private static final int[][] TRYTE_TO_TRITS_MAPPINGS = new int[27][];
|
||||
|
||||
public static final int HIGH_INTEGER_BITS = 0xFFFFFFFF;
|
||||
public static final long HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFFL;
|
||||
|
||||
static {
|
||||
|
||||
final int[] trits = new int[NUMBER_OF_TRITS_IN_A_BYTE];
|
||||
|
||||
@@ -2,7 +2,6 @@ package jota.utils;
|
||||
|
||||
import jota.error.InvalidAddressException;
|
||||
import jota.model.Transfer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -153,18 +152,9 @@ public class InputValidator {
|
||||
* Checks if the seed is valid. If not, an exception is thrown.
|
||||
*
|
||||
* @param seed The seed to validate.
|
||||
* @return The validated seed.
|
||||
* @throws IllegalStateException Format not in trytes or Invalid Seed: Seed too long.
|
||||
* @return <code>true</code> if the specified seed is valid; otherwise, <code>false</code>.
|
||||
**/
|
||||
public static String validateSeed(String seed) {
|
||||
if (seed.length() > 81)
|
||||
throw new IllegalStateException("Invalid Seed: Seed too long");
|
||||
|
||||
if (!isTrytes(seed, seed.length()))
|
||||
throw new IllegalStateException("Invalid Seed: Format not in trytes");
|
||||
|
||||
seed = StringUtils.rightPad(seed, 81, '9');
|
||||
|
||||
return seed;
|
||||
public static boolean isValidSeed(String seed) {
|
||||
return isTrytes(seed, seed.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ public class Multisig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred.
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred.
|
||||
* @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.
|
||||
* @param index Key index to start search from. If the index is provided, the generation of the address is not deterministic.
|
||||
* @return trytes
|
||||
**/
|
||||
public String getDigest(String seed, int security, int index) {
|
||||
@@ -70,7 +70,7 @@ public class Multisig {
|
||||
/**
|
||||
* Gets the key value of a seed
|
||||
*
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred
|
||||
* @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.
|
||||
**/
|
||||
|
||||
Reference in New Issue
Block a user