Merge branch 'feat_central_broker' of github.com:Agorise/graphenej into feat_central_broker
This commit is contained in:
commit
52e0196744
1 changed files with 55 additions and 51 deletions
|
@ -256,21 +256,29 @@ public class NetworkService extends Service {
|
|||
public void onMessage(WebSocket webSocket, String text) {
|
||||
super.onMessage(webSocket, text);
|
||||
Log.v(TAG,"<- "+text);
|
||||
JsonRpcResponse<?> response = gson.fromJson(text, JsonRpcResponse.class);
|
||||
JsonRpcNotification notification = gson.fromJson(text, JsonRpcNotification.class);
|
||||
|
||||
// We will only handle messages that relate to the login and API accesses here.
|
||||
if(notification.method != null){
|
||||
// If we are dealing with a notification
|
||||
handleJsonRpcNotification(notification);
|
||||
}else{
|
||||
// If we are dealing with a response
|
||||
JsonRpcResponse<?> response = gson.fromJson(text, JsonRpcResponse.class);
|
||||
if(response.result != null){
|
||||
// Handling initial handshake with the full node (authentication and API access checks)
|
||||
if(response.result instanceof Double || response.result instanceof Boolean){
|
||||
if(mLastCall.equals(RPC.CALL_LOGIN)){
|
||||
switch (mLastCall) {
|
||||
case RPC.CALL_LOGIN:
|
||||
isLoggedIn = true;
|
||||
|
||||
// Broadcasting result
|
||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.AUTHENTICATED, ApiAccess.API_NONE));
|
||||
|
||||
checkNextRequestedApiAccess();
|
||||
}else if(mLastCall.equals(RPC.CALL_DATABASE)){
|
||||
break;
|
||||
case RPC.CALL_DATABASE: {
|
||||
// Deserializing integer response
|
||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>() {}.getType();
|
||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||
|
||||
// Storing the "database" api id
|
||||
|
@ -280,9 +288,11 @@ public class NetworkService extends Service {
|
|||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_DATABASE));
|
||||
|
||||
checkNextRequestedApiAccess();
|
||||
}else if(mLastCall.equals(RPC.CALL_HISTORY)){
|
||||
break;
|
||||
}
|
||||
case RPC.CALL_HISTORY: {
|
||||
// Deserializing integer response
|
||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>() {}.getType();
|
||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||
|
||||
// Broadcasting result
|
||||
|
@ -292,9 +302,11 @@ public class NetworkService extends Service {
|
|||
mApiIds.put(ApiAccess.API_HISTORY, apiIdResponse.result);
|
||||
|
||||
checkNextRequestedApiAccess();
|
||||
}else if(mLastCall.equals(RPC.CALL_NETWORK_BROADCAST)){
|
||||
break;
|
||||
}
|
||||
case RPC.CALL_NETWORK_BROADCAST:
|
||||
// Deserializing integer response
|
||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>() {}.getType();
|
||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||
|
||||
// Broadcasting result
|
||||
|
@ -305,23 +317,16 @@ public class NetworkService extends Service {
|
|||
|
||||
// All calls have been handled at this point
|
||||
mLastCall = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Properly de-serialize all other fields and broadcasts to the event bus
|
||||
handleJsonRpcResponse(response, text);
|
||||
}else{
|
||||
// If no 'result' field was found, this incoming message probably corresponds to a
|
||||
// JSON-RPC notification message, which should have a 'method' field with the string
|
||||
// 'notice' as its value
|
||||
JsonRpcNotification notification = gson.fromJson(text, JsonRpcNotification.class);
|
||||
if(notification.method != null && notification.method.equals("notice")){
|
||||
handleJsonRpcNotification(notification);
|
||||
}else{
|
||||
if(response.error != null && response.error.message != null){
|
||||
// We could not make sense of this incoming message, just log a warning
|
||||
Log.w(TAG,"Error.Msg: "+response.error.message);
|
||||
}
|
||||
}
|
||||
// Properly de-serialize all other fields and broadcasts to the event bus
|
||||
handleJsonRpcResponse(response, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,7 +397,6 @@ public class NetworkService extends Service {
|
|||
if(parsedResponse == null){
|
||||
parsedResponse = response;
|
||||
}
|
||||
|
||||
// Broadcasting the parsed response to all interested listeners
|
||||
RxBus.getBusInstance().send(parsedResponse);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue