added getAccountData

This commit is contained in:
pinpong 2017-08-13 14:36:56 +02:00
parent 907dd1d95e
commit 2a9a6abd35
4 changed files with 127 additions and 13 deletions

View File

@ -35,20 +35,20 @@
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
@ -66,6 +66,7 @@
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
@ -84,6 +85,11 @@
<goals>
<goal>jar</goal>
</goals>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
<configuration>

View File

@ -706,6 +706,53 @@ public class IotaAPI extends IotaAPICore {
return GetBundleResponse.create(bundle.getTransactions(), stopWatch.getElapsedTimeMili());
}
/**
* Similar to getTransfers, just that it returns additional account data
*
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred.
* @param security The Security level of private key / seed.
* @param start Starting key index.
* @param end Ending key index.
* @param inclusionStates If <code>true</code>, it gets the inclusion states of the transfers.
* @param threshold Min balance required.
* @throws InvalidBundleException is thrown if an invalid bundle was found or provided.
* @throws ArgumentException is thrown when an invalid argument is provided.
* @throws InvalidSignatureException is thrown when an invalid signature is encountered.
* @throws InvalidTrytesException is thrown when invalid trytes is provided.
* @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
* @throws NoInclusionStatesException when it not possible to get a inclusion state.
* @throws NoNodeInfoException is thrown when its not possible to get node info.
*/
public GetAccountDataResponse getAccountData(String seed, int security, int start, int end, boolean inclusionStates, long threshold)
throws InvalidBundleException, ArgumentException, InvalidSignatureException,
InvalidTrytesException, InvalidSecurityLevelException, InvalidAddressException, NoInclusionStatesException, NoNodeInfoException {
StopWatch stopWatch = new StopWatch();
// validate seed
if ((!InputValidator.isValidSeed(seed))) {
throw new IllegalStateException("Invalid Seed");
}
if (security < 1 || security > 3) {
throw new InvalidSecurityLevelException();
}
// If start value bigger than end, return error
// or if difference between end and start is bigger than 500 keys
if (start > end || end > (start + 500)) {
throw new IllegalStateException("Invalid inputs provided");
}
GetNewAddressResponse gna = getNewAddress(seed, security, 0, true, 0, true);
GetTransferResponse gtr = getTransfers(seed, security, start, end, inclusionStates);
GetBalancesAndFormatResponse gbr = getInputs(seed, security, start, end, threshold);
return GetAccountDataResponse.create(gna.getAddresses(), gtr.getTransfers(), gbr.getTotalBalance(), stopWatch.getElapsedTimeMili());
}
/**
* Replays a transfer by doing Proof of Work again.
*

View File

@ -0,0 +1,55 @@
package jota.dto.response;
import jota.model.Bundle;
import java.util.List;
/**
* Response of api request 'getAccountData'.
**/
public class GetAccountDataResponse extends AbstractResponse {
private List<String> addresses;
private Bundle[] transferBundle;
private long balance;
/**
* Initializes a new instance of the GetAccountDataResponse class.
*/
public static GetAccountDataResponse create(List<String> addresses, Bundle[] transferBundle, long balance, long duration) {
GetAccountDataResponse res = new GetAccountDataResponse();
res.addresses = addresses;
res.transferBundle = transferBundle;
res.balance = balance;
res.setDuration(duration);
return res;
}
/**
* Gets the addresses.
*
* @return The addresses.
*/
public List<String> getAddresses() {
return addresses;
}
/**
* Gets the transfers.
*
* @return The transfers.
*/
public Bundle[] getTransfers() {
return transferBundle;
}
/**
* Gets the balance.
*
* @return The balance.
*/
public long getBalance() {
return balance;
}
}

View File

@ -103,7 +103,7 @@ public class IotaAPITest {
@Test
public void shouldCreate100Addresses() throws InvalidSecurityLevelException, InvalidAddressException {
GetNewAddressResponse res = iotaClient.getNewAddress(TEST_SEED1, 2, 0, false, 100, false);
GetNewAddressResponse res = iotaClient.getNewAddress(TEST_SEED1, 2, 0, false, 100, false);
assertEquals(res.getAddresses().size(), 100);
}
@ -130,6 +130,12 @@ public class IotaAPITest {
assertThat(ftr, IsNull.notNullValue());
}
@Test
public void shouldGetAccountData() throws NoInclusionStatesException, InvalidTrytesException, NoNodeInfoException, ArgumentException, InvalidBundleException, InvalidSecurityLevelException, InvalidAddressException, InvalidSignatureException {
GetAccountDataResponse gad = iotaClient.getAccountData(TEST_SEED1, 2, 0, 0, true, 100);
assertThat(gad, IsNull.notNullValue());
}
@Test(expected = IllegalAccessError.class)
public void shouldNotGetBundle() throws InvalidBundleException, ArgumentException, InvalidSignatureException {
GetBundleResponse gbr = iotaClient.getBundle("SADASD");