Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.

Document dto #1143

Merged
merged 10 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/service/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -1802,4 +1802,4 @@ private synchronized AbstractResponse storeMessageStatement(String address, Stri
broadcastTransactionsStatement(powResult);
return AbstractResponse.createEmptyResponse();
}
}
}
28 changes: 18 additions & 10 deletions src/main/java/com/iota/iri/service/dto/AbstractResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@

/**
*
* Abstract response.
* Every response that the IRI API gives is a child of this class.<br/>
* Duration for every response is recorded automatically during the processing of a request.
*
**/
public abstract class AbstractResponse {

/**
* An 'empty' Response class.
* Will only contain values which are included in {@link AbstractResponse} itself.
* This is used when an API command does not need to return data.
*/
private static class Emptyness extends AbstractResponse {}

/**
* The duration it took to process this command in milliseconds
*/
private Integer duration;

/**
* Returns a String that represents this object.
* Builds a string representation of this object using multiple lines
*
* @return Returns a string representation of this object.
*/
Expand All @@ -38,27 +47,26 @@ public boolean equals(Object obj) {
}

/**
* The duration it took to process this command in milliseconds
*
* @return The duration.
* @return {@link #duration}
*/
public Integer getDuration() {
return duration;
}

/**
* Sets the duration.
*
* @param duration The duration
*
* @param duration {@link #duration}
*/
public void setDuration(Integer duration) {
this.duration = duration;
}

/**
* Returns an empty AbstractResponse
*
* @return Returns an empty AbstractResponse
* If a response doesn't need to send data back, an {@link Emptyness} is used.
* This has all the fields and functions of an AbstractResponse, and nothing more.
*
* @return Returns a plain AbstractResponse without extra fields
*/
public static AbstractResponse createEmptyResponse() {
return new Emptyness();
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/iota/iri/service/dto/AccessLimitedResponse.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package com.iota.iri.service.dto;

/**
* This class represents the core API error for accessing a command which is limited by this Node.
*
* This class represents the API error for accessing a command when it is not allowed by this Node.
*
*/
public class AccessLimitedResponse extends AbstractResponse {

/**
* The error identifies what caused this Response.
* It is a readable message identifying the command that is limited.
*/
private String error;

/**
* Creates a new {@link AccessLimitedResponse}
*
* @param error {@link #error}
* @return an {@link AccessLimitedResponse} filled with the error message
*/
public static AbstractResponse create(String error) {
AccessLimitedResponse res = new AccessLimitedResponse();
res.error = error;
return res;
}

/**
* Gets the error
*
* @return The error.
*
* @return {@link #error}
*/
public String getError() {
return error;
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/com/iota/iri/service/dto/AddedNeighborsResponse.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
package com.iota.iri.service.dto;

import com.iota.iri.service.API;

/**
*
* Contains information about the result of a successful {@code addNeighbors} API call.
* See {@link API#addNeighborsStatement} for how this response is created.
*
*/
public class AddedNeighborsResponse extends AbstractResponse {

/**
* The amount of temporally added neighbors to this node.
* Can be 0 or more.
*/
private int addedNeighbors;


/**
* Creates a new {@link AddedNeighborsResponse}
*
* @param numberOfAddedNeighbors {@link #addedNeighbors}
* @return an {@link AddedNeighborsResponse} filled with the number of added neighbors
*/
public static AbstractResponse create(int numberOfAddedNeighbors) {
AddedNeighborsResponse res = new AddedNeighborsResponse();
res.addedNeighbors = numberOfAddedNeighbors;
return res;
}

/**
* Gets the number of added neighbors.
*
* @return The number of added neighbors.
*
* @return {link #addedNeighbors}
*/
public int getAddedNeighbors() {
return addedNeighbors;
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/iota/iri/service/dto/AttachToTangleResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,37 @@

import java.util.List;

import com.iota.iri.service.API;

/**
*
* Contains information about the result of a successful {@code attachToTangle} API call.
* @see {@link API#attachToTangleStatement} for how this response is created.
*
*/
public class AttachToTangleResponse extends AbstractResponse {

/**
* List of the attached transaction trytes.
* The last 243 trytes of the return value consist of the:
* <code>trunkTransaction</code> + <code>branchTransaction</code> + <code>nonce</code>.
*/
private List<String> trytes;

/**
* Creates a new {@link AttachToTangleResponse}
* @param elements {@link #trytes}
* @return an {@link AttachToTangleResponse} filled with the trytes
*/
public static AbstractResponse create(List<String> elements) {
AttachToTangleResponse res = new AttachToTangleResponse();
res.trytes = elements;
return res;
}

/**
* The processed transactions which you can input into broadcastTransactions and storeTransactions
* The last 243 trytes basically consist of the: trunkTransaction + branchTransaction + nonce.
*
* @return The trytes.
*
* @return {@link #trytes}
*/
public List<String> getTrytes() {
return trytes;
Expand Down
35 changes: 29 additions & 6 deletions src/main/java/com/iota/iri/service/dto/CheckConsistency.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
package com.iota.iri.service.dto;

import com.iota.iri.service.API;

/**
*
* Contains information about the result of a successful {@code checkConsistency} API call.
* See {@link API#checkConsistencyStatement} for how this response is created.
*
*/
public class CheckConsistency extends AbstractResponse {

/**
* The state of all the provided tails, which is set to {@code false} on the following checks<br/>
* <ol>
* <li>Missing a reference transaction<li/>
* <li>Invalid bundle<li/>
* <li>Tails of tails are invalid<li/>
* </ol>
*/
private boolean state;

/**
* If state is {@code false}, this provides information on the cause of the inconsistency.
*/
private String info;

/**
* Creates a new {@link CheckConsistency}
* @param state {@link #state}
* @param info {@link #info}
* @return a {@link CheckConsistency} filled with the state and info
*/
public static AbstractResponse create(boolean state, String info) {
CheckConsistency res = new CheckConsistency();
res.state = state;
Expand All @@ -14,18 +39,16 @@ public static AbstractResponse create(boolean state, String info) {
}

/**
* The state of the transaction
*
* @return The state.
*
* @return {@link #state}
*/
public boolean getState() {
return state;
}

/**
* Information about the state
*
* @return The info.
*
* @return {@link #info}
*/
public String getInfo() {
return info;
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/iota/iri/service/dto/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package com.iota.iri.service.dto;

import com.iota.iri.service.API;

/**
* This class represents the core API error response.
* This class represents the response the API returns when an error has occurred.
* This can be returned for various reasons, see {@link API#process} for the cases.
**/
public class ErrorResponse extends AbstractResponse {

/**
* The error string is a readable message identifying what caused this Error response.
*/
private String error;

/**
* Creates a new {@link ErrorResponse}
*
* @param error {@link #error}
* @return an {@link ErrorResponse} filled with the error message
*/
public static AbstractResponse create(String error) {
ErrorResponse res = new ErrorResponse();
res.error = error;
return res;
}

/**
* Gets the error
*
* @return The error.
*
* @return {@link #error}
*/
public String getError() {
return error;
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/iota/iri/service/dto/ExceptionResponse.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package com.iota.iri.service.dto;

import com.iota.iri.service.API;

/**
* This class represents the core API exception response.
*
* This class represents the response the API returns when an exception has occurred.
* This can be returned for various reasons, see {@link API#process} for the cases.
*
**/
public class ExceptionResponse extends AbstractResponse {

/**
* Contains a readable message as to why an exception has been thrown.
* This is either due to invalid payload of an API request, or the message of an uncaught exception.
*/
private String exception;

/**
*
* Creates a new {@link ExceptionResponse}
*
* @param exception {@link #exception}
* @return an {@link ExceptionResponse} filled with the exception
*/
public static AbstractResponse create(String exception) {
ExceptionResponse res = new ExceptionResponse();
res.exception = exception;
return res;
}

/**
* Gets the exception
*
* @return The exception.
*
* @return {@link #exception}
*/
public String getException() {
return exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@

import java.util.List;

import com.iota.iri.service.API;

/**
*
* Contains information about the result of a successful {@code findTransactions} API call.
* See {@link API#findTransactionsStatement} for how this response is created.
*
*/
public class FindTransactionsResponse extends AbstractResponse {

/**
* The transaction hashes which are returned depend on your input.
* For each specified input value, the command will return the following:
* <code>bundles</code>: returns the list of transactions which contain the specified bundle hash.
* <code>addresses</code>: returns the list of transactions which have the specified address as an input/output field.
* <code>tags</code>: returns the list of transactions which contain the specified tag value.
* <code>approvees</code>: returns the list of transactions which reference (i.e. approve) the specified transaction.
*/
private String [] hashes;

/**
* Creates a new {@link FindTransactionsResponse}
*
* @param elements {@link #hashes}
* @return an {@link FindTransactionsResponse} filled with the hashes
*/
public static AbstractResponse create(List<String> elements) {
FindTransactionsResponse res = new FindTransactionsResponse();
res.hashes = elements.toArray(new String[] {});
return res;
}

/**
* The transaction hashes which are returned depend on your input.
* For each specified input value, the command will return the following:
* <code>bundles</code>: returns the list of transactions which contain the specified bundle hash.
* <code>addresses</code>: returns the list of transactions which have the specified address as an input/output field.
* <code>tags</code>: returns the list of transactions which contain the specified tag value.
* <code>approvees</code>: returns the list of transactions which reference (i.e. confirm) the specified transaction.
*
* @return The hashes.
*/

/**
*
* @return {@link #hashes}
*/
public String[] getHashes() {
return hashes;
}
Expand Down
Loading