第四章. BlockService相关接口

BlockService接口与TxService相似,只是获取的对象是区块信息。同样地,BlockService对象也有很多对应的响应类型:

  • BlockResponse
  • BlockNumberResponse
  • BlockAvgTimeResponse
  • BlockCountResponse

分别对应的结构如下。

BlockResponse

通过result接收返回结果,result实际类型是内部类Block,可通过getResult()方法得到。

  1. public class BlockResponse extends Response {
  2. public class Block {
  3. private String version;
  4. private String number;
  5. private String hash;
  6. private String parentHash;
  7. private String writeTime;
  8. private String avgTime;
  9. private String txcounts;
  10. private String merkleRoot;
  11. }
  12. private JsonElement result;
  13. }

BlockNumberResponse

通过result接收返回结果,result实际类型是String,可通过getResult()方法得到。

  1. public class BlockNumberResponse extends Response {
  2. private String result;
  3. }

BlockAvgTimeResponse

通过result接收返回结果,result实际类型是String,可通过getResult()方法得到。

  1. public class BlockAvgTimeResponse extends Response {
  2. @Expose
  3. private String result;
  4. }

BlockCountResponse

通过result接收返回结果,result实际类型是内部类BlockCount,可通过getResult()方法得到。

  1. public class BlockCountResponse extends Response {
  2. public class BlockCount {
  3. private String sumOfBlocks;
  4. private String startBlock;
  5. private String endBlock;
  6. }
  7. private BlockCount result;
  8. }