diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java index cdb6c2d..690bbde 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java @@ -14,8 +14,11 @@ import cy.agorise.graphenej.Authority; import cy.agorise.graphenej.Transaction; import cy.agorise.graphenej.api.calls.GetAccounts; 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.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.LimitOrderCreateOperation; import cy.agorise.graphenej.operations.TransferOperation; @@ -60,6 +63,17 @@ public class DeserializationMap { .registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()) .create(); 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){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index d7b8cd9..3cac3f9 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -24,11 +24,13 @@ import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.bitshares.Nodes; import cy.agorise.graphenej.api.calls.ApiCallable; 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.models.AccountProperties; import cy.agorise.graphenej.models.ApiCall; import cy.agorise.graphenej.models.Block; import cy.agorise.graphenej.models.JsonRpcResponse; +import cy.agorise.graphenej.models.OperationHistory; import io.reactivex.annotations.Nullable; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -274,8 +276,7 @@ public class NetworkService extends Service { if(responsePayloadClass == Block.class){ // If the response payload is a simple Block instance, we proceed to de-serialize it Type GetBlockResponse = new TypeToken>() {}.getType(); - JsonRpcResponse blockResponse = (JsonRpcResponse) gson.fromJson(text, GetBlockResponse); - parsedResponse = blockResponse; + parsedResponse = gson.fromJson(text, GetBlockResponse); }else if(responsePayloadClass == List.class){ // If the response payload is a List, further inquiry is required in order to // 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> // so we proceed with that Type GetAccountsResponse = new TypeToken>>(){}.getType(); - JsonRpcResponse> accountResponse = (JsonRpcResponse) gson.fromJson(text, GetAccountsResponse); - parsedResponse = accountResponse; + parsedResponse = gson.fromJson(text, GetAccountsResponse); }else if(requestClass == GetRequiredFees.class){ Type GetRequiredFeesResponse = new TypeToken>>(){}.getType(); - JsonRpcResponse> assetAmountResponse = (JsonRpcResponse) gson.fromJson(text, GetRequiredFeesResponse); - parsedResponse = assetAmountResponse; + parsedResponse = gson.fromJson(text, GetRequiredFeesResponse); + }else if(requestClass == GetRelativeAccountHistory.class){ + Type RelativeAccountHistoryResponse = new TypeToken>>(){}.getType(); + parsedResponse = gson.fromJson(text, RelativeAccountHistoryResponse); }else{ Log.w(TAG,"Unknown request class"); } diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetRelativeAccountHistory.java b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetRelativeAccountHistory.java new file mode 100644 index 0000000..362d9c1 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetRelativeAccountHistory.java @@ -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 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); + } +}