From 415e41ae110c557103284a81ffe41f2dcc9dbfd6 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Wed, 20 Jun 2018 17:23:15 -0500 Subject: [PATCH] Added support for the get_account_history API call --- .../main/java/cy/agorise/graphenej/RPC.java | 1 + .../api/calls/GetAccountHistory.java | 43 +++++++++++++++++++ .../api/calls/GetAccountHistoryTest.java | 25 +++++++++++ 3 files changed, 69 insertions(+) create mode 100644 graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountHistory.java create mode 100644 graphenej/src/test/java/cy/agorise/graphenej/api/calls/GetAccountHistoryTest.java diff --git a/graphenej/src/main/java/cy/agorise/graphenej/RPC.java b/graphenej/src/main/java/cy/agorise/graphenej/RPC.java index ea6c509..5a7fb21 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/RPC.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/RPC.java @@ -19,6 +19,7 @@ public class RPC { public static final String CALL_GET_REQUIRED_FEES = "get_required_fees"; public static final String CALL_GET_KEY_REFERENCES = "get_key_references"; public static final String CALL_GET_RELATIVE_ACCOUNT_HISTORY = "get_relative_account_history"; + public static final String CALL_GET_ACCOUNT_HISTORY = "get_account_history"; public static final String CALL_LOOKUP_ACCOUNTS = "lookup_accounts"; public static final String CALL_LIST_ASSETS = "list_assets"; public static final String GET_OBJECTS = "get_objects"; diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountHistory.java b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountHistory.java new file mode 100644 index 0000000..0a43ef4 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetAccountHistory.java @@ -0,0 +1,43 @@ +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; + +public class GetAccountHistory implements ApiCallable { + public static final int REQUIRED_API = ApiAccess.API_HISTORY; + + private UserAccount mUserAccount; + private String startOperation; + private String endOperation; + private int limit; + + public GetAccountHistory(UserAccount userAccount, String start, String end, int limit){ + this.mUserAccount = userAccount; + this.startOperation = start; + this.endOperation = end; + this.limit = limit; + } + + public GetAccountHistory(String userId, String start, String end, int limit){ + this.mUserAccount = new UserAccount(userId); + this.startOperation = start; + this.endOperation = end; + this.limit = limit; + } + + + @Override + public ApiCall toApiCall(int apiId, long sequenceId) { + ArrayList params = new ArrayList<>(); + params.add(mUserAccount.getObjectId()); + params.add(endOperation); + params.add(limit); + params.add(startOperation); + return new ApiCall(apiId, RPC.CALL_GET_ACCOUNT_HISTORY, params, RPC.VERSION, sequenceId); + } +} diff --git a/graphenej/src/test/java/cy/agorise/graphenej/api/calls/GetAccountHistoryTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/calls/GetAccountHistoryTest.java new file mode 100644 index 0000000..f14b7f6 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/calls/GetAccountHistoryTest.java @@ -0,0 +1,25 @@ +package cy.agorise.graphenej.api.calls; + +import junit.framework.Assert; + +import org.junit.Test; + +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.models.ApiCall; + +public class GetAccountHistoryTest { + + @Test + public void testSerialization(){ + UserAccount userAccount = new UserAccount("1.2.139293"); + String end = "1.11.225030218"; + String start = "1.11.225487973"; + int limit = 20; + GetAccountHistory getAccountHistory = new GetAccountHistory(userAccount, start, end, limit); + ApiCall apiCall = getAccountHistory.toApiCall(2, 3); + String serialized = apiCall.toJsonString(); + System.out.println("> "+serialized); + String expected = "{\"id\":3,\"method\":\"call\",\"params\":[2,\"get_account_history\",[\"1.2.139293\",\"1.11.225030218\",20,\"1.11.225487973\"]],\"jsonrpc\":\"2.0\"}"; + Assert.assertEquals("Serialized is as expected", expected, serialized); + } +}