Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 7f5910b

Browse files
authored
Added optional inputValidation and remainder
1 parent a5775c8 commit 7f5910b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/main/java/jota/IotaAPI.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,24 @@ public List<Transaction> findTransactionObjectsByBundle(String[] input) {
338338
* @throws InvalidTransferException is thrown when an invalid transfer is provided.
339339
*/
340340
public List<String> prepareTransfers(String seed, int security, final List<Transfer> transfers, String remainder, List<Input> inputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException, InvalidTransferException {
341+
return prepareTransfers(seed, security, transfers, remainder, inputs, true);
342+
}
343+
/**
344+
* Prepares transfer by generating bundle, finding and signing inputs.
345+
*
346+
* @param seed 81-tryte encoded address of recipient.
347+
* @param security The security level of private key / seed.
348+
* @param transfers Array of transfer objects.
349+
* @param remainder If defined, this address will be used for sending the remainder value (of the inputs) to.
350+
* @param inputs The inputs.
351+
* @param validateInputs whether or not to validate the balances of the provided inputs
352+
* @return Returns bundle trytes.
353+
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
354+
* @throws NotEnoughBalanceException is thrown when a transfer fails because their is not enough balance to perform the transfer.
355+
* @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
356+
* @throws InvalidTransferException is thrown when an invalid transfer is provided.
357+
*/
358+
public List<String> prepareTransfers(String seed, int security, final List<Transfer> transfers, String remainder, List<Input> inputs, boolean validateInputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException, InvalidTransferException {
341359

342360
// Input validation of transfers object
343361
if (!InputValidator.isTransfersCollectionValid(transfers)) {
@@ -419,6 +437,8 @@ public List<String> prepareTransfers(String seed, int security, final List<Trans
419437

420438
// Case 1: user provided inputs
421439
// Validate the inputs by calling getBalances
440+
if(!validateInputs)
441+
return addRemainder(seed, security, inputs, bundle, tag, totalValue, remainder, signatureFragments);
422442
if (inputs != null && !inputs.isEmpty()) {
423443

424444
// Get list if addresses of the provided inputs
@@ -456,7 +476,7 @@ public List<String> prepareTransfers(String seed, int security, final List<Trans
456476
throw new IllegalStateException("Not enough balance");
457477
}
458478

459-
return addRemainder(seed, security, confirmedInputs, bundle, tag, totalValue, null, signatureFragments);
479+
return addRemainder(seed, security, confirmedInputs, bundle, tag, totalValue, remainder, signatureFragments);
460480
}
461481

462482
// Case 2: Get inputs deterministically
@@ -467,7 +487,7 @@ public List<String> prepareTransfers(String seed, int security, final List<Trans
467487

468488
@SuppressWarnings("unchecked") GetBalancesAndFormatResponse newinputs = getInputs(seed, security, 0, 0, totalValue);
469489
// If inputs with enough balance
470-
return addRemainder(seed, security, newinputs.getInput(), bundle, tag, totalValue, null, signatureFragments);
490+
return addRemainder(seed, security, newinputs.getInput(), bundle, tag, totalValue, remainder, signatureFragments);
471491
}
472492
} else {
473493

0 commit comments

Comments
 (0)