From 3a3f7f6a596e85ef373ebd1af0fb78c1b63468b7 Mon Sep 17 00:00:00 2001 From: Oliver Nitzschke Date: Fri, 23 Dec 2016 09:48:15 +0100 Subject: [PATCH] added getLatestInclusion (#14) * added getLatestInclusion * added findTransactionObjects * added documentation --- src/main/java/jota/IotaAPIProxy.java | 63 +++++++++++++++++++----- src/test/java/jota/IotaAPIProxyTest.java | 11 +++++ 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/main/java/jota/IotaAPIProxy.java b/src/main/java/jota/IotaAPIProxy.java index 1f9de61..7946d67 100644 --- a/src/main/java/jota/IotaAPIProxy.java +++ b/src/main/java/jota/IotaAPIProxy.java @@ -250,15 +250,15 @@ public class IotaAPIProxy { * sendTrytes * prepareTransfers * getInputs - + * getLatestInclusion + getTransfers sendTransfer getBundle getTransactionsObjects findTransactionObjects - getLatestInclusion - + replayBundle broadcastBundle getAccountData @@ -309,13 +309,7 @@ public class IotaAPIProxy { } return trx; } - - public List findAndGetTxs(final String addresses) { - final FindTransactionResponse res = findTransactionsByAddresses(addresses); - return getTransactionsObjects(res.getHashes()); - } - /** * Wrapper function for getTrytes and transactionObjects * gets the trytes and transaction object from a list of transaction hashes @@ -326,7 +320,7 @@ public class IotaAPIProxy { * @returns {function} callback * @returns {object} success **/ - public List getTransactionsObjects(String ... hashes) { + public List getTransactionsObjects(String[] hashes) { if (!InputValidator.isArrayOfHashes(hashes)) { throw new IllegalStateException("Not an Array of Hashes: " + Arrays.toString(hashes)); @@ -342,6 +336,26 @@ public class IotaAPIProxy { return trxs; } + /** + * Wrapper function for findTransactions, getTrytes and transactionObjects + * Returns the transactionObject of a transaction hash. The input can be a valid + * findTransactions input + * + * @param {object} input + * @method getTransactionsObjects + * @returns {function} callback + * @returns {object} success + **/ + public List findTransactionObjects(String[] input) { + FindTransactionResponse ftr = findTransactions(input, null, null, null); + if (ftr == null || ftr.getHashes() == null) + + return null; + + // get the transaction objects of the transactions + return getTransactionsObjects(ftr.getHashes()); + } + /** * Prepares transfer by generating bundle, finding and signing inputs * @@ -578,11 +592,36 @@ public class IotaAPIProxy { } throw new IllegalStateException("Not enough balance"); } - + + /** + * Gets the associated bundle transactions of a single transaction + * Does validation of signatures, total sum as well as bundle order + * + * @method getBundle + * @param {string} transaction Hash of a tail transaction + * @returns {list} bundle Transaction objects + **/ public GetBundleResponse getBundle(String transaction) { return null; //IotaAPIUtils.getBundle(transaction); } - + + /** + * Wrapper function for getNodeInfo and getInclusionStates + * + * @method getLatestInclusion + * @param {array} hashes + * @returns {function} callback + * @returns {array} state + **/ + public GetInclusionStateResponse getLatestInclusion(String[] hashes) { + GetNodeInfoResponse getNodeInfoResponse = getNodeInfo(); + if (getNodeInfoResponse == null) return null; + + String[] latestMilestone = {getNodeInfoResponse.getLatestSolidSubtangleMilestone()}; + + return getInclusionStates(hashes, latestMilestone); + } + 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 43b4c94..ffb52ac 100644 --- a/src/test/java/jota/IotaAPIProxyTest.java +++ b/src/test/java/jota/IotaAPIProxyTest.java @@ -169,4 +169,15 @@ public class IotaAPIProxyTest { public void shouldSendTrytes() { proxy.sendTrytes(TEST_TRYTES, 18); } + + @Test + public void shouldGetLastInclusionState() { + GetInclusionStateResponse res = proxy.getLatestInclusion(new String[]{TEST_HASH}); + assertThat(res.getStates(), IsNull.notNullValue()); + } + + @Test + public void shouldFindTransactionObjects() { + assertThat(proxy.findTransactionObjects(new String[]{TEST_ADDRESS_WITH_CHECKSUM}), IsNull.notNullValue()); + } } \ No newline at end of file