Introducing support for the GetRelativeAccountHistory api call in the single-connection mode

This commit is contained in:
Nelson R. Perez 2018-06-11 15:40:01 -05:00
parent 8c5d48f71d
commit 7582fefd0e
3 changed files with 69 additions and 6 deletions

View file

@ -14,8 +14,11 @@ import cy.agorise.graphenej.Authority;
import cy.agorise.graphenej.Transaction; import cy.agorise.graphenej.Transaction;
import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetBlock; import cy.agorise.graphenej.api.calls.GetBlock;
import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory;
import cy.agorise.graphenej.api.calls.GetRequiredFees; import cy.agorise.graphenej.api.calls.GetRequiredFees;
import cy.agorise.graphenej.models.Block; import cy.agorise.graphenej.models.Block;
import cy.agorise.graphenej.models.OperationHistory;
import cy.agorise.graphenej.objects.Memo;
import cy.agorise.graphenej.operations.CustomOperation; import cy.agorise.graphenej.operations.CustomOperation;
import cy.agorise.graphenej.operations.LimitOrderCreateOperation; import cy.agorise.graphenej.operations.LimitOrderCreateOperation;
import cy.agorise.graphenej.operations.TransferOperation; import cy.agorise.graphenej.operations.TransferOperation;
@ -60,6 +63,17 @@ public class DeserializationMap {
.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()) .registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer())
.create(); .create();
mGsonMap.put(GetRequiredFees.class, getRequiredFeesGson); mGsonMap.put(GetRequiredFees.class, getRequiredFeesGson);
// GetRelativeAccounthistory
mClassMap.put(GetRelativeAccountHistory.class, List.class);
Gson getRelativeAcountHistoryGson = new GsonBuilder()
.registerTypeAdapter(OperationHistory.class, new OperationHistory.OperationHistoryDeserializer())
.registerTypeAdapter(TransferOperation.class, new TransferOperation.TransferDeserializer())
.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer())
.registerTypeAdapter(Memo.class, new Memo.MemoDeserializer())
.create();
mGsonMap.put(GetRelativeAccountHistory.class, getRelativeAcountHistoryGson);
} }
public Class getReceivedClass(Class _class){ public Class getReceivedClass(Class _class){

View file

@ -24,11 +24,13 @@ import cy.agorise.graphenej.api.ConnectionStatusUpdate;
import cy.agorise.graphenej.api.bitshares.Nodes; import cy.agorise.graphenej.api.bitshares.Nodes;
import cy.agorise.graphenej.api.calls.ApiCallable; import cy.agorise.graphenej.api.calls.ApiCallable;
import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory;
import cy.agorise.graphenej.api.calls.GetRequiredFees; import cy.agorise.graphenej.api.calls.GetRequiredFees;
import cy.agorise.graphenej.models.AccountProperties; import cy.agorise.graphenej.models.AccountProperties;
import cy.agorise.graphenej.models.ApiCall; import cy.agorise.graphenej.models.ApiCall;
import cy.agorise.graphenej.models.Block; import cy.agorise.graphenej.models.Block;
import cy.agorise.graphenej.models.JsonRpcResponse; import cy.agorise.graphenej.models.JsonRpcResponse;
import cy.agorise.graphenej.models.OperationHistory;
import io.reactivex.annotations.Nullable; import io.reactivex.annotations.Nullable;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@ -274,8 +276,7 @@ public class NetworkService extends Service {
if(responsePayloadClass == Block.class){ if(responsePayloadClass == Block.class){
// If the response payload is a simple Block instance, we proceed to de-serialize it // If the response payload is a simple Block instance, we proceed to de-serialize it
Type GetBlockResponse = new TypeToken<JsonRpcResponse<Block>>() {}.getType(); Type GetBlockResponse = new TypeToken<JsonRpcResponse<Block>>() {}.getType();
JsonRpcResponse<Block> blockResponse = (JsonRpcResponse) gson.fromJson(text, GetBlockResponse); parsedResponse = gson.fromJson(text, GetBlockResponse);
parsedResponse = blockResponse;
}else if(responsePayloadClass == List.class){ }else if(responsePayloadClass == List.class){
// If the response payload is a List, further inquiry is required in order to // If the response payload is a List, further inquiry is required in order to
// determine a list of what is expected here // determine a list of what is expected here
@ -284,12 +285,13 @@ public class NetworkService extends Service {
// the response should be in the form of a JsonRpcResponse<List<AccountProperties>> // the response should be in the form of a JsonRpcResponse<List<AccountProperties>>
// so we proceed with that // so we proceed with that
Type GetAccountsResponse = new TypeToken<JsonRpcResponse<List<AccountProperties>>>(){}.getType(); Type GetAccountsResponse = new TypeToken<JsonRpcResponse<List<AccountProperties>>>(){}.getType();
JsonRpcResponse<List<AccountProperties>> accountResponse = (JsonRpcResponse) gson.fromJson(text, GetAccountsResponse); parsedResponse = gson.fromJson(text, GetAccountsResponse);
parsedResponse = accountResponse;
}else if(requestClass == GetRequiredFees.class){ }else if(requestClass == GetRequiredFees.class){
Type GetRequiredFeesResponse = new TypeToken<JsonRpcResponse<List<AssetAmount>>>(){}.getType(); Type GetRequiredFeesResponse = new TypeToken<JsonRpcResponse<List<AssetAmount>>>(){}.getType();
JsonRpcResponse<List<AssetAmount>> assetAmountResponse = (JsonRpcResponse) gson.fromJson(text, GetRequiredFeesResponse); parsedResponse = gson.fromJson(text, GetRequiredFeesResponse);
parsedResponse = assetAmountResponse; }else if(requestClass == GetRelativeAccountHistory.class){
Type RelativeAccountHistoryResponse = new TypeToken<JsonRpcResponse<List<OperationHistory>>>(){}.getType();
parsedResponse = gson.fromJson(text, RelativeAccountHistoryResponse);
}else{ }else{
Log.w(TAG,"Unknown request class"); Log.w(TAG,"Unknown request class");
} }

View file

@ -0,0 +1,47 @@
package cy.agorise.graphenej.api.calls;
import java.io.Serializable;
import java.util.ArrayList;
import cy.agorise.graphenej.RPC;
import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.models.ApiCall;
/**
* Wrapper around the "get_relative_account_history" API call
*/
public class GetRelativeAccountHistory implements ApiCallable {
public static final int REQUIRED_API = ApiAccess.API_HISTORY;
// API call parameters
private UserAccount mUserAccount;
private int stop;
private int limit;
private int start;
/**
* Constructor
* @param userAccount
* @param stop
* @param limit
* @param start
*/
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start){
this.mUserAccount = userAccount;
this.stop = stop;
this.limit = limit;
this.start = start;
}
@Override
public ApiCall toApiCall(int apiId, long sequenceId) {
ArrayList<Serializable> params = new ArrayList<>();
params.add(mUserAccount.getObjectId());
params.add(this.stop);
params.add(this.limit);
params.add(this.start);
return new ApiCall(apiId, RPC.CALL_GET_RELATIVE_ACCOUNT_HISTORY, params, RPC.VERSION, sequenceId);
}
}