mirror of
https://github.com/gosticks/iota.lib.java.git
synced 2025-10-16 11:45:37 +00:00
extended sendTransfers
This commit is contained in:
parent
c668a41784
commit
6c2df37959
@ -807,15 +807,40 @@ public class IotaAPI extends IotaAPICore {
|
||||
* @param transfers Array of transfer objects.
|
||||
* @param inputs List of inputs used for funding the transfer.
|
||||
* @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
|
||||
* @param validateInputs Whether or not to validate the balances of the provided inputs.
|
||||
* @param validateAddresses Whether or not to validate if the destination address is already used and if a key reuse is detect.
|
||||
* @return Array of valid Transaction objects.
|
||||
* @throws ArgumentException is thrown when the specified input is not valid.
|
||||
*/
|
||||
public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List<Transfer> transfers, List<Input> inputs, String remainderAddress, boolean validateInputs) throws ArgumentException {
|
||||
public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List<Transfer> transfers, List<Input> inputs, String remainderAddress, boolean validateInputs, boolean validateAddresses) throws ArgumentException {
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
|
||||
List<String> trytes = prepareTransfers(seed, security, transfers, remainderAddress, inputs, validateInputs);
|
||||
|
||||
if (validateAddresses) {
|
||||
|
||||
HashSet<String> addresses = new HashSet<>();
|
||||
|
||||
for (String trx : trytes) {
|
||||
addresses.add(new Transaction(trx, customCurl.clone()).getAddress());
|
||||
}
|
||||
|
||||
String[] hashes = findTransactionsByAddresses(addresses.toArray(new String[addresses.size()])).getHashes();
|
||||
List<Transaction> transactions = findTransactionsObjectsByHashes(hashes);
|
||||
List<String> gna = getNewAddress(seed, security, 0, false, 0, true).getAddresses();
|
||||
|
||||
for (Transaction trx : transactions) {
|
||||
if (trx.getValue() < 0 && gna.contains(trx.getAddress())) {
|
||||
throw new ArgumentException(Constants.PRIVATE_KEY_REUSE_ERROR);
|
||||
}
|
||||
|
||||
if (trx.getValue() < 0) {
|
||||
throw new ArgumentException(Constants.SENDING_TO_USED_ADDRESS_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Transaction> trxs = sendTrytes(trytes.toArray(new String[trytes.size()]), depth, minWeightMagnitude);
|
||||
|
||||
Boolean[] successful = new Boolean[trxs.size()];
|
||||
|
||||
@ -59,4 +59,7 @@ public class Constants {
|
||||
public static final String GET_TRYTES_RESPONSE_ERROR = "Get trytes response was null.";
|
||||
public static final String GET_BUNDLE_RESPONSE_ERROR = "Get bundle response was null.";
|
||||
public static final String GET_INCLUSION_STATE_RESPONSE_ERROR = "Get inclusion state response was null.";
|
||||
|
||||
public static final String SENDING_TO_USED_ADDRESS_ERROR = "Sending to a used address.";
|
||||
public static final String PRIVATE_KEY_REUSE_ERROR = "Private key reuse detect!";
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ public class IotaAPITest {
|
||||
public void shouldNotSendTransfer() throws ArgumentException {
|
||||
List<Transfer> 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);
|
||||
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false, true);
|
||||
assertThat(str.getTransactions(), IsNull.notNullValue());
|
||||
assertThat(str.getSuccessfully(), IsNull.notNullValue());
|
||||
}
|
||||
@ -269,7 +269,7 @@ public class IotaAPITest {
|
||||
public void shouldSendTransferWithoutInputs() throws ArgumentException {
|
||||
List<Transfer> 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);
|
||||
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false, true);
|
||||
assertThat(str.getTransactions(), IsNull.notNullValue());
|
||||
assertThat(str.getSuccessfully(), IsNull.notNullValue());
|
||||
}
|
||||
@ -286,7 +286,7 @@ public class IotaAPITest {
|
||||
|
||||
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, inputlist, null, true);
|
||||
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, inputlist, null, true, true);
|
||||
assertThat(str.getTransactions(), IsNull.notNullValue());
|
||||
assertThat(str.getSuccessfully(), IsNull.notNullValue());
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public class IotaLocalPoWTest {
|
||||
public void shouldSendTransfer() throws ArgumentException {
|
||||
List<Transfer> 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);
|
||||
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false, false);
|
||||
assertThat(str.getSuccessfully(), IsNull.notNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class SendMessageTest {
|
||||
// for each 2187 trytes in a message one transfer is necessary
|
||||
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 0, StringUtils.rightPad(TEST_MESSAGE, 2188, '9'), TEST_TAG));
|
||||
|
||||
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
|
||||
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false, false);
|
||||
assertEquals(str.getTransactions().size(), 2);
|
||||
assertThat(str.getTransactions(), IsNull.notNullValue());
|
||||
assertThat(str.getSuccessfully(), IsNull.notNullValue());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user