Revert network changes
This commit is contained in:
parent
e0903c0a26
commit
5fb847ba1c
4 changed files with 155 additions and 227 deletions
|
@ -8,6 +8,7 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cy.agorise.crystalwallet.application.constant.BitsharesConstant;
|
||||||
import cy.agorise.crystalwallet.dao.BitsharesAssetDao;
|
import cy.agorise.crystalwallet.dao.BitsharesAssetDao;
|
||||||
import cy.agorise.crystalwallet.dao.CryptoCoinBalanceDao;
|
import cy.agorise.crystalwallet.dao.CryptoCoinBalanceDao;
|
||||||
import cy.agorise.crystalwallet.dao.CryptoCurrencyDao;
|
import cy.agorise.crystalwallet.dao.CryptoCurrencyDao;
|
||||||
|
@ -80,8 +81,6 @@ public abstract class GrapheneApiGenerator {
|
||||||
*/
|
*/
|
||||||
private static HashMap<Long,SubscriptionListener> currentBitsharesListener = new HashMap<>();
|
private static HashMap<Long,SubscriptionListener> currentBitsharesListener = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the data of an account searching by it's id
|
* Retrieves the data of an account searching by it's id
|
||||||
*
|
*
|
||||||
|
@ -129,10 +128,7 @@ public abstract class GrapheneApiGenerator {
|
||||||
List<UserAccount> accounts = resp.get(0);
|
List<UserAccount> accounts = resp.get(0);
|
||||||
if(accounts.size() > 0){
|
if(accounts.size() > 0){
|
||||||
for(UserAccount account : accounts) {
|
for(UserAccount account : accounts) {
|
||||||
request.getListener().success(account, request.getId());
|
request.getListener().success(account,request.getId());}}}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.getListener().fail(request.getId());
|
request.getListener().fail(request.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +292,6 @@ public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the asset ifnormation using the id of the net
|
* Gets the asset ifnormation using the id of the net
|
||||||
*
|
|
||||||
* @param assetIds The list of the ids to retrieve
|
* @param assetIds The list of the ids to retrieve
|
||||||
* @param request the api request object, to answer this petition
|
* @param request the api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
|
@ -417,23 +412,17 @@ public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
currentBitsharesListener.put(accountId,balanceListener);
|
currentBitsharesListener.put(accountId,balanceListener);
|
||||||
bitsharesSubscriptionHub.addSubscriptionListener(balanceListener);
|
bitsharesSubscriptionHub.addSubscriptionListener(balanceListener);
|
||||||
try {
|
|
||||||
if (!subscriptionThread.isConnected() && !subscriptionThread.isAlive()) {
|
|
||||||
|
|
||||||
|
if(!subscriptionThread.isConnected()){
|
||||||
subscriptionThread.start();
|
subscriptionThread.start();
|
||||||
|
}else if(!bitsharesSubscriptionHub.isSubscribed()){
|
||||||
} else if (bitsharesSubscriptionHub != null && !bitsharesSubscriptionHub.isSubscribed()) {
|
|
||||||
bitsharesSubscriptionHub.resubscribe();
|
bitsharesSubscriptionHub.resubscribe();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to save a transaction retrieved from the update
|
* Function to save a transaction retrieved from the update
|
||||||
*
|
|
||||||
* @param transaction The transaction db object
|
* @param transaction The transaction db object
|
||||||
* @param currency The currency of the transaccion
|
* @param currency The currency of the transaccion
|
||||||
* @param accountBitsharesId The id of the account in the bitshares network
|
* @param accountBitsharesId The id of the account in the bitshares network
|
||||||
|
@ -584,7 +573,7 @@ public abstract class GrapheneApiGenerator {
|
||||||
public void onError(BaseResponse.Error error) {
|
public void onError(BaseResponse.Error error) {
|
||||||
request.getListener().fail(request.getId());
|
request.getListener().fail(request.getId());
|
||||||
}
|
}
|
||||||
}), CryptoNetManager.getURL(CryptoNet.BITSHARES)); //todo change equivalent url for current server url
|
}), BitsharesConstant.EQUIVALENT_URL); //todo change equivalent url for current server url
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,7 +589,7 @@ public abstract class GrapheneApiGenerator {
|
||||||
for(BitsharesAsset quoteAsset : quoteAssets){
|
for(BitsharesAsset quoteAsset : quoteAssets){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(),
|
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(),
|
||||||
quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,
|
quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,
|
||||||
quoteAsset, context)), CryptoNetManager.getURL(CryptoNet.BITSHARES)); //todo change equivalent url for current server url
|
quoteAsset,context)), BitsharesConstant.EQUIVALENT_URL); //todo change equivalent url for current server url
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -703,4 +692,5 @@ public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package cy.agorise.crystalwallet.network;
|
package cy.agorise.crystalwallet.network;
|
||||||
|
|
||||||
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
|
||||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||||
import cy.agorise.graphenej.interfaces.WitnessResponseListener;
|
import cy.agorise.graphenej.interfaces.WitnessResponseListener;
|
||||||
import cy.agorise.graphenej.models.BaseResponse;
|
import cy.agorise.graphenej.models.BaseResponse;
|
||||||
|
@ -24,21 +23,15 @@ public class BitsharesCryptoNetVerifier extends CryptoNetVerifier {
|
||||||
private final String CHAIN_ID = "9cf6f255a208100d2bb275a3c52f4b1589b7ec9c9bfc2cb2a5fe6411295106d8";//testnet
|
private final String CHAIN_ID = "9cf6f255a208100d2bb275a3c52f4b1589b7ec9c9bfc2cb2a5fe6411295106d8";//testnet
|
||||||
//private final String CHAIN_ID = "4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8";//mainnet
|
//private final String CHAIN_ID = "4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8";//mainnet
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkURL(final String url) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public BitsharesCryptoNetVerifier(){
|
|
||||||
|
|
||||||
/**/
|
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
thread = new WebSocketThread(new GetChainId(new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetChainId(new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
if(response.result instanceof String) {
|
if(response.result instanceof String) {
|
||||||
if(response.result.equals(CHAIN_ID)) {
|
if(response.result.equals(CHAIN_ID)) {
|
||||||
CryptoNetManager.verifiedCryptoNetURL(cryptoNet, null, System.currentTimeMillis() - startTime);
|
CryptoNetManager.verifiedCryptoNetURL(cryptoNet, url, System.currentTimeMillis() - startTime);
|
||||||
}else{
|
}else{
|
||||||
System.out.println(" BitsharesCryptoNetVerifier Error we are not in the net current chain id " + response.result + " excepted " + CHAIN_ID);
|
System.out.println(" BitsharesCryptoNetVerifier Error we are not in the net current chain id " + response.result + " excepted " + CHAIN_ID);
|
||||||
//TODO handle error bad chain
|
//TODO handle error bad chain
|
||||||
|
@ -50,15 +43,8 @@ public class BitsharesCryptoNetVerifier extends CryptoNetVerifier {
|
||||||
public void onError(BaseResponse.Error error) {
|
public void onError(BaseResponse.Error error) {
|
||||||
//TODO handle error
|
//TODO handle error
|
||||||
}
|
}
|
||||||
}),null);
|
}),url);
|
||||||
|
thread.start();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void checkURL(final String url) {
|
|
||||||
thread.setmUrl(url); //Set the url
|
|
||||||
thread.start(); //Run the thread connection
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package cy.agorise.crystalwallet.network;
|
package cy.agorise.crystalwallet.network;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
|
||||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,14 +12,6 @@ import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||||
|
|
||||||
public abstract class CryptoNetVerifier {
|
public abstract class CryptoNetVerifier {
|
||||||
|
|
||||||
/*
|
|
||||||
* Contains the worker connection thread
|
|
||||||
*/
|
|
||||||
protected WebSocketThread thread;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static CryptoNetVerifier getNetworkVerify(CryptoNet cryptoNet){
|
static CryptoNetVerifier getNetworkVerify(CryptoNet cryptoNet){
|
||||||
if(cryptoNet.getLabel().equals(CryptoNet.BITSHARES.getLabel())){
|
if(cryptoNet.getLabel().equals(CryptoNet.BITSHARES.getLabel())){
|
||||||
return new BitsharesCryptoNetVerifier();
|
return new BitsharesCryptoNetVerifier();
|
||||||
|
@ -33,9 +22,4 @@ public abstract class CryptoNetVerifier {
|
||||||
public abstract void checkURL(final String url);
|
public abstract void checkURL(final String url);
|
||||||
|
|
||||||
public abstract String getChainId();
|
public abstract String getChainId();
|
||||||
|
|
||||||
|
|
||||||
public WebSocketThread getThread() {
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.network;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.neovisionaries.ws.client.WebSocket;
|
import com.neovisionaries.ws.client.WebSocket;
|
||||||
|
import com.neovisionaries.ws.client.WebSocketException;
|
||||||
import com.neovisionaries.ws.client.WebSocketFactory;
|
import com.neovisionaries.ws.client.WebSocketFactory;
|
||||||
import com.neovisionaries.ws.client.WebSocketListener;
|
import com.neovisionaries.ws.client.WebSocketListener;
|
||||||
|
|
||||||
|
@ -33,11 +34,6 @@ public class WebSocketThread extends Thread {
|
||||||
private boolean canChange = true;
|
private boolean canChange = true;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Object needed for socket connection
|
|
||||||
* */
|
|
||||||
private WebSocketFactory factory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic constructor,
|
* Basic constructor,
|
||||||
*
|
*
|
||||||
|
@ -47,20 +43,10 @@ public class WebSocketThread extends Thread {
|
||||||
* @param url The url to connect
|
* @param url The url to connect
|
||||||
*/
|
*/
|
||||||
public WebSocketThread(WebSocketListener webSocketListener, String url) {
|
public WebSocketThread(WebSocketListener webSocketListener, String url) {
|
||||||
|
|
||||||
/*
|
|
||||||
* The listener always can be setted
|
|
||||||
* */
|
|
||||||
this.mWebSocketListener = webSocketListener;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* If at this point the url is not defined, this will be set after
|
|
||||||
* */
|
|
||||||
if(url!=null){
|
|
||||||
try {
|
try {
|
||||||
factory = new WebSocketFactory().setConnectionTimeout(5000);
|
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000);
|
||||||
this.mUrl = url;
|
this.mUrl = url;
|
||||||
|
this.mWebSocketListener = webSocketListener;
|
||||||
this.mWebSocket = factory.createSocket(this.mUrl);
|
this.mWebSocket = factory.createSocket(this.mUrl);
|
||||||
this.mWebSocket.addListener(this.mWebSocketListener);
|
this.mWebSocket.addListener(this.mWebSocketListener);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -69,7 +55,6 @@ public class WebSocketThread extends Thread {
|
||||||
Log.e(TAG, "NullPointerException at WebsocketWorkerThreas. Msg: "+e.getMessage());
|
Log.e(TAG, "NullPointerException at WebsocketWorkerThreas. Msg: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current url where the websocket will connect
|
* Gets the current url where the websocket will connect
|
||||||
|
@ -125,28 +110,16 @@ public class WebSocketThread extends Thread {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
canChange = false;
|
canChange = false;
|
||||||
|
|
||||||
// Moves the current Thread into the background
|
// Moves the current Thread into the background
|
||||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
|
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
/*
|
|
||||||
* If the initialization of the socket comes after
|
|
||||||
* */
|
|
||||||
if(factory==null){
|
|
||||||
factory = new WebSocketFactory().setConnectionTimeout(5000);
|
|
||||||
this.mWebSocket = factory.createSocket(this.mUrl);
|
|
||||||
this.mWebSocket.addListener(this.mWebSocketListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
WebSocketThread.currentThreads.put(this.getId(),this);
|
WebSocketThread.currentThreads.put(this.getId(),this);
|
||||||
mWebSocket.connect();
|
mWebSocket.connect();
|
||||||
|
} catch (WebSocketException e) {
|
||||||
} catch (final Exception e) {
|
|
||||||
Log.e(TAG, "WebSocketException. Msg: "+e.getMessage());
|
Log.e(TAG, "WebSocketException. Msg: "+e.getMessage());
|
||||||
|
} catch(NullPointerException e){
|
||||||
|
Log.e(TAG, "NullPointerException. Msg: "+e.getMessage());
|
||||||
}
|
}
|
||||||
WebSocketThread.currentThreads.remove(this.getId());
|
WebSocketThread.currentThreads.remove(this.getId());
|
||||||
}
|
}
|
||||||
|
@ -154,9 +127,4 @@ public class WebSocketThread extends Thread {
|
||||||
public boolean isConnected(){
|
public boolean isConnected(){
|
||||||
return mWebSocket.isOpen();
|
return mWebSocket.isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setmUrl(String mUrl) {
|
|
||||||
this.mUrl = mUrl;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue