diff --git a/src/main/java/jota/IotaAPIProxy.java b/src/main/java/jota/IotaAPIProxy.java index 52af878..5c0c47d 100644 --- a/src/main/java/jota/IotaAPIProxy.java +++ b/src/main/java/jota/IotaAPIProxy.java @@ -287,8 +287,7 @@ public class IotaAPIProxy { * @param {int} minWeightMagnitude * @return */ - public List sendTrytes(final String trytes, final int minWeightMagnitude) { - + public List sendTrytes(final String[] trytes, final int minWeightMagnitude) { final GetTransactionsToApproveResponse txs = getTransactionsToApprove(minWeightMagnitude); // attach to tangle - do pow @@ -443,7 +442,7 @@ public class IotaAPIProxy { // Case 1: user provided inputs // Validate the inputs by calling getBalances - if (!inputs.isEmpty()) { + if (inputs != null && !inputs.isEmpty()) { // Get list if addresses of the provided inputs List inputsAddresses = new ArrayList<>(); @@ -453,7 +452,6 @@ public class IotaAPIProxy { GetBalancesResponse resbalances = getBalances(100, inputsAddresses); String[] balances = resbalances.getBalances(); - List confirmedInputs = new ArrayList<>(); int totalBalance = 0; int i = 0; @@ -502,7 +500,7 @@ public class IotaAPIProxy { return bundleTrytes; } } - + /** * Gets the inputs of a seed * @@ -628,7 +626,7 @@ public class IotaAPIProxy { bundleTrytes.add(IotaAPIUtils.transactionTrytes(element)); } - return sendTrytes(bundleTrytes.get(0), minWeightMagnitude); + return sendTrytes(bundleTrytes.toArray(new String[bundleTrytes.size()]), minWeightMagnitude); } /** @@ -648,6 +646,13 @@ public class IotaAPIProxy { return getInclusionStates(hashes, latestMilestone); } + public Transaction[] sendTransfer(String seed, int depth, int minWeightMagnitude, Transfer[] transactions, Input[] inputs, String address) { + + List trytes = prepareTransfers(seed, Arrays.asList(transactions), address, Arrays.asList(inputs)); + List trxs = sendTrytes(trytes.toArray(new String[trytes.size()]), minWeightMagnitude); + return trxs.toArray(new Transaction[trxs.size()]); + } + public static class Builder { String protocol, host, port; diff --git a/src/test/java/jota/IotaAPIProxyTest.java b/src/test/java/jota/IotaAPIProxyTest.java index ffb52ac..02ab732 100644 --- a/src/test/java/jota/IotaAPIProxyTest.java +++ b/src/test/java/jota/IotaAPIProxyTest.java @@ -6,6 +6,7 @@ import jota.dto.response.*; import jota.model.Transfer; import org.hamcrest.core.Is; import org.hamcrest.core.IsNull; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -162,12 +163,15 @@ public class IotaAPIProxyTest { public void shouldPrepareTransfer() { List transfers = new ArrayList<>(); transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG)); - proxy.prepareTransfers(TEST_SEED, transfers, null, null); + transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 1, TEST_MESSAGE, TEST_TAG)); + List trytes = proxy.prepareTransfers(TEST_SEED, transfers, null, null); + Assert.assertNotNull(trytes); + assertThat(trytes.isEmpty(), Is.is(false)); } @Test public void shouldSendTrytes() { - proxy.sendTrytes(TEST_TRYTES, 18); + proxy.sendTrytes(new String[]{TEST_TRYTES}, 18); } @Test