Introducing node hop feature to some blockchain API handler classes (GetBlockHeader, GetKeyReferences, GetLimitOrders, GetMarketHistory, GetObjects, GetRelativeAccountHistory)
This commit is contained in:
parent
5369976f08
commit
7313279f95
7 changed files with 211 additions and 113 deletions
|
@ -34,12 +34,19 @@ public class GetBlockHeader extends BaseGrapheneHandler {
|
||||||
private int currentId = LOGIN_ID;
|
private int currentId = LOGIN_ID;
|
||||||
private int apiId = -1;
|
private int apiId = -1;
|
||||||
|
|
||||||
public GetBlockHeader(long blockNumber, WitnessResponseListener listener){
|
private boolean mOneTime;
|
||||||
|
|
||||||
|
public GetBlockHeader(long blockNumber, boolean oneTime, WitnessResponseListener listener){
|
||||||
super(listener);
|
super(listener);
|
||||||
this.blockNumber = blockNumber;
|
this.blockNumber = blockNumber;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GetBlockHeader(long blockNumber, WitnessResponseListener listener){
|
||||||
|
this(blockNumber, true, listener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> loginParams = new ArrayList<>();
|
ArrayList<Serializable> loginParams = new ArrayList<>();
|
||||||
|
@ -58,7 +65,9 @@ public class GetBlockHeader extends BaseGrapheneHandler {
|
||||||
BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
|
BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
|
||||||
if(baseResponse.error != null){
|
if(baseResponse.error != null){
|
||||||
mListener.onError(baseResponse.error);
|
mListener.onError(baseResponse.error);
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
currentId++;
|
currentId++;
|
||||||
ArrayList<Serializable> emptyParams = new ArrayList<>();
|
ArrayList<Serializable> emptyParams = new ArrayList<>();
|
||||||
|
@ -80,9 +89,11 @@ public class GetBlockHeader extends BaseGrapheneHandler {
|
||||||
Type RelativeAccountHistoryResponse = new TypeToken<WitnessResponse<BlockHeader>>(){}.getType();
|
Type RelativeAccountHistoryResponse = new TypeToken<WitnessResponse<BlockHeader>>(){}.getType();
|
||||||
WitnessResponse<BlockHeader> transfersResponse = gson.fromJson(response, RelativeAccountHistoryResponse);
|
WitnessResponse<BlockHeader> transfersResponse = gson.fromJson(response, RelativeAccountHistoryResponse);
|
||||||
mListener.onSuccess(transfersResponse);
|
mListener.onSuccess(transfersResponse);
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,29 @@ public class GetKeyReferences extends BaseGrapheneHandler {
|
||||||
|
|
||||||
private List<Address> addresses;
|
private List<Address> addresses;
|
||||||
|
|
||||||
public GetKeyReferences(Address address, WitnessResponseListener listener){
|
private boolean mOneTime;
|
||||||
|
|
||||||
|
public GetKeyReferences(Address address, boolean oneTime, WitnessResponseListener listener){
|
||||||
super(listener);
|
super(listener);
|
||||||
addresses = new ArrayList<>();
|
addresses = new ArrayList<>();
|
||||||
addresses.add(address);
|
addresses.add(address);
|
||||||
|
this.mOneTime = oneTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetKeyReferences(List<Address> addresses, WitnessResponseListener listener) {
|
public GetKeyReferences(List<Address> addresses, boolean oneTime, WitnessResponseListener listener) {
|
||||||
super(listener);
|
super(listener);
|
||||||
this.addresses = addresses;
|
this.addresses = addresses;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetKeyReferences(Address address, WitnessResponseListener listener){
|
||||||
|
this(address, true, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetKeyReferences(List<Address> addresses, WitnessResponseListener listener) {
|
||||||
|
this(addresses, true, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,8 +76,10 @@ public class GetKeyReferences extends BaseGrapheneHandler {
|
||||||
} else {
|
} else {
|
||||||
this.mListener.onSuccess(witnessResponse);
|
this.mListener.onSuccess(witnessResponse);
|
||||||
}
|
}
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||||
|
|
|
@ -31,14 +31,22 @@ public class GetLimitOrders extends BaseGrapheneHandler {
|
||||||
private int limit;
|
private int limit;
|
||||||
private WitnessResponseListener mListener;
|
private WitnessResponseListener mListener;
|
||||||
|
|
||||||
public GetLimitOrders(String a, String b, int limit, WitnessResponseListener mListener) {
|
private boolean mOneTime;
|
||||||
|
|
||||||
|
|
||||||
|
public GetLimitOrders(String a, String b, int limit, boolean oneTime, WitnessResponseListener mListener) {
|
||||||
super(mListener);
|
super(mListener);
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
this.mListener = mListener;
|
this.mListener = mListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GetLimitOrders(String a, String b, int limit, WitnessResponseListener mListener) {
|
||||||
|
this(a, b, limit, true, mListener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> accountParams = new ArrayList<>();
|
ArrayList<Serializable> accountParams = new ArrayList<>();
|
||||||
|
@ -70,8 +78,10 @@ public class GetLimitOrders extends BaseGrapheneHandler {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||||
|
@ -83,12 +93,16 @@ public class GetLimitOrders extends BaseGrapheneHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
|
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
|
||||||
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
|
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
|
||||||
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
mListener.onError(new BaseResponse.Error(cause.getMessage()));
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,16 +44,23 @@ public class GetMarketHistory extends BaseGrapheneHandler {
|
||||||
private int apiId = -1;
|
private int apiId = -1;
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
|
|
||||||
public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){
|
private boolean mOneTime;
|
||||||
|
|
||||||
|
public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, boolean oneTime, WitnessResponseListener listener){
|
||||||
super(listener);
|
super(listener);
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.quote = quote;
|
this.quote = quote;
|
||||||
this.bucket = bucket;
|
this.bucket = bucket;
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){
|
||||||
|
this(base, quote, bucket, start, end, true, listener);
|
||||||
|
}
|
||||||
|
|
||||||
public Asset getBase() {
|
public Asset getBase() {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +106,7 @@ public class GetMarketHistory extends BaseGrapheneHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(){
|
public void disconnect(){
|
||||||
if(mWebsocket != null && mWebsocket.isOpen()){
|
if(mWebsocket != null && mWebsocket.isOpen() && mOneTime){
|
||||||
mWebsocket.disconnect();
|
mWebsocket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +138,9 @@ public class GetMarketHistory extends BaseGrapheneHandler {
|
||||||
BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
|
BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
|
||||||
if(baseResponse.error != null){
|
if(baseResponse.error != null){
|
||||||
mListener.onError(baseResponse.error);
|
mListener.onError(baseResponse.error);
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
currentId++;
|
currentId++;
|
||||||
ArrayList<Serializable> emptyParams = new ArrayList<>();
|
ArrayList<Serializable> emptyParams = new ArrayList<>();
|
||||||
|
|
|
@ -33,9 +33,16 @@ import de.bitsharesmunich.graphenej.models.WitnessResponse;
|
||||||
public class GetObjects extends BaseGrapheneHandler {
|
public class GetObjects extends BaseGrapheneHandler {
|
||||||
private List<String> ids;
|
private List<String> ids;
|
||||||
|
|
||||||
public GetObjects(List<String> ids, WitnessResponseListener listener){
|
private boolean mOneTime;
|
||||||
|
|
||||||
|
public GetObjects(List<String> ids, boolean oneTime, WitnessResponseListener listener){
|
||||||
super(listener);
|
super(listener);
|
||||||
this.ids = ids;
|
this.ids = ids;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetObjects(List<String> ids, WitnessResponseListener listener){
|
||||||
|
this(ids, true, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,8 +99,10 @@ public class GetObjects extends BaseGrapheneHandler {
|
||||||
WitnessResponse<List<GrapheneObject>> output = new WitnessResponse<>();
|
WitnessResponse<List<GrapheneObject>> output = new WitnessResponse<>();
|
||||||
output.result = parsedResult;
|
output.result = parsedResult;
|
||||||
mListener.onSuccess(output);
|
mListener.onSuccess(output);
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||||
|
|
|
@ -48,36 +48,64 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
|
||||||
private int currentId = 1;
|
private int currentId = 1;
|
||||||
private int apiId = -1;
|
private int apiId = -1;
|
||||||
|
|
||||||
|
private boolean mOneTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that takes all possible parameters.
|
* Constructor that takes all possible parameters.
|
||||||
* @param userAccount The user account to be queried
|
* @param userAccount The user account to be queried
|
||||||
* @param stop Sequence number of earliest operation
|
* @param stop Sequence number of earliest operation
|
||||||
* @param limit Maximum number of operations to retrieve (must not exceed 100)
|
* @param limit Maximum number of operations to retrieve (must not exceed 100)
|
||||||
* @param start Sequence number of the most recent operation to retrieve
|
* @param start Sequence number of the most recent operation to retrieve
|
||||||
|
* @param oneTime Boolean value indicating if websocket must be closed or not after request
|
||||||
|
* @param listener Listener to be notified with the result of this query
|
||||||
|
*/
|
||||||
|
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, boolean oneTime, WitnessResponseListener listener){
|
||||||
|
super(listener);
|
||||||
|
if(limit > MAX_LIMIT) limit = MAX_LIMIT;
|
||||||
|
this.mUserAccount = userAccount;
|
||||||
|
this.stop = stop;
|
||||||
|
this.limit = limit;
|
||||||
|
this.start = start;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
|
this.mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that uses the default values, and sets the limit to its maximum possible value.
|
||||||
|
* @param userAccount The user account to be queried
|
||||||
|
* @param oneTime Boolean value indicating if websocket must be closed or not after request
|
||||||
|
* @param listener Listener to be notified with the result of this query
|
||||||
|
*/
|
||||||
|
public GetRelativeAccountHistory(UserAccount userAccount, boolean oneTime, WitnessResponseListener listener){
|
||||||
|
super(listener);
|
||||||
|
this.mUserAccount = userAccount;
|
||||||
|
this.stop = DEFAULT_STOP;
|
||||||
|
this.limit = MAX_LIMIT;
|
||||||
|
this.start = DEFAULT_START;
|
||||||
|
this.mOneTime = oneTime;
|
||||||
|
this.mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that takes all possible parameters except for oneTime (which will be always true here)
|
||||||
|
* @param userAccount The user account to be queried
|
||||||
|
* @param stop Sequence number of earliest operation
|
||||||
|
* @param limit Maximum number of operations to retrieve (must not exceed 100)
|
||||||
|
* @param start Sequence number of the most recent operation to retrieve
|
||||||
* @param listener Listener to be notified with the result of this query
|
* @param listener Listener to be notified with the result of this query
|
||||||
*/
|
*/
|
||||||
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){
|
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){
|
||||||
super(listener);
|
this(userAccount, stop, limit, start, true, listener);
|
||||||
if(limit > MAX_LIMIT) limit = MAX_LIMIT;
|
|
||||||
this.mUserAccount = userAccount;
|
|
||||||
this.stop = stop;
|
|
||||||
this.limit = limit;
|
|
||||||
this.start = start;
|
|
||||||
this.mListener = listener;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that uses the default values, and sets the limit to its maximum possible value.
|
* Constructor that uses the default values, and sets the limit to its maximum possible value.
|
||||||
|
* oneTime is always set to true at this constructor.
|
||||||
* @param userAccount The user account to be queried
|
* @param userAccount The user account to be queried
|
||||||
* @param listener Listener to be notified with the result of this query
|
* @param listener Listener to be notified with the result of this query
|
||||||
*/
|
*/
|
||||||
public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){
|
public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){
|
||||||
super(listener);
|
this(userAccount, true, listener);
|
||||||
this.mUserAccount = userAccount;
|
|
||||||
this.stop = DEFAULT_STOP;
|
|
||||||
this.limit = MAX_LIMIT;
|
|
||||||
this.start = DEFAULT_START;
|
|
||||||
this.mListener = listener;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,7 +126,9 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
|
||||||
BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
|
BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class);
|
||||||
if(baseResponse.error != null){
|
if(baseResponse.error != null){
|
||||||
mListener.onError(baseResponse.error);
|
mListener.onError(baseResponse.error);
|
||||||
|
if(mOneTime){
|
||||||
websocket.disconnect();
|
websocket.disconnect();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
currentId++;
|
currentId++;
|
||||||
ArrayList<Serializable> emptyParams = new ArrayList<>();
|
ArrayList<Serializable> emptyParams = new ArrayList<>();
|
||||||
|
@ -153,7 +183,7 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
|
||||||
* Disconnects the websocket
|
* Disconnects the websocket
|
||||||
*/
|
*/
|
||||||
public void disconnect(){
|
public void disconnect(){
|
||||||
if(mWebsocket != null && mWebsocket.isOpen()){
|
if(mWebsocket != null && mWebsocket.isOpen() && mOneTime){
|
||||||
mWebsocket.disconnect();
|
mWebsocket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import de.bitsharesmunich.graphenej.api.GetAccounts;
|
||||||
import de.bitsharesmunich.graphenej.api.GetAccountBalances;
|
import de.bitsharesmunich.graphenej.api.GetAccountBalances;
|
||||||
import de.bitsharesmunich.graphenej.api.GetAccountByName;
|
import de.bitsharesmunich.graphenej.api.GetAccountByName;
|
||||||
import de.bitsharesmunich.graphenej.api.GetAllAssetHolders;
|
import de.bitsharesmunich.graphenej.api.GetAllAssetHolders;
|
||||||
|
import de.bitsharesmunich.graphenej.api.GetBlockHeader;
|
||||||
import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException;
|
import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException;
|
||||||
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
||||||
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
||||||
|
@ -24,6 +25,7 @@ public class NodeConnectionTest {
|
||||||
private String BLOCK_PAY_DE = System.getenv("OPENLEDGER_EU");
|
private String BLOCK_PAY_DE = System.getenv("OPENLEDGER_EU");
|
||||||
private String ACCOUNT_ID = System.getenv("ACCOUNT_ID");
|
private String ACCOUNT_ID = System.getenv("ACCOUNT_ID");
|
||||||
private String ACCOUNT_NAME = System.getenv("ACCOUNT_NAME");
|
private String ACCOUNT_NAME = System.getenv("ACCOUNT_NAME");
|
||||||
|
private long BlOCK_TEST_NUMBER = Long.parseLong(System.getenv("BlOCK_TEST_NUMBER"));
|
||||||
private Asset BTS = new Asset("1.3.0");
|
private Asset BTS = new Asset("1.3.0");
|
||||||
private Asset BITDOLAR = new Asset("1.3.121"); //USD Smartcoin
|
private Asset BITDOLAR = new Asset("1.3.121"); //USD Smartcoin
|
||||||
private Asset BITEURO = new Asset("1.3.120"); //EUR Smartcoin
|
private Asset BITEURO = new Asset("1.3.120"); //EUR Smartcoin
|
||||||
|
@ -52,77 +54,6 @@ public class NodeConnectionTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private TimerTask mSubscribeGetAccountBalancesTask = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
System.out.println("Adding GetAccountBalances here");
|
|
||||||
try{
|
|
||||||
UserAccount userAccount = new UserAccount(ACCOUNT_ID);
|
|
||||||
ArrayList<Asset> assetList = new ArrayList<>();
|
|
||||||
assetList.add(BTS);
|
|
||||||
assetList.add(BITDOLAR);
|
|
||||||
assetList.add(BITEURO);
|
|
||||||
nodeConnection.addRequestHandler(new GetAccountBalances(userAccount, false, assetList, new WitnessResponseListener(){
|
|
||||||
@Override
|
|
||||||
public void onSuccess(WitnessResponse response) {
|
|
||||||
System.out.println("getAccountBalances.onSuccess");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(BaseResponse.Error error) {
|
|
||||||
System.out.println("getAccountBalances.onError. Msg: "+ error.message);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}catch(RepeatedRequestIdException e){
|
|
||||||
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private TimerTask mSubscribeGetAccountByNameTask = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
System.out.println("Adding GetAccountByName here");
|
|
||||||
try{
|
|
||||||
nodeConnection.addRequestHandler(new GetAccountByName(ACCOUNT_NAME, false, new WitnessResponseListener(){
|
|
||||||
@Override
|
|
||||||
public void onSuccess(WitnessResponse response) {
|
|
||||||
System.out.println("GetAccountByName.onSuccess");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(BaseResponse.Error error) {
|
|
||||||
System.out.println("GetAccountByName.onError. Msg: "+ error.message);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}catch(RepeatedRequestIdException e){
|
|
||||||
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private TimerTask mSubscribeGetAllAssetHoldersTask = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
System.out.println("Adding GetAllAssetHolders request");
|
|
||||||
try{
|
|
||||||
nodeConnection.addRequestHandler(new GetAllAssetHolders(false, new WitnessResponseListener(){
|
|
||||||
@Override
|
|
||||||
public void onSuccess(WitnessResponse response) {
|
|
||||||
System.out.println("GetAllAssetHolders.onSuccess");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(BaseResponse.Error error) {
|
|
||||||
System.out.println("GetAllAssetHolders.onError. Msg: "+ error.message);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}catch(RepeatedRequestIdException e){
|
|
||||||
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private TimerTask releaseTask = new TimerTask() {
|
private TimerTask releaseTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -157,11 +88,29 @@ public class NodeConnectionTest {
|
||||||
public void testGetAccountBalancesRequest(){
|
public void testGetAccountBalancesRequest(){
|
||||||
nodeConnection = NodeConnection.getInstance();
|
nodeConnection = NodeConnection.getInstance();
|
||||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||||
nodeConnection.connect("", "", true, mErrorListener);
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
Timer timer = new Timer();
|
System.out.println("Adding GetAccountBalances here");
|
||||||
timer.schedule(mSubscribeGetAccountBalancesTask, 5000);
|
try{
|
||||||
timer.schedule(releaseTask, 30000);
|
UserAccount userAccount = new UserAccount(ACCOUNT_ID);
|
||||||
|
ArrayList<Asset> assetList = new ArrayList<>();
|
||||||
|
assetList.add(BTS);
|
||||||
|
assetList.add(BITDOLAR);
|
||||||
|
assetList.add(BITEURO);
|
||||||
|
nodeConnection.addRequestHandler(new GetAccountBalances(userAccount, false, assetList, new WitnessResponseListener(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("getAccountBalances.onSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("getAccountBalances.onError. Msg: "+ error.message);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}catch(RepeatedRequestIdException e){
|
||||||
|
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// Holding this thread while we get update notifications
|
// Holding this thread while we get update notifications
|
||||||
|
@ -177,11 +126,24 @@ public class NodeConnectionTest {
|
||||||
public void testGetAccountByNameRequest(){
|
public void testGetAccountByNameRequest(){
|
||||||
nodeConnection = NodeConnection.getInstance();
|
nodeConnection = NodeConnection.getInstance();
|
||||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||||
nodeConnection.connect("", "", true, mErrorListener);
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
Timer timer = new Timer();
|
System.out.println("Adding GetAccountByName here");
|
||||||
timer.schedule(mSubscribeGetAccountByNameTask, 5000);
|
try{
|
||||||
timer.schedule(releaseTask, 30000);
|
nodeConnection.addRequestHandler(new GetAccountByName(ACCOUNT_NAME, false, new WitnessResponseListener(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("GetAccountByName.onSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("GetAccountByName.onError. Msg: "+ error.message);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}catch(RepeatedRequestIdException e){
|
||||||
|
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// Holding this thread while we get update notifications
|
// Holding this thread while we get update notifications
|
||||||
|
@ -197,11 +159,24 @@ public class NodeConnectionTest {
|
||||||
public void testGetAllAssetHoldersRequest(){
|
public void testGetAllAssetHoldersRequest(){
|
||||||
nodeConnection = NodeConnection.getInstance();
|
nodeConnection = NodeConnection.getInstance();
|
||||||
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||||
nodeConnection.connect("", "", true, mErrorListener);
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
Timer timer = new Timer();
|
System.out.println("Adding GetAllAssetHolders request");
|
||||||
timer.schedule(mSubscribeGetAllAssetHoldersTask, 5000);
|
try{
|
||||||
timer.schedule(releaseTask, 30000);
|
nodeConnection.addRequestHandler(new GetAllAssetHolders(false, new WitnessResponseListener(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("GetAllAssetHolders.onSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("GetAllAssetHolders.onError. Msg: "+ error.message);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}catch(RepeatedRequestIdException e){
|
||||||
|
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// Holding this thread while we get update notifications
|
// Holding this thread while we get update notifications
|
||||||
|
@ -213,6 +188,42 @@ public class NodeConnectionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBlockHeaderRequest(){
|
||||||
|
nodeConnection = NodeConnection.getInstance();
|
||||||
|
nodeConnection.addNodeUrl(BLOCK_PAY_DE);
|
||||||
|
nodeConnection.connect("", "", false, mErrorListener);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Adding GetBlockHeader request");
|
||||||
|
try{
|
||||||
|
nodeConnection.addRequestHandler(new GetBlockHeader(BlOCK_TEST_NUMBER,false, new WitnessResponseListener(){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
System.out.println("GetBlockHeader.onSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
System.out.println("GetBlockHeader.onError. Msg: "+ error.message);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}catch(RepeatedRequestIdException e){
|
||||||
|
System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try{
|
||||||
|
// Holding this thread while we get update notifications
|
||||||
|
synchronized (this){
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
}catch(InterruptedException e){
|
||||||
|
System.out.println("InterruptedException. Msg: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private WitnessResponseListener mErrorListener = new WitnessResponseListener() {
|
private WitnessResponseListener mErrorListener = new WitnessResponseListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue