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 049926f..574ab20 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 @@ -15,9 +15,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.GetBlockHeader; 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.BlockHeader; import cy.agorise.graphenej.models.OperationHistory; import cy.agorise.graphenej.objects.Memo; import cy.agorise.graphenej.operations.CustomOperation; @@ -38,6 +40,8 @@ public class DeserializationMap { private HashMap mGsonMap = new HashMap<>(); public DeserializationMap(){ + Gson genericGson = new Gson(); + // GetBlock mClassMap.put(GetBlock.class, Block.class); Gson getBlockGson = new GsonBuilder() @@ -76,6 +80,10 @@ public class DeserializationMap { .create(); mGsonMap.put(GetRelativeAccountHistory.class, getRelativeAcountHistoryGson); + // GetBlockHeader + mClassMap.put(GetBlockHeader.class, BlockHeader.class); + mGsonMap.put(GetBlockHeader.class, genericGson); + } 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 3cac3f9..4e704e4 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 @@ -29,6 +29,7 @@ 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.BlockHeader; import cy.agorise.graphenej.models.JsonRpcResponse; import cy.agorise.graphenej.models.OperationHistory; import io.reactivex.annotations.Nullable; @@ -274,10 +275,14 @@ public class NetworkService extends Service { Class responsePayloadClass = mDeserializationMap.getReceivedClass(requestClass); Gson gson = mDeserializationMap.getGson(requestClass); 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 Block instance, we proceed to de-serialize it Type GetBlockResponse = new TypeToken>() {}.getType(); parsedResponse = gson.fromJson(text, GetBlockResponse); - }else if(responsePayloadClass == List.class){ + }else if(responsePayloadClass == BlockHeader.class){ + // If the response payload is a BlockHeader instance, we proceed to de-serialize it + Type GetBlockHeaderResponse = new TypeToken>(){}.getType(); + parsedResponse = gson.fromJson(text, GetBlockHeaderResponse); + } 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 if(requestClass == GetAccounts.class){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetBlockHeader.java b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetBlockHeader.java new file mode 100644 index 0000000..5c8045a --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/calls/GetBlockHeader.java @@ -0,0 +1,30 @@ +package cy.agorise.graphenej.api.calls; + +import java.io.Serializable; +import java.util.ArrayList; + +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.api.ApiAccess; +import cy.agorise.graphenej.models.ApiCall; + +/** + * Wrapper around the "get_block_header" API call. To be used in the single-connection mode. + */ +public class GetBlockHeader implements ApiCallable { + public static final int REQUIRED_API = ApiAccess.API_DATABASE; + + private long blockNumber; + + public GetBlockHeader(long number){ + this.blockNumber = number; + } + + @Override + public ApiCall toApiCall(int apiId, long sequenceId) { + ArrayList params = new ArrayList<>(); + String blockNum = String.format("%d", this.blockNumber); + params.add(blockNum); + + return new ApiCall(apiId, RPC.CALL_GET_BLOCK_HEADER, params, RPC.VERSION, sequenceId); + } +} diff --git a/graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java b/graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java index 9ebdef7..503f074 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java @@ -1,12 +1,11 @@ package cy.agorise.graphenej.models; /** - * Created by nelson on 12/13/16. + * Class used to represent the response to the 'get_block_header' API call. */ public class BlockHeader { public String previous; public String timestamp; public String witness; public String transaction_merkle_root; - public Object[] extension; }