diff --git a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java index 50f528ba..2b480825 100644 --- a/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java +++ b/source/gateway/src/main/java/com/jd/blockchain/gateway/web/BlockBrowserController.java @@ -597,7 +597,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { public AccountHeader[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) { - return peerService.getQueryService().getUsers(ledgerHash, fromIndex, count); + return revertAccountHeader(peerService.getQueryService().getUsers(ledgerHash, fromIndex, count)); } @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts") @@ -605,7 +605,7 @@ public class BlockBrowserController implements BlockchainExtendQueryService { public AccountHeader[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) { - return peerService.getQueryService().getDataAccounts(ledgerHash, fromIndex, count); + return revertAccountHeader(peerService.getQueryService().getDataAccounts(ledgerHash, fromIndex, count)); } @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts") @@ -613,6 +613,20 @@ public class BlockBrowserController implements BlockchainExtendQueryService { public AccountHeader[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) { - return peerService.getQueryService().getContractAccounts(ledgerHash, fromIndex, count); + return revertAccountHeader(peerService.getQueryService().getContractAccounts(ledgerHash, fromIndex, count)); + } + + /** + * reverse the AccountHeader[] content; the latest record show first; + * @return + */ + private AccountHeader[] revertAccountHeader(AccountHeader[] accountHeaders){ + AccountHeader[] accounts = new AccountHeader[accountHeaders.length]; + if(accountHeaders!=null && accountHeaders.length>0){ + for (int i = 0; i < accountHeaders.length; i++) { + accounts[accountHeaders.length-1-i] = accountHeaders[i]; + } + } + return accounts; } } diff --git a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java index ea858ff2..6af57e64 100644 --- a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java +++ b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/QueryUtil.java @@ -45,6 +45,10 @@ public class QueryUtil { } rtn[0] = fromIndex; rtn[1] = count; + + //now use descend; first show the latest record; + rtn[0] = maxNum - fromIndex - count; + rtn[1] = count; return rtn; } }