Skip to content

Commit

Permalink
Update determineTxType
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Jan 14, 2025
1 parent b0a936e commit f84dc26
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,31 @@ private Map<String, Object> 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);
Expand Down Expand Up @@ -760,6 +773,44 @@ private Map<String, Object> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f84dc26

Please sign in to comment.