Introducing support for the GetBlockHeader api call in the single-connection mode
This commit is contained in:
parent
4f6b628891
commit
85bf1d1ba1
4 changed files with 46 additions and 4 deletions
|
@ -15,9 +15,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.GetBlockHeader;
|
||||||
import cy.agorise.graphenej.api.calls.GetRelativeAccountHistory;
|
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.BlockHeader;
|
||||||
import cy.agorise.graphenej.models.OperationHistory;
|
import cy.agorise.graphenej.models.OperationHistory;
|
||||||
import cy.agorise.graphenej.objects.Memo;
|
import cy.agorise.graphenej.objects.Memo;
|
||||||
import cy.agorise.graphenej.operations.CustomOperation;
|
import cy.agorise.graphenej.operations.CustomOperation;
|
||||||
|
@ -38,6 +40,8 @@ public class DeserializationMap {
|
||||||
private HashMap<Class, Gson> mGsonMap = new HashMap<>();
|
private HashMap<Class, Gson> mGsonMap = new HashMap<>();
|
||||||
|
|
||||||
public DeserializationMap(){
|
public DeserializationMap(){
|
||||||
|
Gson genericGson = new Gson();
|
||||||
|
|
||||||
// GetBlock
|
// GetBlock
|
||||||
mClassMap.put(GetBlock.class, Block.class);
|
mClassMap.put(GetBlock.class, Block.class);
|
||||||
Gson getBlockGson = new GsonBuilder()
|
Gson getBlockGson = new GsonBuilder()
|
||||||
|
@ -76,6 +80,10 @@ public class DeserializationMap {
|
||||||
.create();
|
.create();
|
||||||
mGsonMap.put(GetRelativeAccountHistory.class, getRelativeAcountHistoryGson);
|
mGsonMap.put(GetRelativeAccountHistory.class, getRelativeAcountHistoryGson);
|
||||||
|
|
||||||
|
// GetBlockHeader
|
||||||
|
mClassMap.put(GetBlockHeader.class, BlockHeader.class);
|
||||||
|
mGsonMap.put(GetBlockHeader.class, genericGson);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getReceivedClass(Class _class){
|
public Class getReceivedClass(Class _class){
|
||||||
|
|
|
@ -29,6 +29,7 @@ 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.BlockHeader;
|
||||||
import cy.agorise.graphenej.models.JsonRpcResponse;
|
import cy.agorise.graphenej.models.JsonRpcResponse;
|
||||||
import cy.agorise.graphenej.models.OperationHistory;
|
import cy.agorise.graphenej.models.OperationHistory;
|
||||||
import io.reactivex.annotations.Nullable;
|
import io.reactivex.annotations.Nullable;
|
||||||
|
@ -274,9 +275,13 @@ public class NetworkService extends Service {
|
||||||
Class responsePayloadClass = mDeserializationMap.getReceivedClass(requestClass);
|
Class responsePayloadClass = mDeserializationMap.getReceivedClass(requestClass);
|
||||||
Gson gson = mDeserializationMap.getGson(requestClass);
|
Gson gson = mDeserializationMap.getGson(requestClass);
|
||||||
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 Block instance, we proceed to de-serialize it
|
||||||
Type GetBlockResponse = new TypeToken<JsonRpcResponse<Block>>() {}.getType();
|
Type GetBlockResponse = new TypeToken<JsonRpcResponse<Block>>() {}.getType();
|
||||||
parsedResponse = gson.fromJson(text, GetBlockResponse);
|
parsedResponse = gson.fromJson(text, GetBlockResponse);
|
||||||
|
}else if(responsePayloadClass == BlockHeader.class){
|
||||||
|
// If the response payload is a BlockHeader instance, we proceed to de-serialize it
|
||||||
|
Type GetBlockHeaderResponse = new TypeToken<JsonRpcResponse<BlockHeader>>(){}.getType();
|
||||||
|
parsedResponse = gson.fromJson(text, GetBlockHeaderResponse);
|
||||||
} 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
|
||||||
|
|
|
@ -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<Serializable> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,11 @@
|
||||||
package cy.agorise.graphenej.models;
|
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 class BlockHeader {
|
||||||
public String previous;
|
public String previous;
|
||||||
public String timestamp;
|
public String timestamp;
|
||||||
public String witness;
|
public String witness;
|
||||||
public String transaction_merkle_root;
|
public String transaction_merkle_root;
|
||||||
public Object[] extension;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue