diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java index 3dcef07a..fe49f5f4 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java @@ -1,6 +1,5 @@ package com.github.ontio.controller; -import com.alibaba.fastjson.JSONObject; import com.github.ontio.aop.RequestLimit; import com.github.ontio.model.dto.Anniversary6thDataDto; import com.github.ontio.service.IActivityDataService; @@ -41,24 +40,24 @@ public String queryAddressCertainTimeBalance(@RequestParam @Length(min = 34, max return activityDataService.queryAddressCertainTimeBalance(address, timestamp); } - @RequestLimit(count = 120) - @ApiOperation(value = "Get ont id or address active time") - @GetMapping(value = "/active_time") - public JSONObject queryAddressActiveTime(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { - return activityDataService.queryAddressActiveTime(address); - } - - @RequestLimit(count = 120) - @ApiOperation(value = "Get address send tx count and first tx time") - @GetMapping(value = "/send_tx_info") - public JSONObject queryAddressSendTxInfo(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { - return activityDataService.queryAddressSendTxInfo(address); - } - - @RequestLimit(count = 120) - @ApiOperation(value = "Get running node info") - @GetMapping(value = "/running_node_info") - public JSONObject queryRunningNodeInfo(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { - return activityDataService.queryRunningNodeInfo(address); - } +// @RequestLimit(count = 120) +// @ApiOperation(value = "Get ont id or address active time") +// @GetMapping(value = "/active_time") +// public JSONObject queryAddressActiveTime(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { +// return activityDataService.queryAddressActiveTime(address); +// } +// +// @RequestLimit(count = 120) +// @ApiOperation(value = "Get address send tx count and first tx time") +// @GetMapping(value = "/send_tx_info") +// public JSONObject queryAddressSendTxInfo(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { +// return activityDataService.queryAddressSendTxInfo(address); +// } +// +// @RequestLimit(count = 120) +// @ApiOperation(value = "Get running node info") +// @GetMapping(value = "/running_node_info") +// public JSONObject queryRunningNodeInfo(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { +// return activityDataService.queryRunningNodeInfo(address); +// } } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/TransactionServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/TransactionServiceImpl.java index 20e0acf6..e5b23866 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/TransactionServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/TransactionServiceImpl.java @@ -717,18 +717,31 @@ private Map determineTxType(TxEventLog eventLog) { calledContractHash = ""; } else { if (NATIVE_CALLED_CONTRACT_HASH.equals(calledContractHash)) { - if (eventLog.getOntidTxFlag()) { - txType = TxTypeEnum.ONT_ID; - calledContractHash = ConstantParam.CONTRACTHASH_ONTID; - } else if (eventLog.getEventLog().contains(ConstantParam.CONTRACTHASH_ONT)) { - txType = TxTypeEnum.ONT_TRANSFER; - calledContractHash = ConstantParam.CONTRACTHASH_ONT; - } else if (eventLog.getEventLog().contains(ConstantParam.CONTRACTHASH_ONG)) { - txType = TxTypeEnum.ONG_TRANSFER; - calledContractHash = ConstantParam.CONTRACTHASH_ONG; + calledContractHash = decodeNativeContractHash(eventLog.getTxHash()); + if (calledContractHash == null) { + if (eventLog.getOntidTxFlag()) { + txType = TxTypeEnum.ONT_ID; + calledContractHash = ConstantParam.CONTRACTHASH_ONTID; + } else if (eventLog.getEventLog().contains(ConstantParam.CONTRACTHASH_ONT)) { + txType = TxTypeEnum.ONT_TRANSFER; + calledContractHash = ConstantParam.CONTRACTHASH_ONT; + } else if (eventLog.getEventLog().contains(ConstantParam.CONTRACTHASH_ONG)) { + txType = TxTypeEnum.ONG_TRANSFER; + calledContractHash = ConstantParam.CONTRACTHASH_ONG; + } else { + calledContractHash = ConstantParam.CONTRACTHASH_ONG; + txType = TxTypeEnum.CONTRACT_CALL; + } } else { - calledContractHash = ConstantParam.CONTRACTHASH_ONG; - txType = TxTypeEnum.CONTRACT_CALL; + if (ConstantParam.CONTRACTHASH_ONTID.equalsIgnoreCase(calledContractHash)) { + txType = TxTypeEnum.ONT_ID; + } else if (ConstantParam.CONTRACTHASH_ONT.equalsIgnoreCase(calledContractHash)) { + txType = TxTypeEnum.ONT_TRANSFER; + } else if (ConstantParam.CONTRACTHASH_ONG.equalsIgnoreCase(calledContractHash)) { + txType = TxTypeEnum.ONG_TRANSFER; + } else { + txType = TxTypeEnum.CONTRACT_CALL; + } } } else { ContractType contractType = contractTypes.get(calledContractHash); @@ -760,6 +773,44 @@ private Map determineTxType(TxEventLog eventLog) { return map; } + private String decodeNativeContractHash(String txHash) { + String contractHash = null; + try { + String inputData = ""; + int txType = 0; + String resp = HttpClientUtil.getRequest(String.format(ConstantParam.GET_TRANSACTION_URL, paramsConfig.MASTERNODE_RESTFUL_URL, txHash), Collections.emptyMap(), Collections.emptyMap()); + JSONObject jsonObject = JSONObject.parseObject(resp); + Integer error = jsonObject.getInteger("Error"); + if (error == 0) { + JSONObject result = jsonObject.getJSONObject("Result"); + JSONObject payload = result.getJSONObject("Payload"); + txType = result.getInteger("TxType"); + inputData = payload.getString("Code"); + } + if (txType == 209) { + int nativeInvokeIndex = inputData.lastIndexOf(ConstantParam.NATIVE_INPUT_DATA_END); + if (nativeInvokeIndex != -1) { + if (inputData.startsWith(ConstantParam.NATIVE_STRUCT_START)) { + // 有参数 + String argsMethodContract = inputData.substring(6, nativeInvokeIndex); + int length = argsMethodContract.length(); + String contract = argsMethodContract.substring(length - 40); + contractHash = com.github.ontio.common.Helper.reverse(contract); + } else { + // native方法无参数 + String methodContract = inputData.substring(0, nativeInvokeIndex); + int length = methodContract.length(); + String contract = methodContract.substring(length - 40); + contractHash = com.github.ontio.common.Helper.reverse(contract); + } + } + } + } catch (Exception e) { + log.error("decodeNativeContractHash error", e); + } + return contractHash; + } + @Autowired public void setContractMapper(ContractMapper contractMapper) { this.contractTypes = Caffeine.newBuilder() diff --git a/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml index be146046..b26e681d 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml @@ -146,6 +146,7 @@ d.from_address as fromAddress, d.tx_index as txIndex, d.contract_hash as contractHash, + d.called_contract_hash as calledContractHash, c.type AS assetType FROM tbl_tx_detail d INNER JOIN