improvements for IRI 1.1.0

This commit is contained in:
davassi
2016-11-02 23:47:32 +01:00
parent 6ab0f45de6
commit fcbaf19acc
12 changed files with 56 additions and 241 deletions
+14 -20
View File
@@ -5,26 +5,20 @@ package jota;
*/
public enum IotaAPICommands {
GET_NODE_INFO("getNodeInfo", 0),
GET_MILESTONE("getMilestone", 0),
GET_NEIGHBORS("getNeighbors", 0),
GET_TIPS("getTips",0),
GET_TRANSFER("getTransfers", 0), //
FIND_TRANSACTIONS("findTransactions", 0),
GET_INCLUSIONS_STATES("getInclusionStates", 0),
GET_BUNDLE("getBundle", 0),
GET_TRYTES("getTrytes", 0),
ANALYZE_TRANSACTIONS("analyzeTransactions", 0),
GET_NEW_ADDRESS("getNewAddress", 0),
PREPARE_TRANSFERS("prepareTransfers", 0),
GET_TRANSACTIONS_TO_APPROVE("getTransactionsToApprove", 0),
ATTACH_TO_TANGLE("attachToTangle", 0),
INTERRUPT_ATTACHING_TO_TANGLE("interruptAttachingToTangle", 0),
PUSH_TRANSACTIONS("pushTransactions", 0),
STORE_TRANSACTIONS("storeTransactions", 0),
TRANSFER("transfer", 0),
REPLAY_TRANSFER("replayTransfer",0),
PULL_TRANSACTIONS("pullTransactions", 0);
GET_NODE_INFO("getNodeInfo", 0),
GET_NEIGHBORS("getNeighbors", 0),
ADD_NEIGHBORS("addNeighbors", 0),
REMOVE_NEIGHBORS("removeNeighbors",0),
GET_TIPS("getTips",0),
FIND_TRANSACTIONS("findTransactions", 0),
GET_TRYTES("getTrytes", 0),
GET_INCLUSIONS_STATES("getInclusionStates", 0),
GET_BALANCES("getBalances", 0),
GET_TRANSACTIONS_TO_APPROVE("getTransactionsToApprove", 0),
ATTACH_TO_TANGLE("attachToTangle", 0),
INTERRUPT_ATTACHING_TO_TANGLE("interruptAttachingToTangle", 0),
BROADCAST_TRANSACTIONS("broadcastTransactions",0),
STORE_TRANSACTIONS("storeTransactions", 0);
private IotaAPICommands(String command, int params) {
this.command = command;
+10 -27
View File
@@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
@@ -74,11 +73,6 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public GetMilestoneResponse getMilestone(Integer index) {
final Call<GetMilestoneResponse> res = service.getMilestone(IotaGetMilestoneRequest.createMilestoneRequest(index));
return wrapCheckedException(res).body();
}
public GetNeighborsResponse getNeighbors() {
final Call<GetNeighborsResponse> res = service.getNeighbors(IotaCommandRequest.createGetNeighborsRequest());
return wrapCheckedException(res).body();
@@ -88,12 +82,6 @@ public class IotaAPIProxy {
final Call<GetTipsResponse> res = service.getTips(IotaCommandRequest.createGetTipsRequest());
return wrapCheckedException(res).body();
}
public GetTransfersResponse getTransfers(String seed, Integer securityLevel) {
final IotaGetTransferRequest tr = IotaGetTransferRequest.createGetTransferRequest(seed, securityLevel);
final Call<GetTransfersResponse> res = service.getTransfers(tr);
return wrapCheckedException(res).body();
}
public FindTransactionResponse findTransactions(String [] addresses, String [] digests, String [] approvees, String [] bundles ) {
@@ -136,26 +124,11 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public GetBundleResponse getBundle(String transaction) {
final Call<GetBundleResponse> res = service.getBundle(IotaGetBundleRequest.createIotaGetBundleRequest(transaction));
return wrapCheckedException(res).body();
}
public GetTrytesResponse getTrytes(String ... hashes) {
final Call<GetTrytesResponse> res = service.getTrytes(IotaGetTrytesRequest.createGetTrytesRequest(hashes));
return wrapCheckedException(res).body();
}
public AnalyzeTransactionResponse analyseTransaction(String ... trytes) {
final Call<AnalyzeTransactionResponse> res = service.analyzeTransactions(IotaAnalyzeTransactionRequest.createIotaAnalyzeTransactionRequest(trytes));
return wrapCheckedException(res).body();
}
public GetNewAddressResponse getNewAddress(String seed, Integer securityLevel) {
final Call<GetNewAddressResponse> res = service.getNewAddress(IotaGetNewAddressRequest.createIotaGetNewAddressRequest(seed, securityLevel));
return wrapCheckedException(res).body();
}
public GetTransactionsToApproveResponse getTransactionsToApprove(String milestone) {
final Call<GetTransactionsToApproveResponse> res = service.getTransactionsToApprove(IotaGetTransactionsToApproveRequest.createIotaGetTransactionsToApproveRequest(milestone));
return wrapCheckedException(res).body();
@@ -175,6 +148,16 @@ public class IotaAPIProxy {
}
}
// end of proxied calls.
public GetBundleResponse getBundle(String transaction) {
return IotaAPIUtils.getBundle(transaction);
}
public GetNewAddressResponse getNewAddress(String seed, Integer securityLevel) {
return IotaAPIUtils.getNewAddress(seed, securityLevel);
}
private static final String env(String env, String def) {
return Optional.ofNullable(System.getenv(env)).orElseGet(() -> {
log.warn("Enviroment variable '{}' is not defined, and actual value has not been specified. "
+4 -65
View File
@@ -20,8 +20,8 @@ public interface IotaAPIService {
/**
* Returns information about your node.
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type:
* application/json' \ -d '{"command": "getNodeInfo"}'
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getNodeInfo"}'
*
* @return a {@code NodeInfoResponse} object, if succesfull.
*/
@@ -29,18 +29,6 @@ public interface IotaAPIService {
@POST("./")
Call<GetNodeInfoResponse> getNodeInfo(@Body IotaCommandRequest request);
/**
* Returns a milestone from a given index.
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type:
* application/json' \ -d '{"command": "getMilestone", "index": 8059}'
*
* @return
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetMilestoneResponse> getMilestone(@Body IotaGetMilestoneRequest request);
/**
* Get the list of latest tips (unconfirmed transactions).
*
@@ -54,24 +42,13 @@ public interface IotaAPIService {
/**
* Get the list of latest tips (unconfirmed transactions).
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type:
* application/json' \ -d '{"command": "getTips"}'
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTips"}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetTipsResponse> getTips(@Body IotaCommandRequest request);
/**
* Get the list of transfers from a specified seed (account).
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTransfers", "seed": "AAA999999999999999999999999999999999999999999999999999999999999999999999999999999", "securityLevel": 1}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetTransfersResponse> getTransfers(@Body IotaGetTransferRequest request);
/**
* Find the transactions which match the specified input and return
*
@@ -93,17 +70,6 @@ public interface IotaAPIService {
@POST("./")
Call<GetInclusionStateResponse> getInclusionStates(@Body IotaGetInclusionStateRequest request);
/**
* Get the list of transactions which were bundled with the specified tail transaction. This call returns the full value of all individual transactions, not just the hashes.
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getBundle", "transaction": "ZJVYUGTDRPDYFGFXMKOTV9ZWSGFK9CFPXTITQLQNLPPG9YNAARMKNKYQO9GSCSBIOTGMLJUFLZWSY9999"}'
*
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetBundleResponse> getBundle(@Body IotaGetBundleRequest request);
/**
* Returns the raw trytes data of a transaction.
*
@@ -115,33 +81,6 @@ public interface IotaAPIService {
@POST("./")
Call<GetTrytesResponse> getTrytes(@Body IotaGetTrytesRequest request);
/**
*
* Analyze a raw transaction by its trytes and return the full transaction object.
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "analyzeTransactions", "trytes": ["BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCO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PAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"]}'
* */
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<AnalyzeTransactionResponse> analyzeTransactions(@Body IotaAnalyzeTransactionRequest request);
/**
* Generates a new address for your specified account (seed + securityLevel).
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getNewAddress", "seed": "AAA999999999999999999999999999999999999999999999999999999999999999999999999999999", "securityLevel": 1}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetNewAddressResponse> getNewAddress(@Body IotaGetNewAddressRequest request);
/*
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<PrepareTransfersResponse> prepareTransfers(@Body IotaPrepareTransfersRequest request);
*/
/**
* Tip selection which returns trunkTransaction and branchTransaction. The input value is the latest coordinator milestone, as provided through the getNodeInfo API call.
*
+25
View File
@@ -0,0 +1,25 @@
package jota;
import jota.dto.response.GetBundleResponse;
import jota.dto.response.GetNewAddressResponse;
import org.apache.commons.lang3.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Client Side computation service
*
* @author davassi
*/
public class IotaAPIUtils {
private static final Logger log = LoggerFactory.getLogger(IotaAPIUtils.class);
public static GetNewAddressResponse getNewAddress(final String seed, final Integer securityLevel) {
throw new NotImplementedException("Not yet implemented");
}
public static GetBundleResponse getBundle(final String transaction) {
throw new NotImplementedException("Not yet implemented");
}
}
@@ -1,17 +0,0 @@
package jota.dto.request;
import jota.IotaAPICommands;
public class IotaAnalyzeTransactionRequest extends IotaCommandRequest {
private String [] trytes;
private IotaAnalyzeTransactionRequest(final String ... trytes) {
super(IotaAPICommands.ANALYZE_TRANSACTIONS);
this.trytes = trytes;
}
public static IotaAnalyzeTransactionRequest createIotaAnalyzeTransactionRequest(String ... trytes) {
return new IotaAnalyzeTransactionRequest(trytes);
}
}
@@ -1,18 +0,0 @@
package jota.dto.request;
import jota.IotaAPICommands;
public class IotaGetBundleRequest extends IotaCommandRequest {
private String transaction;
private IotaGetBundleRequest(final String transaction) {
super(IotaAPICommands.GET_BUNDLE);
this.transaction = transaction;
}
public static IotaGetBundleRequest createIotaGetBundleRequest(String transaction) {
return new IotaGetBundleRequest(transaction);
}
}
@@ -1,17 +0,0 @@
package jota.dto.request;
import jota.IotaAPICommands;
public class IotaGetMilestoneRequest extends IotaCommandRequest {
private String index;
private IotaGetMilestoneRequest(final String index) {
super(IotaAPICommands.GET_MILESTONE);
this.index = index;
}
public static IotaGetMilestoneRequest createMilestoneRequest(Integer index) {
return new IotaGetMilestoneRequest(String.valueOf(index));
}
}
@@ -1,19 +0,0 @@
package jota.dto.request;
import jota.IotaAPICommands;
public class IotaGetNewAddressRequest extends IotaCommandRequest {
private String seed;
private Integer securityLevel;
private IotaGetNewAddressRequest(final String seed, final Integer securityLevel) {
super(IotaAPICommands.GET_NEW_ADDRESS);
this.seed = seed;
this.securityLevel = securityLevel;
}
public static IotaGetNewAddressRequest createIotaGetNewAddressRequest(String seed, Integer securityLevel) {
return new IotaGetNewAddressRequest(seed, securityLevel);
}
}
@@ -1,20 +0,0 @@
package jota.dto.request;
import com.google.gson.Gson;
import jota.IotaAPICommands;
public class IotaGetTransferRequest extends IotaCommandRequest {
private String seed;
private Integer securityLevel;
private IotaGetTransferRequest(final String seed, final Integer securityLevel) {
super(IotaAPICommands.GET_TRANSFER);
this.seed = seed;
this.securityLevel = securityLevel;
}
public static IotaGetTransferRequest createGetTransferRequest(String seed, Integer securityLevel) {
return new IotaGetTransferRequest(seed, securityLevel);
}
}