From 677a4d231ae11a393dd172ecb303025e95133b12 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Fri, 26 Apr 2019 17:26:50 +0800 Subject: [PATCH 01/42] add empty json --- .../contractlogs/ContractWithAbiController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java b/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java index e759356..a573298 100644 --- a/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java +++ b/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java @@ -77,13 +77,14 @@ private JSONObject getContractTrigger(Map hmap, QueryFactory que ContractLogTriggerEntity.class); List contractEventTriggerList = mongoTemplate.find(query.getQuery(), ContractEventTriggerEntity.class); + Map map = new HashMap(); if (contractLogTriggerList.isEmpty() && contractEventTriggerList.isEmpty()) { - return null; + return new JSONObject(map); } if (!hmap.containsKey("abi") || hmap.get("abi").length() == 0) { - return null; + return new JSONObject(map); } String abi = hmap.get("abi"); @@ -96,7 +97,6 @@ private JSONObject getContractTrigger(Map hmap, QueryFactory que resLogList.addAll(QueryFactory.parseLogWithAbiByEvent(contractEventTriggerList, abi)); } - Map map = new HashMap(); if (resLogList != null && !resLogList.isEmpty()) { map.put("contractLogTriggers", resLogList); } From 83fed7c588400e61b9d41f74d7d205ac6083276e Mon Sep 17 00:00:00 2001 From: wubinTron <44354524+wubinTron@users.noreply.github.com> Date: Mon, 3 Jun 2019 14:56:12 +0800 Subject: [PATCH 02/42] Update README.md --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1667b16..4c26edc 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,6 @@ limit: each page size, default is 25 sort: sort Field, default is sort by timeStamp descending order start: start page, default is 1 -Note: if developers wants to check whether this event is confirmed or not, they could check the blocknumber is small than the solidified block number(get from url https://api.tronex.io/blocks/latestblockNum). If it is smaller than block number, it is conformed Example: https://api.tronex.io/events/confirmed?since=1544483426749&limit=1&start=1&sort=timeStamp ``` @@ -197,7 +196,7 @@ block: block number, block number >= block will be shown Example: https://api.tronex.io/blocks?limit=1&sort=timeStamp&start=0&block=0 ``` -Function: get latest solidified block number +Function: get latest block number ``` subpath: $baseUrl/blocks/latestSolidifiedBlockNumber @@ -206,3 +205,73 @@ none Example: https://api.tronex.io/blocks/latestSolidifiedBlockNumber ``` +Function: get contract log list +``` +subpath: $baseUrl/contractlogs + +parameters +limit: each page size, default is 25 +sort: sort Field, default is sort by timeStamp descending order +start: start page, default is 1 +block: block number, block number >= block will be shown + +Example: https://api.tronex.io/contractlogs +``` +Function: get contract log list based on transactionId +``` +subpath: $baseUrl/contractlogs/transaction/{transactionId} + +parameters +transactionId + +Example: https://api.tronex.io/contractlogs/transaction/{transactionId} +``` +Function: post abi string and get contract log list based on transactionId(release on 3.6) +``` +subpath: $baseUrl/contract/transaction/{transactionId} + +parameters +transactionId +body: +abi: user self upload abi + +Example: https://api.tronex.io/contract/transaction/{transactionId} +``` +Function: get contract log list based on contractAddress +``` +subpath: $baseUrl/contractlogs/contract/{contractAddress} + +parameters +contractAddress + +Example: https://api.tronex.io/contractlogs/contract/{contractAddress} +``` +Function: post abi string and get contract log list based on contractAddress(release on 3.6) +``` +subpath: $baseUrl/contract/contractAddress/{contractAddress} + +parameters +contractAddress +abi: user self upload abi + +Example: https://api.tronex.io/contract/contractAddress/{contractAddress} +``` +Function: get contract log list based on uniqueId +``` +subpath: $baseUrl/contractlogs/uniqueId/{uniqueId} + +parameters +uniqueId + +Example: https://api.tronex.io/contractlogs/uniqueId/{uniqueId} +``` +Function: post abi string and get contract log list based on uniqueId(release on 3.6) +``` +subpath: $baseUrl/contract/uniqueId/{uniqueId} + +parameters +uniqueId +abi: user self upload abi + +Example: https://api.tronex.io/contract/uniqueId/{uniqueId} +``` From a9b174f561c23cfedf0e0c8a5903223cf97663f4 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 3 Jun 2019 19:37:36 +0800 Subject: [PATCH 03/42] add input null check --- .../ContractWithAbiController.java | 2 +- .../query/ContractEventParserJson.java | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java b/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java index a573298..3c469b9 100644 --- a/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java +++ b/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java @@ -50,7 +50,7 @@ public JSONObject findByContractAddressAndEntryName( return getContractTrigger(hmap, query); } - @RequestMapping(method = RequestMethod.POST, value = "/contract/uniqueId/{uniqueId}") + @RequestMapping(method = RequestMethod.POST, value = "/contract/uniqueId/{uniqueId}") public JSONObject getEvent( @PathVariable(value = "uniqueId", required = false) String uniqueId, @RequestBody Map hmap diff --git a/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java b/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java index 7f026bd..c3c4838 100644 --- a/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java +++ b/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java @@ -30,20 +30,22 @@ public static Map parseTopics(List topicList, JSONObject // in case indexed topics doesn't match if (topicsMatched(topicList, entry)) { - for (int i = 0; i < inputs.size(); ++i) { - JSONObject param = inputs.getJSONObject(i); - Boolean indexed = param.getBoolean("indexed"); - if (indexed == null || !indexed) { - continue; - } - if (index >= topicList.size()) { - break; - } - String str = parseTopic(topicList.get(index++), param.getString("type")); - if (StringUtils.isNotNullOrEmpty(param.getString("name"))) { - map.put(param.getString("name"), str); + if (inputs != null) { + for (int i = 0; i < inputs.size(); ++i) { + JSONObject param = inputs.getJSONObject(i); + Boolean indexed = param.getBoolean("indexed"); + if (indexed == null || !indexed) { + continue; + } + if (index >= topicList.size()) { + break; + } + String str = parseTopic(topicList.get(index++), param.getString("type")); + if (StringUtils.isNotNullOrEmpty(param.getString("name"))) { + map.put(param.getString("name"), str); + } + map.put("" + i, str); } - map.put("" + i, str); } } else { for (int i = 1; i < topicList.size(); ++i) { @@ -113,11 +115,13 @@ private static boolean topicsMatched(List topicList, JSONObject entry) { } int inputSize = 1; JSONArray inputs = entry.getJSONArray("inputs"); - for (int i = 0; i < inputs.size(); i++) { - JSONObject param = inputs.getJSONObject(i); - Boolean indexed = param.getBoolean("indexed"); - if (indexed != null && indexed) { - inputSize++; + if (inputs != null) { + for (int i = 0; i < inputs.size(); i++) { + JSONObject param = inputs.getJSONObject(i); + Boolean indexed = param.getBoolean("indexed"); + if (indexed != null && indexed) { + inputSize++; + } } } return inputSize == topicList.size(); From cb1e4a9f1609c2f24e8c6b3e727e5324867acc51 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 3 Jun 2019 20:07:17 +0800 Subject: [PATCH 04/42] add input null check --- .../trongeventquery/contractlogs/ContractWithAbiController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java b/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java index 3c469b9..a573298 100644 --- a/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java +++ b/src/main/java/org/tron/trongeventquery/contractlogs/ContractWithAbiController.java @@ -50,7 +50,7 @@ public JSONObject findByContractAddressAndEntryName( return getContractTrigger(hmap, query); } - @RequestMapping(method = RequestMethod.POST, value = "/contract/uniqueId/{uniqueId}") + @RequestMapping(method = RequestMethod.POST, value = "/contract/uniqueId/{uniqueId}") public JSONObject getEvent( @PathVariable(value = "uniqueId", required = false) String uniqueId, @RequestBody Map hmap From 8dbd657a98eb6032bf9f5bce036f52105f7e1049 Mon Sep 17 00:00:00 2001 From: wubinTron <44354524+wubinTron@users.noreply.github.com> Date: Sat, 12 Oct 2019 12:42:10 +0800 Subject: [PATCH 05/42] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4c26edc..6d06f52 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ Make sure the relative path of config.conf and troneventquery jar. The config.co - troneventquery/insertIndex.sh is used to setup mongodb index to speedup query. (make sure run insertIndex before create collecions) + ## Delete expire data +- troneventquery/deleteData.sh is used to delete expire data +- using crontable delete regularly mongodb expire data(if not delete, visit delay time will become too long) + ## What is the main HTTP service? baseUrl: https://api.tronex.io From e45152c32f2150875d3245ace41e44391aa8861e Mon Sep 17 00:00:00 2001 From: wubinTron <44354524+wubinTron@users.noreply.github.com> Date: Sat, 12 Oct 2019 12:43:31 +0800 Subject: [PATCH 06/42] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d06f52..69943ce 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Make sure the relative path of config.conf and troneventquery jar. The config.co ## Delete expire data - troneventquery/deleteData.sh is used to delete expire data -- using crontable delete regularly mongodb expire data(if not delete, visit delay time will become too long) +- using crontable delete regularly mongodb expire data(if not delete, the database will be too big) ## What is the main HTTP service? From 2a6d60511fe2660a8329a696be8fbc8019fd1ff0 Mon Sep 17 00:00:00 2001 From: wubinTron Date: Tue, 14 Jan 2020 12:00:29 +0800 Subject: [PATCH 07/42] fix bug --- .../ContractEventController.java | 207 ++++++++++++++---- 1 file changed, 159 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index d01dc80..4caae35 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -8,6 +8,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.spongycastle.util.Strings; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.core.MongoTemplate; @@ -112,54 +113,7 @@ public List findOneByTransaction(@PathVariable Strin query.setTransactionIdEqual(transactionId); List queryResult = mongoTemplate.find(query.getQuery(), ContractEventTriggerEntity.class); - return queryResult; - } - - // get event list - @RequestMapping(method = RequestMethod.GET, value = "/events/{contractAddress}") - public List findEventsListByContractAddress( - @PathVariable String contractAddress, - @RequestParam(value = "limit", required = false, defaultValue = "25") int limit, - @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, - @RequestParam(value = "start", required = false, defaultValue = "0") int start, - @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, - @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp - ) { - - QueryFactory query = new QueryFactory(); - if (blocknum != -1) { - query.setBlockNumGte(blocknum); - } - query.setContractAddress(contractAddress); - query.setTimestampGreaterEqual(timestamp); - query.setPageniate(this.setPagniateVariable(limit, sort, start)); - List result = mongoTemplate.find(query.getQuery(), - ContractEventTriggerEntity.class); - - List array = new ArrayList<>(); - for (ContractEventTriggerEntity p : result) { - Map map = new HashMap(); - map.put("transactionId", p.getTransactionId()); - map.put("blockNumber", p.getBlockNumber()); - map.put("timeStamp", p.getTimeStamp()); - map.put("eventSignatureFull", p.getEventSignatureFull()); - map.put("eventName", p.getEventName()); - map.put("contractAddress", p.getContractAddress()); - int i = 0; - Map dataMap = p.getDataMap(); - Map topicMap = p.getTopicMap(); - for (String topic : topicMap.keySet()) { - dataMap.put(topic, topicMap.get(topic)); - } - - while (dataMap.containsKey(String.valueOf(i))) { - map.put(String.valueOf(i), dataMap.get(String.valueOf(i))); - i++; - } - array.add(new JSONObject(map)); - } - - return array; + return queryResult; } @RequestMapping(method = RequestMethod.GET, @@ -283,4 +237,161 @@ private Pageable setPagniateVariable(int limit, String sort, int start) { } + // get event list + @RequestMapping(method = RequestMethod.GET, value = "/events/{contractAddress}") + public List findEventsListByContractAddress( + @PathVariable String contractAddress, + @RequestParam(value = "limit", required = false, defaultValue = "25") int limit, + @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, + @RequestParam(value = "start", required = false, defaultValue = "0") int start, + @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, + @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp + ) { + + QueryFactory query = new QueryFactory(); + if (blocknum != -1) { + query.setBlockNumGte(blocknum); + } + query.setContractAddress(contractAddress); + query.setTimestampGreaterEqual(timestamp); + query.setPageniate(this.setPagniateVariable(limit, sort, start)); + List result = mongoTemplate.find(query.getQuery(), + ContractEventTriggerEntity.class); + + List array = new ArrayList<>(); + for (ContractEventTriggerEntity p : result) { + Map map = new HashMap(); + map.put("transactionId", p.getTransactionId()); + map.put("blockNumber", p.getBlockNumber()); + map.put("timeStamp", p.getTimeStamp()); + map.put("eventSignatureFull", p.getEventSignatureFull()); + map.put("eventName", p.getEventName()); + map.put("contractAddress", p.getContractAddress()); + int i = 0; + Map dataMap = p.getDataMap(); + Map topicMap = p.getTopicMap(); + for (String topic : topicMap.keySet()) { + dataMap.put(topic, topicMap.get(topic)); + } + + while (dataMap.containsKey(String.valueOf(i))) { + map.put(String.valueOf(i), dataMap.get(String.valueOf(i))); + i++; + } + array.add(new JSONObject(map)); + } + + return array; + } + + // for tron web + + @RequestMapping(method = RequestMethod.GET, value = "/events/v1/transaction/{transactionId}") + public List findOneByTransactionTronGri (@PathVariable String transactionId) { + QueryFactory query = new QueryFactory(); + query.setTransactionIdEqual(transactionId); + List queryResult = mongoTemplate.find(query.getQuery(), + ContractEventTriggerEntity.class); + + List array = new ArrayList<>(); + for (ContractEventTriggerEntity p : queryResult) { + Map map = new HashMap(); + map.put("transaction_id", p.getTransactionId()); + map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_number", p.getBlockNumber()); + map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); + map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); + map.put("event_index", getIndex(p.getUniqueId())); + map.put("event_name", p.getEventName()); + map.put("contract_address", p.getContractAddress()); + map.put("caller_contract_address", p.getOriginAddress()); + + array.add(new JSONObject(map)); + } + + return array; + } + + // get event list + @RequestMapping(method = RequestMethod.GET, value = "/events/v1/{contractAddress}") + public List findEventsByContractAddressTronGrid ( + @PathVariable String contractAddress, + @RequestParam(value = "limit", required = false, defaultValue = "25") int limit, + @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, + @RequestParam(value = "start", required = false, defaultValue = "0") int start, + @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, + @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp + ) { + + QueryFactory query = new QueryFactory(); + if (blocknum != -1) { + query.setBlockNumGte(blocknum); + } + query.setContractAddress(contractAddress); + query.setTimestampGreaterEqual(timestamp); + query.setPageniate(this.setPagniateVariable(limit, sort, start)); + List result = mongoTemplate.find(query.getQuery(), + ContractEventTriggerEntity.class); + + List array = new ArrayList<>(); + for (ContractEventTriggerEntity p : result) { + Map map = new HashMap(); + map.put("transaction_id", p.getTransactionId()); + map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_number", p.getBlockNumber()); + map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); + map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); + map.put("event_index", getIndex(p.getUniqueId())); + map.put("event_name", p.getEventName()); + map.put("contract_address", p.getContractAddress()); + map.put("caller_contract_address", p.getOriginAddress()); + + array.add(new JSONObject(map)); + } + + return array; + } + + List getResultType(String fullName, String eventSignature) { + int num = eventSignature.length(); + String newSignature = fullName.substring(num + 1, fullName.length() - 1); + String[] arrayList = Strings.split(newSignature, ','); + Map map = new HashMap(); + List array = new ArrayList<>(); + for (String str : arrayList) { + String[] type = str.split(" "); + map.put(type[1], type[0]); + } + array.add(new JSONObject(map)); + return array; + } + + List getResult(String fullName, String eventSignature, Map topMap, Map dataMap) { + int num = eventSignature.length(); + String newSignature = fullName.substring(num + 1, fullName.length() - 1); + String[] arrayList = Strings.split(newSignature, ','); + Map map = new HashMap(); + List array = new ArrayList<>(); + int i = 0; + for (String str : arrayList) { + String[] type = str.split(" "); + + String ans; + if (topMap.containsKey(i)) { + ans = topMap.get(String.format("%d", i)); + } else { + ans = dataMap.get(String.format("%d", i)); + } + i ++; + map.put(type[1], ans); + + } + array.add(new JSONObject(map)); + return array; + } + + int getIndex(String unique) { + String[]id = unique.split("_"); + return Integer.parseInt(id[1]) - 1; + } } From e89b4d07abd32df657f5896eb596b335865700fb Mon Sep 17 00:00:00 2001 From: helloboy12345 Date: Wed, 15 Jan 2020 12:39:48 +0800 Subject: [PATCH 08/42] TronWeb compatibility --- src/main/java/org/tron/core/Wallet.java | 2 +- .../ContractEventController.java | 158 +++++++++++++++++- 2 files changed, 150 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/tron/core/Wallet.java b/src/main/java/org/tron/core/Wallet.java index 862692a..431e29b 100755 --- a/src/main/java/org/tron/core/Wallet.java +++ b/src/main/java/org/tron/core/Wallet.java @@ -49,7 +49,7 @@ public static String encode58Check(byte[] input) { return Base58.encode(inputCheck); } - private static byte[] decode58Check(String input) { + public static byte[] decode58Check(String input) { byte[] decodeCheck = Base58.decode(input); if (decodeCheck.length <= 4) { return null; diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 4caae35..6b39d1c 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -1,5 +1,8 @@ package org.tron.trongeventquery.contractevents; + +import static org.tron.core.Wallet.decode58Check; + import com.alibaba.fastjson.JSONObject; import java.util.ArrayList; import java.util.HashMap; @@ -8,6 +11,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.spongycastle.util.Strings; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; @@ -17,6 +21,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.tron.common.utils.ByteArray; +import org.tron.core.Constant; import org.tron.trongeventquery.query.QueryFactory; @RestController @@ -233,7 +239,7 @@ private Pageable setPagniateVariable(int limit, String sort, int start) { int page = start; int pageSize = limit; - return QueryFactory.make_pagination(Math.max(0,page - 1),Math.min(200,pageSize),sort); + return QueryFactory.make_pagination(Math.max(0,page - 1), Math.min(200,pageSize), sort); } @@ -286,8 +292,9 @@ public List findEventsListByContractAddress( // for tron web - @RequestMapping(method = RequestMethod.GET, value = "/events/v1/transaction/{transactionId}") + @RequestMapping(method = RequestMethod.GET, value = "/event/transaction/{transactionId}") public List findOneByTransactionTronGri (@PathVariable String transactionId) { + QueryFactory query = new QueryFactory(); query.setTransactionIdEqual(transactionId); List queryResult = mongoTemplate.find(query.getQuery(), @@ -313,27 +320,146 @@ public List findOneByTransactionTronGri (@PathVariable String transa } // get event list - @RequestMapping(method = RequestMethod.GET, value = "/events/v1/{contractAddress}") + @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}") public List findEventsByContractAddressTronGrid ( @PathVariable String contractAddress, - @RequestParam(value = "limit", required = false, defaultValue = "25") int limit, + @RequestParam(value = "size", required = false, defaultValue = "20") int limit, @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, @RequestParam(value = "start", required = false, defaultValue = "0") int start, @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, - @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp + @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, + @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp + ) { + if (sort.contains("block_timestamp")) { + sort = sort.replace("block_timestamp", "timeStamp"); + } + if (fromTimestamp > 0) { + timestamp = fromTimestamp; + } + + QueryFactory query = new QueryFactory(); + if (blocknum != -1) { + query.setBlockNumGte(blocknum); + } + query.setContractAddress(contractAddress); + query.setTimestampGreaterEqual(timestamp); + query.setPageniate(this.setPagniateVariable(limit, sort, start)); + List result = mongoTemplate.find(query.getQuery(), + ContractEventTriggerEntity.class); + + List array = new ArrayList<>(); + int count = 1; + for (ContractEventTriggerEntity p : result) { + Map map = new HashMap(); + map.put("transaction_id", p.getTransactionId()); + map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_number", p.getBlockNumber()); + map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); + map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); + map.put("event_index", getIndex(p.getUniqueId())); + map.put("event_name", p.getEventName()); + map.put("contract_address", p.getContractAddress()); + map.put("caller_contract_address", p.getOriginAddress()); + + if (count++ == result.size()) { + map.put("_fingerprint", start + 1); + } + array.add(new JSONObject(map)); + } + + return array; + } + + // get event list + @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}/{eventName}") + public List findEventsByContractAddressAndEventNameTronGrid ( + @PathVariable String contractAddress, + @PathVariable String eventName, + @RequestParam(value = "size", required = false, defaultValue = "20") int limit, + @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, + @RequestParam(value = "start", required = false, defaultValue = "0") int start, + @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, + @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, + @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp + ) { + if (sort.contains("block_timestamp")) { + sort = sort.replace("block_timestamp", "timeStamp"); + } + if (fromTimestamp > 0) { + timestamp = fromTimestamp; + } + + QueryFactory query = new QueryFactory(); + if (blocknum != -1) { + query.setBlockNumGte(blocknum); + } + query.setContractAddress(contractAddress); + query.setEventName(eventName); + + query.setTimestampGreaterEqual(timestamp); + query.setPageniate(this.setPagniateVariable(limit, sort, start)); + List result = mongoTemplate.find(query.getQuery(), + ContractEventTriggerEntity.class); + + List array = new ArrayList<>(); + int count = 1; + for (ContractEventTriggerEntity p : result) { + Map map = new HashMap(); + map.put("transaction_id", p.getTransactionId()); + map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_number", p.getBlockNumber()); + map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); + map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); + map.put("event_index", getIndex(p.getUniqueId())); + map.put("event_name", p.getEventName()); + map.put("contract_address", p.getContractAddress()); + map.put("caller_contract_address", p.getOriginAddress()); + + if (count++ == result.size()) { + map.put("_fingerprint", start + 1); + } + array.add(new JSONObject(map)); + } + + return array; + } + + // get event list + @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}/{eventName}/{blockNum}") + public List findEventsByContractAddressAndEventNameAndBlockNumTronGrid ( + @PathVariable String contractAddress, + @PathVariable String eventName, + @PathVariable Long blockNum, + @RequestParam(value = "size", required = false, defaultValue = "20") int limit, + @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, + @RequestParam(value = "start", required = false, defaultValue = "0") int start, + @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, + @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, + @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp ) { + if (sort.contains("block_timestamp")) { + sort = sort.replace("block_timestamp", "timeStamp"); + } + + if (fromTimestamp > 0) { + timestamp = fromTimestamp; + } QueryFactory query = new QueryFactory(); if (blocknum != -1) { query.setBlockNumGte(blocknum); } query.setContractAddress(contractAddress); + query.setEventName(eventName); + query.setBlockNum(blockNum); + query.setTimestampGreaterEqual(timestamp); query.setPageniate(this.setPagniateVariable(limit, sort, start)); List result = mongoTemplate.find(query.getQuery(), ContractEventTriggerEntity.class); List array = new ArrayList<>(); + int count = 1; for (ContractEventTriggerEntity p : result) { Map map = new HashMap(); map.put("transaction_id", p.getTransactionId()); @@ -346,6 +472,9 @@ public List findEventsByContractAddressTronGrid ( map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); + if (count++ == result.size()) { + map.put("_fingerprint", start + 1); + } array.add(new JSONObject(map)); } @@ -377,14 +506,25 @@ List getResult(String fullName, String eventSignature, Map Date: Wed, 15 Jan 2020 14:21:27 +0800 Subject: [PATCH 09/42] fix bug --- pom.xml | 1 - .../contractevents/ContractEventController.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 08fc1c2..b574aaa 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,6 @@ 24.1-jre - diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 6b39d1c..b4fc0b8 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -22,11 +22,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.tron.common.utils.ByteArray; -import org.tron.core.Constant; import org.tron.trongeventquery.query.QueryFactory; @RestController public class ContractEventController { + public static final String ADD_PRE_FIX_STRING_MAINNET = "41"; + @Autowired MongoTemplate mongoTemplate; @@ -516,7 +517,7 @@ List getResult(String fullName, String eventSignature, Map Date: Wed, 15 Jan 2020 14:31:49 +0800 Subject: [PATCH 10/42] update .gitignore --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b118fd8..e268bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -target/classes/org/tron/trongrid/ContractEventTriggerEntity.class -target/classes/org/tron/trongrid/InternalTransactionPojo.class +target/* +.idea/* +troneventquery.iml \ No newline at end of file From e40842c5d2837e6c60b5943541ec4ff5ae9d3888 Mon Sep 17 00:00:00 2001 From: helloboy12345 Date: Wed, 15 Jan 2020 15:41:11 +0800 Subject: [PATCH 11/42] fix bug --- .../java/org/tron/common/crypto/Crypto.java | 84 +++++++++++++++++++ .../ContractEventController.java | 29 +++++-- 2 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/tron/common/crypto/Crypto.java diff --git a/src/main/java/org/tron/common/crypto/Crypto.java b/src/main/java/org/tron/common/crypto/Crypto.java new file mode 100644 index 0000000..9829a08 --- /dev/null +++ b/src/main/java/org/tron/common/crypto/Crypto.java @@ -0,0 +1,84 @@ +package org.tron.common.crypto; +import java.util.regex.Pattern; + +public class Crypto { + + private final static long SECRET_KEY = 5658116; + private final static String CONVERT_KEY = "DeCATbJIzM"; + private final static String CONFUSED_WORDS_KEY = "FxYNgq"; + private final static int LEN_KEY = 32; + + + static public String encrypt(String str){ + Long time = new Long(157551410); + if(!isNumber(str)){ + System.out.println(str + "不是数字"); + return null; + } + + long number = Long.parseLong(str); + long newNumber = (number + time) * SECRET_KEY; + String[] numArr = String.valueOf(newNumber).split(""); + String[] initArr = CONVERT_KEY.split(""); + int len = numArr.length; + StringBuffer buffer = new StringBuffer(); + + for(int i = 0; i < len; i++){ + int inx = Integer.parseInt(numArr[i]); + buffer.append(initArr[inx]); + } + + String[] cwkArr = CONFUSED_WORDS_KEY.split(""); + if(len < LEN_KEY){ + int l = LEN_KEY - len; + for(int i = 0; i < l; i++){ + int index = (int)(Math.random()*buffer.length()); + int inx = (int)(Math.random()*(CONFUSED_WORDS_KEY.length())); + buffer.insert(index,cwkArr[inx]); + } + } + String result = buffer.toString(); + return result; + } + + public static int decrypt(String str){ + Long time = new Long(157551410); + if(null == str || "".equals(str)){ + return 0; + } + int l = CONFUSED_WORDS_KEY.length(); + String[] cwkArr = CONFUSED_WORDS_KEY.split(""); + for(int i = 0; i < l; i++){ + str = str.replaceAll(cwkArr[i],""); + } + String[] initArr = str.split(""); + int len = initArr.length; + StringBuffer result = new StringBuffer(); + for(int i = 0; i < len; i++ ){ + int k = CONVERT_KEY.indexOf(initArr[i]); + if(k == -1){ + return 0; + } + result.append(k); + } + Long number; + try { + long total = Long.parseLong(result.toString()); + long sum = total/SECRET_KEY; + number = sum - time; + } catch (NumberFormatException e) { + e.printStackTrace(); + return 0; + } + return number.intValue(); + } + + /** + * 数字校验 + * */ + public static boolean isNumber(String value) { + String pattern = "^[0-9]*[1-9][0-9]*$"; + boolean isMatch = Pattern.matches(pattern, value); + return isMatch; + } +} diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index b4fc0b8..e676551 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.tron.common.crypto.Crypto; import org.tron.common.utils.ByteArray; import org.tron.trongeventquery.query.QueryFactory; @@ -329,7 +330,8 @@ public List findEventsByContractAddressTronGrid ( @RequestParam(value = "start", required = false, defaultValue = "0") int start, @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, - @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp + @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, + @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint ) { if (sort.contains("block_timestamp")) { sort = sort.replace("block_timestamp", "timeStamp"); @@ -338,6 +340,10 @@ public List findEventsByContractAddressTronGrid ( timestamp = fromTimestamp; } + if (fingerprint.length() != 0) { + start = Crypto.decrypt(fingerprint) > 0 ? Crypto.decrypt(fingerprint) : 0; + } + QueryFactory query = new QueryFactory(); if (blocknum != -1) { query.setBlockNumGte(blocknum); @@ -363,7 +369,7 @@ public List findEventsByContractAddressTronGrid ( map.put("caller_contract_address", p.getOriginAddress()); if (count++ == result.size()) { - map.put("_fingerprint", start + 1); + map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); } array.add(new JSONObject(map)); } @@ -381,7 +387,8 @@ public List findEventsByContractAddressAndEventNameTronGrid ( @RequestParam(value = "start", required = false, defaultValue = "0") int start, @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, - @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp + @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, + @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint ) { if (sort.contains("block_timestamp")) { sort = sort.replace("block_timestamp", "timeStamp"); @@ -390,6 +397,10 @@ public List findEventsByContractAddressAndEventNameTronGrid ( timestamp = fromTimestamp; } + if (fingerprint.length() != 0) { + start = Crypto.decrypt(fingerprint) > 0 ? Crypto.decrypt(fingerprint) : 0; + } + QueryFactory query = new QueryFactory(); if (blocknum != -1) { query.setBlockNumGte(blocknum); @@ -417,7 +428,7 @@ public List findEventsByContractAddressAndEventNameTronGrid ( map.put("caller_contract_address", p.getOriginAddress()); if (count++ == result.size()) { - map.put("_fingerprint", start + 1); + map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); } array.add(new JSONObject(map)); } @@ -436,7 +447,8 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr @RequestParam(value = "start", required = false, defaultValue = "0") int start, @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, - @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp + @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, + @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint ) { if (sort.contains("block_timestamp")) { sort = sort.replace("block_timestamp", "timeStamp"); @@ -446,6 +458,10 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr timestamp = fromTimestamp; } + if (fingerprint.length() != 0) { + start = Crypto.decrypt(fingerprint) > 0 ? Crypto.decrypt(fingerprint) : 0; + } + QueryFactory query = new QueryFactory(); if (blocknum != -1) { query.setBlockNumGte(blocknum); @@ -474,7 +490,7 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr map.put("caller_contract_address", p.getOriginAddress()); if (count++ == result.size()) { - map.put("_fingerprint", start + 1); + map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); } array.add(new JSONObject(map)); } @@ -535,4 +551,5 @@ int getIndex(String unique) { String[]id = unique.split("_"); return Integer.parseInt(id[1]) - 1; } + } From 684dc69e4f5b26424c34908ebb856ec36edbff7a Mon Sep 17 00:00:00 2001 From: wubinTron Date: Wed, 15 Jan 2020 15:49:57 +0800 Subject: [PATCH 12/42] fix logger method --- src/main/java/org/tron/common/crypto/Crypto.java | 7 +++---- src/main/java/org/tron/common/crypto/Hash.java | 5 +++-- src/main/java/org/tron/common/utils/ByteArray.java | 5 +++-- src/main/java/org/tron/common/utils/LogConfig.java | 10 ++++++++++ .../contractevents/ContractEventController.java | 1 - .../trongeventquery/query/ContractEventParser.java | 5 +++-- .../trongeventquery/query/ContractEventParserJson.java | 5 +++-- 7 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/tron/common/utils/LogConfig.java diff --git a/src/main/java/org/tron/common/crypto/Crypto.java b/src/main/java/org/tron/common/crypto/Crypto.java index 9829a08..21784b7 100644 --- a/src/main/java/org/tron/common/crypto/Crypto.java +++ b/src/main/java/org/tron/common/crypto/Crypto.java @@ -1,4 +1,6 @@ package org.tron.common.crypto; +import static org.tron.common.utils.LogConfig.LOG; + import java.util.regex.Pattern; public class Crypto { @@ -12,7 +14,7 @@ public class Crypto { static public String encrypt(String str){ Long time = new Long(157551410); if(!isNumber(str)){ - System.out.println(str + "不是数字"); + LOG.info("not number"); return null; } @@ -73,9 +75,6 @@ public static int decrypt(String str){ return number.intValue(); } - /** - * 数字校验 - * */ public static boolean isNumber(String value) { String pattern = "^[0-9]*[1-9][0-9]*$"; boolean isMatch = Pattern.matches(pattern, value); diff --git a/src/main/java/org/tron/common/crypto/Hash.java b/src/main/java/org/tron/common/crypto/Hash.java index 6421c33..0a1cfc0 100644 --- a/src/main/java/org/tron/common/crypto/Hash.java +++ b/src/main/java/org/tron/common/crypto/Hash.java @@ -18,6 +18,8 @@ package org.tron.common.crypto; +import static org.tron.common.utils.LogConfig.LOG; + import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.Provider; @@ -25,7 +27,6 @@ import lombok.extern.slf4j.Slf4j; import org.tron.common.crypto.jce.TronCastleProvider; -@Slf4j(topic = "crypto") public class Hash { private static final Provider CRYPTO_PROVIDER; @@ -48,7 +49,7 @@ public static byte[] sha3(byte[] input) { digest.update(input); return digest.digest(); } catch (NoSuchAlgorithmException e) { - log.error("Can't find such algorithm", e); + LOG.error("Can't find such algorithm", e); throw new RuntimeException(e); } } diff --git a/src/main/java/org/tron/common/utils/ByteArray.java b/src/main/java/org/tron/common/utils/ByteArray.java index f2722be..52b5ccc 100644 --- a/src/main/java/org/tron/common/utils/ByteArray.java +++ b/src/main/java/org/tron/common/utils/ByteArray.java @@ -18,6 +18,8 @@ package org.tron.common.utils; +import static org.tron.common.utils.LogConfig.LOG; + import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; import java.io.ByteArrayOutputStream; @@ -29,7 +31,6 @@ import org.apache.commons.lang3.StringUtils; import org.spongycastle.util.encoders.Hex; -@Slf4j(topic = "utils") public class ByteArray { public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; @@ -101,7 +102,7 @@ public static byte[] fromObject(Object obj) { objectOutputStream.flush(); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { - log.error("objectToByteArray failed: " + e.getMessage(), e); + LOG.error("objectToByteArray failed: " + e.getMessage(), e); } return bytes; } diff --git a/src/main/java/org/tron/common/utils/LogConfig.java b/src/main/java/org/tron/common/utils/LogConfig.java new file mode 100644 index 0000000..c37f415 --- /dev/null +++ b/src/main/java/org/tron/common/utils/LogConfig.java @@ -0,0 +1,10 @@ +package org.tron.common.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class LogConfig { + public static final Logger LOG = LoggerFactory.getLogger(LogConfig.class); +} \ No newline at end of file diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index e676551..a24d5a4 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -190,7 +190,6 @@ public List filterevent( } query.setPageniate(this.setPagniateVariable(limit, sort, start)); - System.out.println(query.toString()); List result = mongoTemplate.find(query.getQuery(), ContractEventTriggerEntity.class); return result; diff --git a/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java b/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java index 8c4df37..af6453a 100644 --- a/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java +++ b/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java @@ -1,5 +1,7 @@ package org.tron.trongeventquery.query; +import static org.tron.common.utils.LogConfig.LOG; + import java.math.BigInteger; import java.util.regex.Pattern; import lombok.extern.slf4j.Slf4j; @@ -12,7 +14,6 @@ import org.tron.common.runtime.vm.DataWord; import org.tron.core.Wallet; -@Slf4j(topic = "Parser") public class ContractEventParser { private static final int DATAWORD_UNIT_SIZE = 32; @@ -52,7 +53,7 @@ protected static String parseDataBytes(byte[] data, String typeStr, int index) { return type == Type.STRING ? new String(realBytes) : Hex.toHexString(realBytes); } } catch (OutputLengthException | ArithmeticException e) { - log.debug("parseDataBytes ", e); + LOG.debug("parseDataBytes ", e); } throw new UnsupportedOperationException("unsupported type:" + typeStr); } diff --git a/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java b/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java index c3c4838..9030325 100644 --- a/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java +++ b/src/main/java/org/tron/trongeventquery/query/ContractEventParserJson.java @@ -1,6 +1,8 @@ package org.tron.trongeventquery.query; +import static org.tron.common.utils.LogConfig.LOG; + import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import java.util.HashMap; @@ -11,7 +13,6 @@ import org.pf4j.util.StringUtils; import org.spongycastle.util.encoders.Hex; -@Slf4j(topic = "Parser") public class ContractEventParserJson extends ContractEventParser { /** @@ -102,7 +103,7 @@ public static Map parseEventData(byte[] data, map.put("0", Hex.toHexString(data)); } } catch (UnsupportedOperationException e) { - log.debug("UnsupportedOperationException", e); + LOG.debug("UnsupportedOperationException", e); map.clear(); map.put(startIndex.toString(), Hex.toHexString(data)); } From 4cc965c58c21b55b935a33d9f9881de0c1daf6de Mon Sep 17 00:00:00 2001 From: wubinTron Date: Wed, 15 Jan 2020 17:48:31 +0800 Subject: [PATCH 13/42] add solidity comfirm --- .../trongeventquery/TronEventApplication.java | 11 ++++++ .../ContractEventController.java | 38 +++++++++++++++++++ .../query/ContractEventParser.java | 2 + 3 files changed, 51 insertions(+) diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index c436886..815ed7e 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -1,5 +1,8 @@ package org.tron.trongeventquery; +import static org.tron.common.utils.LogConfig.LOG; +import static org.tron.trongeventquery.contractevents.ContractEventController.isRunRePushThread; + import com.mongodb.MongoClient; import com.mongodb.MongoClientOptions; import com.mongodb.MongoCredential; @@ -29,6 +32,7 @@ public class TronEventApplication { public static void main(String[] args) { SpringApplication.run(TronEventApplication.class, args); + shutdown(); } @Bean @@ -82,4 +86,11 @@ public void customize(Connector connector) { }); return factory; } + + public static void shutdown() { + Runnable stopThread = + () -> isRunRePushThread.set(false); + LOG.info("********register application shutdown hook********"); + Runtime.getRuntime().addShutdownHook(new Thread(stopThread)); + } } diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index a24d5a4..8308798 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -1,6 +1,7 @@ package org.tron.trongeventquery.contractevents; +import static org.tron.common.utils.LogConfig.LOG; import static org.tron.core.Wallet.decode58Check; import com.alibaba.fastjson.JSONObject; @@ -10,12 +11,17 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; import org.spongycastle.util.Strings; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -26,12 +32,15 @@ import org.tron.trongeventquery.query.QueryFactory; @RestController +@Component public class ContractEventController { public static final String ADD_PRE_FIX_STRING_MAINNET = "41"; @Autowired MongoTemplate mongoTemplate; + public static AtomicBoolean isRunRePushThread = new AtomicBoolean(true); + public static AtomicLong latestSolidifiedBlockNumber = new AtomicLong(0); @RequestMapping(method = RequestMethod.GET, value = "/healthcheck") public String healthCheck() { @@ -367,6 +376,10 @@ public List findEventsByContractAddressTronGrid ( map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); + if (p.getBlockNumber() > latestSolidifiedBlockNumber.get()) { + + } + if (count++ == result.size()) { map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); } @@ -551,4 +564,29 @@ int getIndex(String unique) { return Integer.parseInt(id[1]) - 1; } + private Runnable getSolidityBlockNumber = + () -> { + while (isRunRePushThread.get()) { + try { + QueryFactory query = new QueryFactory(); + query.setPageniate(QueryFactory.setPagniateVariable(0, 1, "-latestSolidifiedBlockNumber")); + List contractEventTriggerEntityList + = mongoTemplate.find(query.getQuery(), + ContractEventTriggerEntity.class); + if (contractEventTriggerEntityList.isEmpty()) { + return; + } + latestSolidifiedBlockNumber.set(contractEventTriggerEntityList.get(0).getLatestSolidifiedBlockNumber()); + TimeUnit.MILLISECONDS.sleep(1000L); + } catch (InterruptedException e) { + LOG.error(e.getMessage()); + } + } + }; + + @PostConstruct + public void init() { + Thread rePushThread = new Thread(getSolidityBlockNumber); + rePushThread.start(); + } } diff --git a/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java b/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java index af6453a..d005ebe 100644 --- a/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java +++ b/src/main/java/org/tron/trongeventquery/query/ContractEventParser.java @@ -1,5 +1,6 @@ package org.tron.trongeventquery.query; + import static org.tron.common.utils.LogConfig.LOG; import java.math.BigInteger; @@ -14,6 +15,7 @@ import org.tron.common.runtime.vm.DataWord; import org.tron.core.Wallet; + public class ContractEventParser { private static final int DATAWORD_UNIT_SIZE = 32; From d29643818bb339a13b2a36513922217ea23f2106 Mon Sep 17 00:00:00 2001 From: wubinTron Date: Wed, 15 Jan 2020 19:49:03 +0800 Subject: [PATCH 14/42] add solidity comfirm --- .../ContractEventController.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 8308798..109dfe6 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -35,6 +35,10 @@ @Component public class ContractEventController { public static final String ADD_PRE_FIX_STRING_MAINNET = "41"; + private static final int RETURN_ALL_EVENTS = 0; + private static final int RETURN_ONLYCONFIRMED_EVENTS = 1; + //private static final int RETURN_ONLYCONFIRMED_EVENTS = 1; + @Autowired MongoTemplate mongoTemplate; @@ -339,8 +343,12 @@ public List findEventsByContractAddressTronGrid ( @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, - @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint - ) { + @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint, + @RequestParam(value = "onlyConfirmed", required = false, defaultValue = "") String onlyConfirmed, + @RequestParam(value = "onlyUnconfirmed", required = false, defaultValue = "") String onlyUnconfirmed) { + + //int confirm = needConfirmed(onlyConfirmed, onlyUnconfirmed); + if (sort.contains("block_timestamp")) { sort = sort.replace("block_timestamp", "timeStamp"); } @@ -376,10 +384,6 @@ public List findEventsByContractAddressTronGrid ( map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); - if (p.getBlockNumber() > latestSolidifiedBlockNumber.get()) { - - } - if (count++ == result.size()) { map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); } @@ -449,15 +453,14 @@ public List findEventsByContractAddressAndEventNameTronGrid ( } // get event list - @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}/{eventName}/{blockNum}") + @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}/{eventName}/{blockNumber}") public List findEventsByContractAddressAndEventNameAndBlockNumTronGrid ( @PathVariable String contractAddress, @PathVariable String eventName, - @PathVariable Long blockNum, + @PathVariable String blockNumber, @RequestParam(value = "size", required = false, defaultValue = "20") int limit, @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, @RequestParam(value = "start", required = false, defaultValue = "0") int start, - @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint @@ -475,13 +478,13 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr } QueryFactory query = new QueryFactory(); - if (blocknum != -1) { - query.setBlockNumGte(blocknum); + if (blockNumber.equalsIgnoreCase("latest")) { + query.setBlockNum(latestSolidifiedBlockNumber.get()); + } else { + query.setBlockNum(Long.parseLong(blockNumber)); } query.setContractAddress(contractAddress); query.setEventName(eventName); - query.setBlockNum(blockNum); - query.setTimestampGreaterEqual(timestamp); query.setPageniate(this.setPagniateVariable(limit, sort, start)); List result = mongoTemplate.find(query.getQuery(), @@ -589,4 +592,13 @@ public void init() { Thread rePushThread = new Thread(getSolidityBlockNumber); rePushThread.start(); } + +// int needConfirmed(String onlyConfirmed, String onlyUnconfirmed) { +// if (onlyConfirmed.length() == 0 && onlyUnconfirmed.length() == 0) { +// return -1; +// } +// if (onlyConfirmed.length() != 0 && onlyUnconfirmed.length() != 0) { +// +// } +// } } From a84f6c7394873c49ecf12dddb2fee99aa864238b Mon Sep 17 00:00:00 2001 From: wubinTron Date: Thu, 16 Jan 2020 14:42:32 +0800 Subject: [PATCH 15/42] fix bug --- .../ContractEventController.java | 71 +++++++++++++------ .../trongeventquery/query/QueryFactory.java | 6 +- .../trongeventquery/response/Response.java | 19 +++++ 3 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 src/main/java/org/tron/trongeventquery/response/Response.java diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 109dfe6..7df5c63 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -30,14 +30,16 @@ import org.tron.common.crypto.Crypto; import org.tron.common.utils.ByteArray; import org.tron.trongeventquery.query.QueryFactory; +import org.tron.trongeventquery.response.Response; @RestController @Component public class ContractEventController { public static final String ADD_PRE_FIX_STRING_MAINNET = "41"; private static final int RETURN_ALL_EVENTS = 0; - private static final int RETURN_ONLYCONFIRMED_EVENTS = 1; - //private static final int RETURN_ONLYCONFIRMED_EVENTS = 1; + private static final int RETURN_ONLY_CONFIRMED_EVENTS = 1; + private static final int RETURN_ONLY_UNCONFIRMED_EVENTS = 2; + private static final int CONFILICTING_PARAMETERS = -1; @Autowired @@ -118,7 +120,7 @@ public List verifyEvents( long latestSolidifiedBlockNumber = contractEventTriggerEntityList.get(0).getLatestSolidifiedBlockNumber(); query = new QueryFactory(); - query.setBlockNumSmall(latestSolidifiedBlockNumber); + query.setBlockNumLte(latestSolidifiedBlockNumber); query.setTimestampGreaterEqual(timestamp); query.setRemovedEqual(false); query.setPageniate(QueryFactory.setPagniateVariable(start, limit, sort)); @@ -335,20 +337,17 @@ public List findOneByTransactionTronGri (@PathVariable String transa // get event list @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}") - public List findEventsByContractAddressTronGrid ( + public Object findEventsByContractAddressTronGrid ( @PathVariable String contractAddress, @RequestParam(value = "size", required = false, defaultValue = "20") int limit, @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, @RequestParam(value = "start", required = false, defaultValue = "0") int start, - @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint, @RequestParam(value = "onlyConfirmed", required = false, defaultValue = "") String onlyConfirmed, @RequestParam(value = "onlyUnconfirmed", required = false, defaultValue = "") String onlyUnconfirmed) { - //int confirm = needConfirmed(onlyConfirmed, onlyUnconfirmed); - if (sort.contains("block_timestamp")) { sort = sort.replace("block_timestamp", "timeStamp"); } @@ -361,9 +360,17 @@ public List findEventsByContractAddressTronGrid ( } QueryFactory query = new QueryFactory(); - if (blocknum != -1) { - query.setBlockNumGte(blocknum); + + int confirm = needConfirmed(onlyConfirmed, onlyUnconfirmed); + if (confirm == CONFILICTING_PARAMETERS) { + return new Response(false, "Conflicting parameters passed.").toJSONObject(); + } + if (confirm == RETURN_ONLY_CONFIRMED_EVENTS) { + query.setBlockNumLte(latestSolidifiedBlockNumber.get()); + } else if (confirm == RETURN_ONLY_UNCONFIRMED_EVENTS) { + query.setBlockNumGt(latestSolidifiedBlockNumber.get()); } + query.setContractAddress(contractAddress); query.setTimestampGreaterEqual(timestamp); query.setPageniate(this.setPagniateVariable(limit, sort, start)); @@ -395,16 +402,17 @@ public List findEventsByContractAddressTronGrid ( // get event list @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}/{eventName}") - public List findEventsByContractAddressAndEventNameTronGrid ( + public Object findEventsByContractAddressAndEventNameTronGrid ( @PathVariable String contractAddress, @PathVariable String eventName, @RequestParam(value = "size", required = false, defaultValue = "20") int limit, @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, @RequestParam(value = "start", required = false, defaultValue = "0") int start, - @RequestParam(value = "block", required = false, defaultValue = "-1") long blocknum, @RequestParam(value = "since", required = false, defaultValue = "0") long timestamp, @RequestParam(value = "fromTimestamp", required = false, defaultValue = "0") long fromTimestamp, - @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint + @RequestParam(value = "fingerprint", required = false, defaultValue = "") String fingerprint, + @RequestParam(value = "onlyConfirmed", required = false, defaultValue = "") String onlyConfirmed, + @RequestParam(value = "onlyUnconfirmed", required = false, defaultValue = "") String onlyUnconfirmed ) { if (sort.contains("block_timestamp")) { sort = sort.replace("block_timestamp", "timeStamp"); @@ -417,10 +425,18 @@ public List findEventsByContractAddressAndEventNameTronGrid ( start = Crypto.decrypt(fingerprint) > 0 ? Crypto.decrypt(fingerprint) : 0; } + QueryFactory query = new QueryFactory(); - if (blocknum != -1) { - query.setBlockNumGte(blocknum); + int confirm = needConfirmed(onlyConfirmed, onlyUnconfirmed); + if (confirm == CONFILICTING_PARAMETERS) { + return new Response(false, "Conflicting parameters passed.").toJSONObject(); + } + if (confirm == RETURN_ONLY_CONFIRMED_EVENTS) { + query.setBlockNumLte(latestSolidifiedBlockNumber.get()); + } else if (confirm == RETURN_ONLY_UNCONFIRMED_EVENTS) { + query.setBlockNumGt(latestSolidifiedBlockNumber.get()); } + query.setContractAddress(contractAddress); query.setEventName(eventName); @@ -479,10 +495,12 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr QueryFactory query = new QueryFactory(); if (blockNumber.equalsIgnoreCase("latest")) { - query.setBlockNum(latestSolidifiedBlockNumber.get()); + query.setBlockNumGte(latestSolidifiedBlockNumber.get()); } else { query.setBlockNum(Long.parseLong(blockNumber)); } + + query.setContractAddress(contractAddress); query.setEventName(eventName); query.setTimestampGreaterEqual(timestamp); @@ -593,12 +611,19 @@ public void init() { rePushThread.start(); } -// int needConfirmed(String onlyConfirmed, String onlyUnconfirmed) { -// if (onlyConfirmed.length() == 0 && onlyUnconfirmed.length() == 0) { -// return -1; -// } -// if (onlyConfirmed.length() != 0 && onlyUnconfirmed.length() != 0) { -// -// } -// } + int needConfirmed(String onlyConfirmed, String onlyUnconfirmed) { + if (onlyConfirmed.length() == 0 && onlyUnconfirmed.length() == 0) { + return RETURN_ALL_EVENTS; + } + if (onlyConfirmed.length() != 0 && onlyUnconfirmed.length() != 0) { + return CONFILICTING_PARAMETERS; + } + if (onlyConfirmed.length() != 0) { + return Boolean.getBoolean(onlyConfirmed)? RETURN_ONLY_CONFIRMED_EVENTS : RETURN_ONLY_UNCONFIRMED_EVENTS; + } + if (onlyUnconfirmed.length() != 0) { + return Boolean.getBoolean(onlyUnconfirmed)? RETURN_ONLY_UNCONFIRMED_EVENTS : RETURN_ONLY_CONFIRMED_EVENTS; + } + return RETURN_ALL_EVENTS; + } } diff --git a/src/main/java/org/tron/trongeventquery/query/QueryFactory.java b/src/main/java/org/tron/trongeventquery/query/QueryFactory.java index 2a69846..43d8945 100644 --- a/src/main/java/org/tron/trongeventquery/query/QueryFactory.java +++ b/src/main/java/org/tron/trongeventquery/query/QueryFactory.java @@ -122,7 +122,11 @@ public void setBlockNumGte(long block) { this.query.addCriteria(Criteria.where("blockNumber").gte(block)); } - public void setBlockNumSmall(long block) { + public void setBlockNumGt(long block) { + this.query.addCriteria(Criteria.where("blockNumber").gt(block)); + } + + public void setBlockNumLte(long block) { this.query.addCriteria(Criteria.where("blockNumber").lte(block)); } diff --git a/src/main/java/org/tron/trongeventquery/response/Response.java b/src/main/java/org/tron/trongeventquery/response/Response.java new file mode 100644 index 0000000..d32f146 --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/response/Response.java @@ -0,0 +1,19 @@ +package org.tron.trongeventquery.response; + +import com.alibaba.fastjson.JSONObject; + + +public class Response { + public Response(boolean result, String msg) { + jsonObject = new JSONObject(); + jsonObject.put("success", result); + jsonObject.put("error", msg); + } + + public JSONObject toJSONObject() { + return jsonObject; + } + + private JSONObject jsonObject; + +} \ No newline at end of file From 953d558d86d33b7327ea812cef7362f4bc068d7a Mon Sep 17 00:00:00 2001 From: wubinTron Date: Thu, 16 Jan 2020 15:02:15 +0800 Subject: [PATCH 16/42] add solidity comfirm --- .../contractevents/ContractEventController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 7df5c63..e87dd8d 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -468,6 +468,11 @@ public Object findEventsByContractAddressAndEventNameTronGrid ( return array; } + @RequestMapping(method = RequestMethod.GET, value = "/event/contract/latestSolidifiedBlockNum") + public Object findLatestSolidifiedBlockNum() { + return latestSolidifiedBlockNumber.get(); + } + // get event list @RequestMapping(method = RequestMethod.GET, value = "/event/contract/{contractAddress}/{eventName}/{blockNumber}") public List findEventsByContractAddressAndEventNameAndBlockNumTronGrid ( From d7ef2431c56a52d80e495ee82f223648c79d6431 Mon Sep 17 00:00:00 2001 From: TracyHesiCecil Date: Fri, 17 Jan 2020 14:25:51 +0800 Subject: [PATCH 17/42] fix bug --- .../contractevents/ContractEventController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index e87dd8d..1867ccf 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -320,7 +320,7 @@ public List findOneByTransactionTronGri (@PathVariable String transa for (ContractEventTriggerEntity p : queryResult) { Map map = new HashMap(); map.put("transaction_id", p.getTransactionId()); - map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_timestamp", p.getTimeStamp()); map.put("block_number", p.getBlockNumber()); map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); @@ -382,7 +382,7 @@ public Object findEventsByContractAddressTronGrid ( for (ContractEventTriggerEntity p : result) { Map map = new HashMap(); map.put("transaction_id", p.getTransactionId()); - map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_timestamp", p.getTimeStamp()); map.put("block_number", p.getBlockNumber()); map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); @@ -450,7 +450,7 @@ public Object findEventsByContractAddressAndEventNameTronGrid ( for (ContractEventTriggerEntity p : result) { Map map = new HashMap(); map.put("transaction_id", p.getTransactionId()); - map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_timestamp", p.getTimeStamp()); map.put("block_number", p.getBlockNumber()); map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); @@ -518,7 +518,7 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr for (ContractEventTriggerEntity p : result) { Map map = new HashMap(); map.put("transaction_id", p.getTransactionId()); - map.put("block_timestamp", String.valueOf(p.getTimeStamp())); + map.put("block_timestamp", p.getTimeStamp()); map.put("block_number", p.getBlockNumber()); map.put("result_type", getResultType(p.getEventSignatureFull(), p.getEventName())); map.put("result", getResult(p.getEventSignatureFull(), p.getEventName(), p.getTopicMap(), p.getDataMap())); From 908ea98d0248a61b33ab649282367baf4488579d Mon Sep 17 00:00:00 2001 From: TracyHesiCecil Date: Fri, 17 Jan 2020 14:31:55 +0800 Subject: [PATCH 18/42] fix following comment --- .../contractevents/ContractEventController.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 1867ccf..63e068b 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -536,7 +536,7 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr return array; } - List getResultType(String fullName, String eventSignature) { + JSONObject getResultType(String fullName, String eventSignature) { int num = eventSignature.length(); String newSignature = fullName.substring(num + 1, fullName.length() - 1); String[] arrayList = Strings.split(newSignature, ','); @@ -546,11 +546,10 @@ List getResultType(String fullName, String eventSignature) { String[] type = str.split(" "); map.put(type[1], type[0]); } - array.add(new JSONObject(map)); - return array; + return new JSONObject(map); } - List getResult(String fullName, String eventSignature, Map topMap, Map dataMap) { + JSONObject getResult(String fullName, String eventSignature, Map topMap, Map dataMap) { int num = eventSignature.length(); String newSignature = fullName.substring(num + 1, fullName.length() - 1); String[] arrayList = Strings.split(newSignature, ','); @@ -581,8 +580,7 @@ List getResult(String fullName, String eventSignature, Map Date: Fri, 17 Jan 2020 18:52:01 +0800 Subject: [PATCH 19/42] add solidity confirm --- .../ContractEventController.java | 9 ++-- .../solidityevents/SolidityTriggerEntity.java | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/tron/trongeventquery/solidityevents/SolidityTriggerEntity.java diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 63e068b..bb4c2b9 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -31,6 +31,7 @@ import org.tron.common.utils.ByteArray; import org.tron.trongeventquery.query.QueryFactory; import org.tron.trongeventquery.response.Response; +import org.tron.trongeventquery.solidityevents.SolidityTriggerEntity; @RestController @Component @@ -594,13 +595,13 @@ int getIndex(String unique) { try { QueryFactory query = new QueryFactory(); query.setPageniate(QueryFactory.setPagniateVariable(0, 1, "-latestSolidifiedBlockNumber")); - List contractEventTriggerEntityList + List solidityTriggerEntityList = mongoTemplate.find(query.getQuery(), - ContractEventTriggerEntity.class); - if (contractEventTriggerEntityList.isEmpty()) { + SolidityTriggerEntity.class); + if (solidityTriggerEntityList.isEmpty()) { return; } - latestSolidifiedBlockNumber.set(contractEventTriggerEntityList.get(0).getLatestSolidifiedBlockNumber()); + latestSolidifiedBlockNumber.set(solidityTriggerEntityList.get(0).getLatestSolidifiedBlockNumber()); TimeUnit.MILLISECONDS.sleep(1000L); } catch (InterruptedException e) { LOG.error(e.getMessage()); diff --git a/src/main/java/org/tron/trongeventquery/solidityevents/SolidityTriggerEntity.java b/src/main/java/org/tron/trongeventquery/solidityevents/SolidityTriggerEntity.java new file mode 100644 index 0000000..d64e58a --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/solidityevents/SolidityTriggerEntity.java @@ -0,0 +1,42 @@ +package org.tron.trongeventquery.solidityevents; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +@Document(collection = "solidity") +public class SolidityTriggerEntity implements Serializable { + + private static final long serialVersionUID = -70777625567836430L; + + @Id + private String id; + + @Field(value = "latestSolidifiedBlockNumber") + @JsonProperty(value = "latestSolidifiedBlockNumber") + private long latestSolidifiedBlockNumber; + + @Field(value = "timeStamp") + @JsonProperty(value = "timeStamp") + private long timeStamp; + + @Field(value = "triggerName") + @JsonProperty(value = "triggerName") + private String triggerName; + + public long getLatestSolidifiedBlockNumber() { + return latestSolidifiedBlockNumber; + } + + public SolidityTriggerEntity(Long timeStamp, + String triggerName, long latestSolidifiedBlockNumber) { + this.timeStamp = timeStamp; + this.triggerName = triggerName; + this.latestSolidifiedBlockNumber = latestSolidifiedBlockNumber; + } +} From 33e17dd40c2df2688cd75862fac0240d82081b73 Mon Sep 17 00:00:00 2001 From: wubinTron Date: Mon, 3 Feb 2020 15:17:35 +0800 Subject: [PATCH 20/42] merge develop --- .../contractevents/ContractEventController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index bb4c2b9..c94757e 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -329,6 +329,9 @@ public List findOneByTransactionTronGri (@PathVariable String transa map.put("event_name", p.getEventName()); map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); + if (p.getBlockNumber() > latestSolidifiedBlockNumber.get()) { + map.put("_unconfirmed", true); + } array.add(new JSONObject(map)); } @@ -391,6 +394,9 @@ public Object findEventsByContractAddressTronGrid ( map.put("event_name", p.getEventName()); map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); + if (p.getBlockNumber() > latestSolidifiedBlockNumber.get()) { + map.put("_unconfirmed", true); + } if (count++ == result.size()) { map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); @@ -459,6 +465,9 @@ public Object findEventsByContractAddressAndEventNameTronGrid ( map.put("event_name", p.getEventName()); map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); + if (p.getBlockNumber() > latestSolidifiedBlockNumber.get()) { + map.put("_unconfirmed", true); + } if (count++ == result.size()) { map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); @@ -527,6 +536,9 @@ public List findEventsByContractAddressAndEventNameAndBlockNumTronGr map.put("event_name", p.getEventName()); map.put("contract_address", p.getContractAddress()); map.put("caller_contract_address", p.getOriginAddress()); + if (p.getBlockNumber() > latestSolidifiedBlockNumber.get()) { + map.put("_unconfirmed", true); + } if (count++ == result.size()) { map.put("_fingerprint", Crypto.encrypt(String.format("%d", start + 1))); From 1b2a7da8d50514e7906d817d964452fc5053f68a Mon Sep 17 00:00:00 2001 From: geb789 Date: Tue, 4 Feb 2020 17:18:47 +0800 Subject: [PATCH 21/42] remove db config file --- config.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.conf b/config.conf index f90c3fc..45347b5 100644 --- a/config.conf +++ b/config.conf @@ -1,5 +1,5 @@ -mongo.host=47.90.245.68 -mongo.port=27017 +mongo.host=47.91.17.89 +mongo.port=18883 mongo.dbname=eventlog mongo.username=tron mongo.password=123456 From 0a24db0583ac0167ed4052448a4cd1109a1039d5 Mon Sep 17 00:00:00 2001 From: wubinTron Date: Wed, 5 Feb 2020 16:45:24 +0800 Subject: [PATCH 22/42] fix check style problem --- .../contractevents/ContractEventController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index c94757e..7d4f9a7 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -635,10 +635,10 @@ int needConfirmed(String onlyConfirmed, String onlyUnconfirmed) { return CONFILICTING_PARAMETERS; } if (onlyConfirmed.length() != 0) { - return Boolean.getBoolean(onlyConfirmed)? RETURN_ONLY_CONFIRMED_EVENTS : RETURN_ONLY_UNCONFIRMED_EVENTS; + return Boolean.parseBoolean(onlyConfirmed)? RETURN_ONLY_CONFIRMED_EVENTS : RETURN_ONLY_UNCONFIRMED_EVENTS; } if (onlyUnconfirmed.length() != 0) { - return Boolean.getBoolean(onlyUnconfirmed)? RETURN_ONLY_UNCONFIRMED_EVENTS : RETURN_ONLY_CONFIRMED_EVENTS; + return Boolean.parseBoolean(onlyUnconfirmed)? RETURN_ONLY_UNCONFIRMED_EVENTS : RETURN_ONLY_CONFIRMED_EVENTS; } return RETURN_ALL_EVENTS; } From 22eabfea7a4c457388a74537f070c9f1dc267dc7 Mon Sep 17 00:00:00 2001 From: M-blockcoder Date: Thu, 13 Feb 2020 00:02:31 +0800 Subject: [PATCH 23/42] remove duplicate function --- .../contractevents/ContractEventTriggerEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventTriggerEntity.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventTriggerEntity.java index 260c1bd..1e50510 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventTriggerEntity.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventTriggerEntity.java @@ -132,5 +132,4 @@ public ContractEventTriggerEntity(String eventSignature, Map top this.rawData = rawData; this.abiString = abiString; } - } From f39b4c2cbd0ab5fefcc4173e2078709f3746502f Mon Sep 17 00:00:00 2001 From: wubinTron Date: Thu, 13 Feb 2020 00:03:20 +0800 Subject: [PATCH 24/42] remove duplicate function --- .../trongeventquery/contractevents/ContractEventController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java index 7d4f9a7..89521f9 100644 --- a/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java +++ b/src/main/java/org/tron/trongeventquery/contractevents/ContractEventController.java @@ -62,7 +62,6 @@ public List events( @RequestParam(value = "sort", required = false, defaultValue = "-timeStamp") String sort, @RequestParam(value = "start", required = false, defaultValue = "0") int start ) { - QueryFactory query = new QueryFactory(); if (blocknum != -1) { query.setBlockNumGte(blocknum); From b3fc3a34108fb647b1c3bbcdae7b474d15f2d70a Mon Sep 17 00:00:00 2001 From: wubinTron <44354524+wubinTron@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:35:30 +0800 Subject: [PATCH 25/42] Update config.conf --- config.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.conf b/config.conf index 45347b5..af5ca14 100644 --- a/config.conf +++ b/config.conf @@ -1,4 +1,4 @@ -mongo.host=47.91.17.89 +mongo.host=127.0.0.1 mongo.port=18883 mongo.dbname=eventlog mongo.username=tron From a0331b2588073aa520c700c8431072113f91d7e1 Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 20 Feb 2020 14:54:36 +0800 Subject: [PATCH 26/42] add Filter and interceptor --- .../trongeventquery/TronEventApplication.java | 2 + .../trongeventquery/filter/CommonFilter.java | 110 ++++++++++++++++++ .../filter/CommonInterceptor.java | 36 ++++++ .../filter/CommonWebAppConfigurer.java | 23 ++++ 4 files changed, 171 insertions(+) create mode 100644 src/main/java/org/tron/trongeventquery/filter/CommonFilter.java create mode 100644 src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java create mode 100644 src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 815ed7e..7d2d9df 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -18,6 +18,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; @@ -26,6 +27,7 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; +@ServletComponentScan("org.tron.trongeventquery.filter") //扫描Filter @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) @PropertySource(value = {"file:./config.conf"}, ignoreResourceNotFound = true) public class TronEventApplication { diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java new file mode 100644 index 0000000..98f1bf5 --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java @@ -0,0 +1,110 @@ +package org.tron.trongeventquery.filter; + + +import com.alibaba.fastjson.JSONObject; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; + +@WebFilter(urlPatterns = "/*") +public class CommonFilter implements Filter { + + + public static String TOTAL_REQUST = "TOTAL_REQUEST"; + public static String FAIL_REQUST = "FAIL_REQUEST"; + public static String OK_REQUST = "OK_REQUEST"; + private static int totalCount = 0; + private static int failCount = 0; + private static int okCount=0; + private static int interval = 1; // 1 minute interval + private static HashMap EndpointCount = new HashMap(); + public String END_POINT = "END_POINT"; + public String uri = ""; + public long gapMilliseconds = interval * 60 * 1000; + private long preciousTime = 0; + + public int getTotalCount() { + return this.totalCount; + } + + public int getInterval() { + return this.interval; + } + + public int getFailCount() { + return this.failCount; + } + + public int getOkCount() { return this.okCount; } + + public HashMap getEndpointMap() { + return this.EndpointCount; + } + + public CommonFilter getInstance() { return this; } + + @Override public void init(FilterConfig filterConfig) throws ServletException { + // code here + preciousTime = System.currentTimeMillis(); + } + + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { +// System.out.println("--------------doFilter start--------------"); + long currentTime = System.currentTimeMillis(); + if (currentTime - preciousTime > gapMilliseconds) { //reset every 1 minutes + totalCount = 0; + failCount = 0; + okCount=0; + preciousTime = currentTime; + EndpointCount.clear(); + } + + if (request instanceof HttpServletRequest) { + String endpoint = ((HttpServletRequest) request).getRequestURI(); + JSONObject obj = new JSONObject(); + if (EndpointCount.containsKey(endpoint)) { + obj = EndpointCount.get(endpoint); + } else { + obj.put(TOTAL_REQUST, 0); + obj.put(FAIL_REQUST, 0); + obj.put(OK_REQUST, 0); + obj.put(END_POINT, endpoint); + } + obj.put(TOTAL_REQUST, (int) obj.get(TOTAL_REQUST) + 1); + totalCount++; + System.out.println("--response:"+response); + try { + chain.doFilter(request, response); + HttpServletResponse resp = (HttpServletResponse) response; + System.out.println("--status:"+resp.getStatus()); + System.out.println("--response:"+response); + if (resp.getStatus() != 200) { + failCount++; + obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); + } + } catch (Exception e) { + failCount++; + obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); + throw e; + } + // update map + EndpointCount.put(endpoint, obj); + } else { + chain.doFilter(request, response); + } +// System.out.println("TOTAL_REQUST:"+ totalCount); +// System.out.println("FAIL_REQUST:"+failCount); +// System.out.println("--------------doFilter stop--------------"); + } + + @Override + public void destroy() { + } +} \ No newline at end of file diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java b/src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java new file mode 100644 index 0000000..8acf33a --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java @@ -0,0 +1,36 @@ +package org.tron.trongeventquery.filter; + +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CommonInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + + System.out.println(">>>CommonInterceptor>>>>>>>在请求处理之前进行调用"); + + return true;// 只有返回true才会继续向下执行,返回false取消当前请求 + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, + Object handler, ModelAndView modelAndView) throws Exception { + + System.out.println(">>>CommonInterceptor>>>>>>>请求处理之后进行调用"); + + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, + Object handler, Exception ex) throws Exception { + + System.out.println(">>>CommonInterceptor>>>>>>>在整个请求结束之后被调用"); + + } + +} \ No newline at end of file diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java b/src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java new file mode 100644 index 0000000..b2cf087 --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java @@ -0,0 +1,23 @@ +package org.tron.trongeventquery.filter; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class CommonWebAppConfigurer implements WebMvcConfigurer { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + // 多个拦截器组成一个拦截器链 + InterceptorRegistration r1 = registry.addInterceptor(new CommonInterceptor()); + + // addPathPatterns 添加拦截 + r1.addPathPatterns("/*"); + + // excludePathPatterns 排除拦截 +// r1.excludePathPatterns("/login"); + + } +} From 564e96a42d65cd580df3278d242e096737209b4f Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 20 Feb 2020 14:56:28 +0800 Subject: [PATCH 27/42] delete interceptor --- .../trongeventquery/TronEventApplication.java | 2 +- .../filter/CommonInterceptor.java | 36 ------------------- .../filter/CommonWebAppConfigurer.java | 23 ------------ 3 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java delete mode 100644 src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 7d2d9df..5e5ef9a 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -27,7 +27,7 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; -@ServletComponentScan("org.tron.trongeventquery.filter") //扫描Filter +@ServletComponentScan("org.tron.trongeventquery.filter") //Scan Filter @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) @PropertySource(value = {"file:./config.conf"}, ignoreResourceNotFound = true) public class TronEventApplication { diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java b/src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java deleted file mode 100644 index 8acf33a..0000000 --- a/src/main/java/org/tron/trongeventquery/filter/CommonInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.tron.trongeventquery.filter; - -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class CommonInterceptor implements HandlerInterceptor { - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, - Object handler) throws Exception { - - System.out.println(">>>CommonInterceptor>>>>>>>在请求处理之前进行调用"); - - return true;// 只有返回true才会继续向下执行,返回false取消当前请求 - } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, - Object handler, ModelAndView modelAndView) throws Exception { - - System.out.println(">>>CommonInterceptor>>>>>>>请求处理之后进行调用"); - - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) throws Exception { - - System.out.println(">>>CommonInterceptor>>>>>>>在整个请求结束之后被调用"); - - } - -} \ No newline at end of file diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java b/src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java deleted file mode 100644 index b2cf087..0000000 --- a/src/main/java/org/tron/trongeventquery/filter/CommonWebAppConfigurer.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.tron.trongeventquery.filter; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class CommonWebAppConfigurer implements WebMvcConfigurer { - - @Override - public void addInterceptors(InterceptorRegistry registry) { - // 多个拦截器组成一个拦截器链 - InterceptorRegistration r1 = registry.addInterceptor(new CommonInterceptor()); - - // addPathPatterns 添加拦截 - r1.addPathPatterns("/*"); - - // excludePathPatterns 排除拦截 -// r1.excludePathPatterns("/login"); - - } -} From 8d83b2b1d33ce59ba783718b73ebd66fcf0a49c8 Mon Sep 17 00:00:00 2001 From: alberto Date: Thu, 20 Feb 2020 17:42:20 +0800 Subject: [PATCH 28/42] add controller service --- config.conf | 2 +- .../trongeventquery/TronEventApplication.java | 3 +- .../trongeventquery/filter/CommonFilter.java | 7 +- .../monitor/MonitorController.java | 28 + .../trongeventquery/monitor/MonitorInfo.java | 776 ++++++++++++++++++ .../monitor/MonitorService.java | 57 ++ 6 files changed, 867 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/tron/trongeventquery/monitor/MonitorController.java create mode 100644 src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java create mode 100644 src/main/java/org/tron/trongeventquery/monitor/MonitorService.java diff --git a/config.conf b/config.conf index af5ca14..45347b5 100644 --- a/config.conf +++ b/config.conf @@ -1,4 +1,4 @@ -mongo.host=127.0.0.1 +mongo.host=47.91.17.89 mongo.port=18883 mongo.dbname=eventlog mongo.username=tron diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 5e5ef9a..4138c3a 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -27,8 +27,9 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; -@ServletComponentScan("org.tron.trongeventquery.filter") //Scan Filter + @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) +@ServletComponentScan("org.tron.trongeventquery.filter") //Scan Filter @PropertySource(value = {"file:./config.conf"}, ignoreResourceNotFound = true) public class TronEventApplication { diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java index 98f1bf5..63abe28 100644 --- a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java +++ b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java @@ -20,10 +20,9 @@ public class CommonFilter implements Filter { private static int totalCount = 0; private static int failCount = 0; private static int okCount=0; - private static int interval = 1; // 1 minute interval + private static int interval = 1440; // 24 hour private static HashMap EndpointCount = new HashMap(); public String END_POINT = "END_POINT"; - public String uri = ""; public long gapMilliseconds = interval * 60 * 1000; private long preciousTime = 0; @@ -83,8 +82,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha try { chain.doFilter(request, response); HttpServletResponse resp = (HttpServletResponse) response; - System.out.println("--status:"+resp.getStatus()); - System.out.println("--response:"+response); +// System.out.println("--status:"+resp.getStatus()); +// System.out.println("--response:"+response); if (resp.getStatus() != 200) { failCount++; obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorController.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorController.java new file mode 100644 index 0000000..fceed54 --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorController.java @@ -0,0 +1,28 @@ +package org.tron.trongeventquery.monitor; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MonitorController { + + @Autowired + MonitorService monitorService; + + @RequestMapping(method = RequestMethod.GET, value = "/monitor") + public String getMonitor(){ + + MonitorInfo monitorInfo = monitorService.getMonitorInfo(); + String monitorInfoString = JSON.toJSONString(monitorInfo); +// Object parse = JSONObject.parse(monitorInfoString); + return monitorInfoString; + } +} diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java new file mode 100644 index 0000000..f61dba7 --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java @@ -0,0 +1,776 @@ +package org.tron.trongeventquery.monitor; + + +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class MonitorInfo { + private int status; + private String msg; + private DataInfo data; + + public int getStatus() { + return this.status; + } + + public MonitorInfo setStatus(int status) { + this.status = status; + return this; + } + + public String getMsg() { + return this.msg; + } + + public MonitorInfo setMsg(String msg) { + this.msg = msg; + return this; + } + + public DataInfo getDataInfo() { + return this.data; + } + + public MonitorInfo setDataInfo(DataInfo data) { + this.data = data; + return this; + } + +// public MonitorInfo ToProtoEntity() { +// Protocol.MonitorInfo.Builder builder = Protocol.MonitorInfo.newBuilder(); +// builder.setStatus(getStatus()); +// builder.setMsg(getMsg()); +// Protocol.MonitorInfo.DataInfo.Builder dataInfo = Protocol.MonitorInfo.DataInfo.newBuilder(); +// DataInfo data = getDataInfo(); +// dataInfo.setInterval(data.getInterval()); +// +// Protocol.MonitorInfo.DataInfo.NodeInfo.Builder nodeInfo = +// Protocol.MonitorInfo.DataInfo.NodeInfo.newBuilder(); +// DataInfo.NodeInfo node = data.getNodeInfo(); +// nodeInfo.setIp(node.getIp()); +// nodeInfo.setType(node.getType()); +// nodeInfo.setStatus(node.getType()); +// nodeInfo.setVersion(node.getVersion()); +// nodeInfo.setNoUpgradedSRCount(node.getNoUpgradedSRCount()); +// +// for (DataInfo.NodeInfo.NoUpgradedSR noUpgradedSR : node.getNoUpgradedSRList()) { +// Protocol.MonitorInfo.DataInfo.NodeInfo.NoUpgradedSR.Builder noUpgradeSRProto = +// Protocol.MonitorInfo.DataInfo.NodeInfo.NoUpgradedSR.newBuilder(); +// noUpgradeSRProto.setAddress(noUpgradedSR.getAddress()); +// noUpgradeSRProto.setUrl(noUpgradedSR.getUrl()); +// nodeInfo.addNoUpgradedSRList(noUpgradeSRProto.build()); +// } +// // set node info +// dataInfo.setNode(nodeInfo.build()); +// +// Protocol.MonitorInfo.DataInfo.BlockChainInfo.Builder blockChain = +// Protocol.MonitorInfo.DataInfo.BlockChainInfo.newBuilder(); +// DataInfo.BlochainInfo BlockChain = data.getBlockchainInfo(); +// blockChain.setHeadBlockTimestamp(BlockChain.getHeadBlockTimestamp()); +// blockChain.setHeadBlockHash(BlockChain.getHeadBlockHash()); +// blockChain.setBlockProcessTime(BlockChain.getBlockProcessTime()); +// blockChain.setForkCount(BlockChain.getForkCount()); +// blockChain.setHeadBlockNum(BlockChain.getHeadBlockNum()); +// blockChain.setTxCacheSize(BlockChain.getTxCacheSize()); +// blockChain.setMissedTxCount(BlockChain.getMissTxCount()); +// +// Protocol.MonitorInfo.DataInfo.BlockChainInfo.TPSInfo.Builder tpsInfo = +// Protocol.MonitorInfo.DataInfo.BlockChainInfo.TPSInfo.newBuilder(); +// DataInfo.BlochainInfo.TPSInfo TpsInfo = BlockChain.getTPS(); +// tpsInfo.setMeanRate(TpsInfo.getMeanRate()); +// tpsInfo.setOneMinuteRate(TpsInfo.getOneMinuteRate()); +// tpsInfo.setFiveMinuteRate(TpsInfo.getFiveMinuteRate()); +// tpsInfo.setFifteenMinuteRate(TpsInfo.getFifteenMinuteRate()); +// blockChain.setTPS(tpsInfo.build()); +// // set blockchain info +// dataInfo.setBlockchain(blockChain.build()); +// +// +// Protocol.MonitorInfo.DataInfo.NetInfo.Builder netInfo = +// Protocol.MonitorInfo.DataInfo.NetInfo.newBuilder(); +// DataInfo.NetInfo NetInfo = data.getNetInfo(); +// netInfo.setConnectionCount(NetInfo.getConnectionCount()); +// netInfo.setValidConnectionCount(NetInfo.getValidConnectionCount()); +// netInfo.setErrorProtoCount(NetInfo.getErrorProtoCount()); +// netInfo.setTCPInTraffic(NetInfo.getTCPInTraffic()); +// netInfo.setTCPOutTraffic(NetInfo.getTCPOutTraffic()); +// netInfo.setDisconnectionCount(NetInfo.getDisconnectionCount()); +// netInfo.setUDPInTraffic(NetInfo.getUDPInTraffic()); +// netInfo.setUDPOutTraffic(NetInfo.getUDPOutTraffic()); +// +// Protocol.MonitorInfo.DataInfo.NetInfo.ApiInfo.Builder apiInfo = +// Protocol.MonitorInfo.DataInfo.NetInfo.ApiInfo.newBuilder(); +// apiInfo.setTotalCount(NetInfo.getApi().getTotalCount()); +// apiInfo.setTotalFailCount(NetInfo.getApi().getTotalFailCount()); +// for (DataInfo.NetInfo.ApiInfo.ApiDetailInfo ApiDetail : NetInfo.getApi().getApiDetailInfo()) { +// Protocol.MonitorInfo.DataInfo.NetInfo.ApiInfo.ApiDetailInfo.Builder apiDetail = +// Protocol.MonitorInfo.DataInfo.NetInfo.ApiInfo.ApiDetailInfo.newBuilder(); +// apiDetail.setName(ApiDetail.getName()); +// apiDetail.setCount(ApiDetail.getCount()); +// apiDetail.setFailCount(ApiDetail.getFailCount()); +// apiInfo.addDetail(apiDetail.build()); +// } +// netInfo.setApi(apiInfo.build()); +// +// +// for (DataInfo.NetInfo.DisconnectionDetailInfo DisconnectionDetail : NetInfo +// .getDisconnectionDetail()) { +// Protocol.MonitorInfo.DataInfo.NetInfo.DisconnectionDetailInfo.Builder disconnectionDetail = +// Protocol.MonitorInfo.DataInfo.NetInfo.DisconnectionDetailInfo.newBuilder(); +// disconnectionDetail.setReason(DisconnectionDetail.getReason()); +// disconnectionDetail.setCount(DisconnectionDetail.getCount()); +// netInfo.addDisconnectionDetail(disconnectionDetail.build()); +// } +// +// Protocol.MonitorInfo.DataInfo.NetInfo.LatencyInfo.Builder latencyInfo = +// Protocol.MonitorInfo.DataInfo.NetInfo.LatencyInfo.newBuilder(); +// latencyInfo.setDelay1S(NetInfo.getLatency().getDelay1S()); +// latencyInfo.setDelay2S(NetInfo.getLatency().getDelay2S()); +// latencyInfo.setDelay3S(NetInfo.getLatency().getDelay3S()); +// latencyInfo.setTop99(NetInfo.getLatency().getTop99()); +// latencyInfo.setTop95(NetInfo.getLatency().getTop95()); +// latencyInfo.setTotalCount(NetInfo.getLatency().getTotalCount()); +// +// for (DataInfo.NetInfo.LatencyInfo.LatencyDetailInfo LatencyDetailInfo : NetInfo.getLatency() +// .getLatencyDetailInfo()) { +// Protocol.MonitorInfo.DataInfo.NetInfo.LatencyInfo.LatencyDetailInfo.Builder latencyDetail = +// Protocol.MonitorInfo.DataInfo.NetInfo.LatencyInfo.LatencyDetailInfo.newBuilder(); +// latencyDetail.setCount(LatencyDetailInfo.getCount()); +// latencyDetail.setWitness(LatencyDetailInfo.getWitness()); +// latencyDetail.setTop99(LatencyDetailInfo.getTop99()); +// latencyDetail.setTop95(LatencyDetailInfo.getTop95()); +// latencyDetail.setDelay1S(LatencyDetailInfo.getDelay1S()); +// latencyDetail.setDelay2S(LatencyDetailInfo.getDelay2S()); +// latencyDetail.setDelay3S(LatencyDetailInfo.getDelay3S()); +// latencyInfo.addDetail(latencyDetail.build()); +// } +// +// // set latency info +// netInfo.setLatency(latencyInfo.build()); +// // set net info +// dataInfo.setNet(netInfo.build()); +// // set data info +// builder.setData(dataInfo.build()); +// return builder.build(); +// } + + + public static class DataInfo { + private int interval; + private NodeInfo node; + private BlochainInfo blockchain; + private NetInfo net; + + public int getInterval() { + return this.interval; + } + + public DataInfo setInterval(int interval) { + this.interval = interval; + return this; + } + + public NodeInfo getNodeInfo() { + return this.node; + } + + public DataInfo setNodeInfo(NodeInfo node) { + this.node = node; + return this; + } + + public DataInfo setBlockInfo(BlochainInfo blockchain) { + this.blockchain = blockchain; + return this; + } + + public BlochainInfo getBlockchainInfo() { + return this.blockchain; + } + + public NetInfo getNetInfo() { + return this.net; + } + + public DataInfo setNetInfo(NetInfo net) { + this.net = net; + return this; + } + + // node monitor information + public static class NodeInfo { + private String ip; + private int Type; + private int status; + private String version; + private int noUpgradedSRCount; + private List noUpgradedSRList = new ArrayList<>(); + + public String getIp() { + return this.ip; + } + + public NodeInfo setIp(String ip) { + this.ip = ip; + return this; + } + + public int getType() { + return this.Type; + } + + public NodeInfo setType(int Type) { + this.Type = Type; + return this; + } + + public int getStatus() { + return this.status; + } + + public NodeInfo setStatus(int status) { + this.status = status; + return this; + } + + public String getVersion() { + return this.version; + } + + public NodeInfo setVersion(String version) { + this.version = version; + return this; + } + + public int getNoUpgradedSRCount() { + return this.noUpgradedSRCount; + } + + public NodeInfo setNoUpgradedSRCount(int noUpgradedSRCount) { + this.noUpgradedSRCount = noUpgradedSRCount; + return this; + } + + public List getNoUpgradedSRList() { + return this.noUpgradedSRList; + } + + public NodeInfo setNoUpgradedSRList(List noUpgradedSRList) { + this.noUpgradedSRList = noUpgradedSRList; + return this; + } + + public static class NoUpgradedSR { + private String address; + private String url; + + public String getAddress() { + return this.address; + } + + public NoUpgradedSR setAddress(String address) { + this.address = address; + return this; + } + + public String getUrl() { + return this.url; + } + + public NoUpgradedSR setUrl(String url) { + this.url = url; + return this; + } + } + + } + + // blockchain monitor information + public static class BlochainInfo { + private int headBlockNum; + private long headBlockTimestamp; + private String headBlockHash; + private int forkCount; + private int blockProcessTime; + private TPSInfo TPS; + private int TxCacheSize; + private int missTxCount; + + public int getHeadBlockNum() { + return this.headBlockNum; + } + + public BlochainInfo setHeadBlockNum(int headBlockNum) { + this.headBlockNum = headBlockNum; + return this; + } + + public long getHeadBlockTimestamp() { + return this.headBlockTimestamp; + } + + public BlochainInfo setHeadBlockTimestamp(long headBlockTimestamp) { + this.headBlockTimestamp = headBlockTimestamp; + return this; + } + + public String getHeadBlockHash() { + return this.headBlockHash; + } + + public BlochainInfo setHeadBlockHash(String headBlockHash) { + this.headBlockHash = headBlockHash; + return this; + } + + public int getForkCount() { + return this.forkCount; + } + + public BlochainInfo setForkCount(int forkCount) { + this.forkCount = forkCount; + return this; + } + + public int getBlockProcessTime() { + return this.blockProcessTime; + } + + public BlochainInfo setBlockProcessTime(int blockProcessTime) { + this.blockProcessTime = blockProcessTime; + return this; + } + + public TPSInfo getTPS() { + return this.TPS; + } + + public BlochainInfo setTPS(TPSInfo TPS) { + this.TPS = TPS; + return this; + } + + public int getTxCacheSize() { + return this.TxCacheSize; + } + + public BlochainInfo setTxCacheSize(int TxCacheSize) { + this.TxCacheSize = TxCacheSize; + return this; + } + + public int getMissTxCount() { + return this.missTxCount; + } + + public BlochainInfo setMissTxCount(int missTxCount) { + this.missTxCount = missTxCount; + return this; + } + + public static class TPSInfo { + private double meanRate; + private double oneMinuteRate; + private double fiveMinuteRate; + private double fifteenMinuteRate; + + public double getMeanRate() { + return this.meanRate; + } + + public TPSInfo setMeanRate(double meanRate) { + this.meanRate = meanRate; + return this; + } + + public double getOneMinuteRate() { + return this.oneMinuteRate; + } + + public TPSInfo setOneMinuteRate(double oneMinuteRate) { + this.oneMinuteRate = oneMinuteRate; + return this; + } + + public double getFiveMinuteRate() { + return this.fiveMinuteRate; + } + + public TPSInfo setFiveMinuteRate(double fiveMinuteRate) { + this.fiveMinuteRate = fiveMinuteRate; + return this; + } + + public double getFifteenMinuteRate() { + return this.fifteenMinuteRate; + } + + public TPSInfo setFifteenMinuteRate(double fifteenMinuteRate) { + this.fifteenMinuteRate = fifteenMinuteRate; + return this; + } + + } + } + + // network monitor information + public static class NetInfo { + private int errorProtoCount; + private ApiInfo api; + private int connectionCount; + private int validConnectionCount; + private long TCPInTraffic; + private long TCPOutTraffic; + private int disconnectionCount; + private List disconnectionDetail = new ArrayList<>(); + private long UDPInTraffic; + private long UDPOutTraffic; + private LatencyInfo latency; + + public int getErrorProtoCount() { + return this.errorProtoCount; + } + + public NetInfo setErrorProtoCount(int errorProtoCount) { + this.errorProtoCount = errorProtoCount; + return this; + } + + public ApiInfo getApi() { + return this.api; + } + + public NetInfo setApi(ApiInfo api) { + this.api = api; + return this; + } + + public int getConnectionCount() { + return this.connectionCount; + } + + public NetInfo setConnectionCount(int connectionCount) { + this.connectionCount = connectionCount; + return this; + } + + public int getValidConnectionCount() { + return this.validConnectionCount; + } + + public NetInfo setValidConnectionCount(int validConnectionCount) { + this.validConnectionCount = validConnectionCount; + return this; + } + + public long getTCPInTraffic() { + return this.TCPInTraffic; + } + + public NetInfo setTCPInTraffic(long TCPInTraffic) { + this.TCPInTraffic = TCPInTraffic; + return this; + } + + public long getTCPOutTraffic() { + return this.TCPOutTraffic; + } + + public NetInfo setTCPOutTraffic(long TCPOutTraffic) { + this.TCPOutTraffic = TCPOutTraffic; + return this; + } + + public int getDisconnectionCount() { + return this.disconnectionCount; + } + + public NetInfo setDisconnectionCount(int disconnectionCount) { + this.disconnectionCount = disconnectionCount; + return this; + } + + public List getDisconnectionDetail() { + return this.disconnectionDetail; + } + + public NetInfo setDisconnectionDetail(List disconnectionDetail) { + this.disconnectionDetail = disconnectionDetail; + return this; + } + + public long getUDPInTraffic() { + return this.UDPInTraffic; + } + + public NetInfo setUDPInTraffic(long UDPInTraffic) { + this.UDPInTraffic = UDPInTraffic; + return this; + } + + public long getUDPOutTraffic() { + return this.UDPOutTraffic; + } + + public NetInfo setUDPOutTraffic(long UDPOutTraffic) { + this.UDPOutTraffic = UDPOutTraffic; + return this; + } + + public LatencyInfo getLatency() { + return this.latency; + } + + public NetInfo setLatency(LatencyInfo latency) { + this.latency = latency; + return this; + } + + // API monitor information + public static class ApiInfo { + private int totalCount; + private int totalFailCount; + private List detail = new ArrayList<>(); + + public int getTotalCount() { + return this.totalCount; + } + + public ApiInfo setTotalCount(int totalCount) { + this.totalCount = totalCount; + return this; + } + + public int getTotalFailCount() { + return this.totalFailCount; + } + + public ApiInfo setTotalFailCount(int totalFailCount) { + this.totalFailCount = totalFailCount; + return this; + } + + public List getApiDetailInfo() { + return this.detail; + } + + public ApiInfo setApiDetailInfo(List detail) { + this.detail = detail; + return this; + } + + public static class ApiDetailInfo { + private String name; + private int count; + private int failCount; + + public String getName() { + return this.name; + } + + public ApiDetailInfo setName(String name) { + this.name = name; + return this; + } + + public int getCount() { + return this.count; + } + + public ApiDetailInfo setCount(int count) { + this.count = count; + return this; + } + + public int getFailCount() { + return this.failCount; + } + + public ApiDetailInfo setFailCount(int failCount) { + this.failCount = failCount; + return this; + } + } + } + + // disconnection monitor information + public static class DisconnectionDetailInfo { + private String reason; + private int count; + + public String getReason() { + return this.reason; + } + + public DisconnectionDetailInfo setReason(String reason) { + this.reason = reason; + return this; + } + + public int getCount() { + return this.count; + } + + public DisconnectionDetailInfo setCount(int count) { + this.count = count; + return this; + } + + } + + // latency monitor information + public static class LatencyInfo { + private int top99; + private int top95; + private int totalCount; + private int delay1S; + private int delay2S; + private int delay3S; + private List detail = new ArrayList<>(); + + public int getTop99() { + return this.top99; + } + + public LatencyInfo setTop99(int top99) { + this.top99 = top99; + return this; + } + + public int getTop95() { + return this.top95; + } + + public LatencyInfo setTop95(int top95) { + this.top95 = top95; + return this; + } + + public int getTotalCount() { + return this.totalCount; + } + + public LatencyInfo setTotalCount(int totalCount) { + this.totalCount = totalCount; + return this; + } + + public int getDelay1S() { + return this.delay1S; + } + + public LatencyInfo setDelay1S(int delay1S) { + this.delay1S = delay1S; + return this; + } + + public int getDelay2S() { + return this.delay2S; + } + + public LatencyInfo setDelay2S(int delay2S) { + this.delay2S = delay2S; + return this; + } + + public int getDelay3S() { + return this.delay3S; + } + + public LatencyInfo setDelay3S(int delay3S) { + this.delay3S = delay3S; + return this; + } + + public List getLatencyDetailInfo() { + return this.detail; + } + + public LatencyInfo setLatencyDetailInfo(List detail) { + this.detail = detail; + return this; + } + + public static class LatencyDetailInfo { + private String witness; + private int top99; + private int top95; + private int count; + private int delay1S; + private int delay2S; + private int delay3S; + + public String getWitness() { + return this.witness; + } + + public LatencyDetailInfo setWitness(String witness) { + this.witness = witness; + return this; + } + + public int getTop99() { + return this.top99; + } + + public LatencyDetailInfo setTop99(int top99) { + this.top99 = top99; + return this; + } + + public int getTop95() { + return this.top95; + } + + public LatencyDetailInfo setTop95(int top95) { + this.top95 = top95; + return this; + } + + public int getCount() { + return this.count; + } + + public LatencyDetailInfo setCount(int count) { + this.count = count; + return this; + } + + public int getDelay1S() { + return this.delay1S; + } + + public LatencyDetailInfo setDelay1S(int delay1S) { + this.delay1S = delay1S; + return this; + } + + public int getDelay2S() { + return this.delay2S; + } + + public LatencyDetailInfo setDelay2S(int delay2S) { + this.delay2S = delay2S; + return this; + } + + public int getDelay3S() { + return this.delay3S; + } + + public LatencyDetailInfo setDelay3S(int delay3S) { + this.delay3S = delay3S; + return this; + } + + } + } + + } + + + } +} diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java new file mode 100644 index 0000000..8dfeee5 --- /dev/null +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java @@ -0,0 +1,57 @@ +package org.tron.trongeventquery.monitor; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.tron.trongeventquery.filter.CommonFilter; + + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Slf4j(topic = "monitorService") +@Component +public class MonitorService { + +// @Autowired +// private MonitorMetric monitorMetric; + + public MonitorInfo getMonitorInfo() { + MonitorInfo monitorInfo = new MonitorInfo(); + monitorInfo.setStatus(1); + monitorInfo.setMsg("success"); + MonitorInfo.DataInfo data = new MonitorInfo.DataInfo(); + setNetInfo(data); + monitorInfo.setDataInfo(data); + +// return monitorInfo.ToProtoEntity(); + return monitorInfo; + } + + public void setNetInfo(MonitorInfo.DataInfo data) { + MonitorInfo.DataInfo.NetInfo netInfo = new MonitorInfo.DataInfo.NetInfo(); + + // set api request info + MonitorInfo.DataInfo.NetInfo.ApiInfo apiInfo = new MonitorInfo.DataInfo.NetInfo.ApiInfo(); + CommonFilter commonFilter=new CommonFilter(); + apiInfo.setTotalCount(commonFilter.getInstance().getTotalCount()); + apiInfo.setTotalFailCount(commonFilter.getInstance().getFailCount()); + List apiDetails = new ArrayList<>(); + for(Map.Entry entry: commonFilter.getInstance().getEndpointMap().entrySet()){ + MonitorInfo.DataInfo.NetInfo.ApiInfo.ApiDetailInfo apiDetail = + new MonitorInfo.DataInfo.NetInfo.ApiInfo.ApiDetailInfo(); + apiDetail.setName(entry.getKey()); + apiDetail.setCount((int)entry.getValue().get(CommonFilter.TOTAL_REQUST)); + apiDetail.setFailCount((int)entry.getValue().get(CommonFilter.FAIL_REQUST)); + apiDetails.add(apiDetail); + } + apiInfo.setApiDetailInfo(apiDetails); + netInfo.setApi(apiInfo); + + data.setNetInfo(netInfo); + + } + +} From 6474a0b21fe5040466be8deb9747d75e953c7051 Mon Sep 17 00:00:00 2001 From: alberto Date: Fri, 21 Feb 2020 11:55:03 +0800 Subject: [PATCH 29/42] delete nodeInfo blockChain --- config.conf | 2 +- .../trongeventquery/monitor/MonitorInfo.java | 237 ------------------ 2 files changed, 1 insertion(+), 238 deletions(-) diff --git a/config.conf b/config.conf index 45347b5..af5ca14 100644 --- a/config.conf +++ b/config.conf @@ -1,4 +1,4 @@ -mongo.host=47.91.17.89 +mongo.host=127.0.0.1 mongo.port=18883 mongo.dbname=eventlog mongo.username=tron diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java index f61dba7..61e14a5 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java @@ -160,8 +160,6 @@ public MonitorInfo setDataInfo(DataInfo data) { public static class DataInfo { private int interval; - private NodeInfo node; - private BlochainInfo blockchain; private NetInfo net; public int getInterval() { @@ -172,25 +170,6 @@ public DataInfo setInterval(int interval) { this.interval = interval; return this; } - - public NodeInfo getNodeInfo() { - return this.node; - } - - public DataInfo setNodeInfo(NodeInfo node) { - this.node = node; - return this; - } - - public DataInfo setBlockInfo(BlochainInfo blockchain) { - this.blockchain = blockchain; - return this; - } - - public BlochainInfo getBlockchainInfo() { - return this.blockchain; - } - public NetInfo getNetInfo() { return this.net; } @@ -200,222 +179,6 @@ public DataInfo setNetInfo(NetInfo net) { return this; } - // node monitor information - public static class NodeInfo { - private String ip; - private int Type; - private int status; - private String version; - private int noUpgradedSRCount; - private List noUpgradedSRList = new ArrayList<>(); - - public String getIp() { - return this.ip; - } - - public NodeInfo setIp(String ip) { - this.ip = ip; - return this; - } - - public int getType() { - return this.Type; - } - - public NodeInfo setType(int Type) { - this.Type = Type; - return this; - } - - public int getStatus() { - return this.status; - } - - public NodeInfo setStatus(int status) { - this.status = status; - return this; - } - - public String getVersion() { - return this.version; - } - - public NodeInfo setVersion(String version) { - this.version = version; - return this; - } - - public int getNoUpgradedSRCount() { - return this.noUpgradedSRCount; - } - - public NodeInfo setNoUpgradedSRCount(int noUpgradedSRCount) { - this.noUpgradedSRCount = noUpgradedSRCount; - return this; - } - - public List getNoUpgradedSRList() { - return this.noUpgradedSRList; - } - - public NodeInfo setNoUpgradedSRList(List noUpgradedSRList) { - this.noUpgradedSRList = noUpgradedSRList; - return this; - } - - public static class NoUpgradedSR { - private String address; - private String url; - - public String getAddress() { - return this.address; - } - - public NoUpgradedSR setAddress(String address) { - this.address = address; - return this; - } - - public String getUrl() { - return this.url; - } - - public NoUpgradedSR setUrl(String url) { - this.url = url; - return this; - } - } - - } - - // blockchain monitor information - public static class BlochainInfo { - private int headBlockNum; - private long headBlockTimestamp; - private String headBlockHash; - private int forkCount; - private int blockProcessTime; - private TPSInfo TPS; - private int TxCacheSize; - private int missTxCount; - - public int getHeadBlockNum() { - return this.headBlockNum; - } - - public BlochainInfo setHeadBlockNum(int headBlockNum) { - this.headBlockNum = headBlockNum; - return this; - } - - public long getHeadBlockTimestamp() { - return this.headBlockTimestamp; - } - - public BlochainInfo setHeadBlockTimestamp(long headBlockTimestamp) { - this.headBlockTimestamp = headBlockTimestamp; - return this; - } - - public String getHeadBlockHash() { - return this.headBlockHash; - } - - public BlochainInfo setHeadBlockHash(String headBlockHash) { - this.headBlockHash = headBlockHash; - return this; - } - - public int getForkCount() { - return this.forkCount; - } - - public BlochainInfo setForkCount(int forkCount) { - this.forkCount = forkCount; - return this; - } - - public int getBlockProcessTime() { - return this.blockProcessTime; - } - - public BlochainInfo setBlockProcessTime(int blockProcessTime) { - this.blockProcessTime = blockProcessTime; - return this; - } - - public TPSInfo getTPS() { - return this.TPS; - } - - public BlochainInfo setTPS(TPSInfo TPS) { - this.TPS = TPS; - return this; - } - - public int getTxCacheSize() { - return this.TxCacheSize; - } - - public BlochainInfo setTxCacheSize(int TxCacheSize) { - this.TxCacheSize = TxCacheSize; - return this; - } - - public int getMissTxCount() { - return this.missTxCount; - } - - public BlochainInfo setMissTxCount(int missTxCount) { - this.missTxCount = missTxCount; - return this; - } - - public static class TPSInfo { - private double meanRate; - private double oneMinuteRate; - private double fiveMinuteRate; - private double fifteenMinuteRate; - - public double getMeanRate() { - return this.meanRate; - } - - public TPSInfo setMeanRate(double meanRate) { - this.meanRate = meanRate; - return this; - } - - public double getOneMinuteRate() { - return this.oneMinuteRate; - } - - public TPSInfo setOneMinuteRate(double oneMinuteRate) { - this.oneMinuteRate = oneMinuteRate; - return this; - } - - public double getFiveMinuteRate() { - return this.fiveMinuteRate; - } - - public TPSInfo setFiveMinuteRate(double fiveMinuteRate) { - this.fiveMinuteRate = fiveMinuteRate; - return this; - } - - public double getFifteenMinuteRate() { - return this.fifteenMinuteRate; - } - - public TPSInfo setFifteenMinuteRate(double fifteenMinuteRate) { - this.fifteenMinuteRate = fifteenMinuteRate; - return this; - } - - } - } - // network monitor information public static class NetInfo { private int errorProtoCount; From ed554d992d01a16cdc00cd30211bdf91f855a6b9 Mon Sep 17 00:00:00 2001 From: alberto Date: Fri, 21 Feb 2020 13:01:58 +0800 Subject: [PATCH 30/42] add 4xx 5xx --- .../trongeventquery/filter/CommonFilter.java | 25 + .../trongeventquery/monitor/MonitorInfo.java | 817 +++++++++--------- .../monitor/MonitorService.java | 4 + 3 files changed, 459 insertions(+), 387 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java index 63abe28..c03069c 100644 --- a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java +++ b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java @@ -16,9 +16,13 @@ public class CommonFilter implements Filter { public static String TOTAL_REQUST = "TOTAL_REQUEST"; public static String FAIL_REQUST = "FAIL_REQUEST"; + public static String FAIL4XX_REQUST = "FAIL4XX_REQUEST"; + public static String FAIL5XX_REQUST = "FAIL5XX_REQUEST"; public static String OK_REQUST = "OK_REQUEST"; private static int totalCount = 0; private static int failCount = 0; + private static int count4xx=0; + private static int count5xx=0; private static int okCount=0; private static int interval = 1440; // 24 hour private static HashMap EndpointCount = new HashMap(); @@ -40,6 +44,13 @@ public int getFailCount() { public int getOkCount() { return this.okCount; } + public int getCount4xx() { + return count4xx; + } + public int getCount5xx() { + return count5xx; + } + public HashMap getEndpointMap() { return this.EndpointCount; } @@ -60,6 +71,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if (currentTime - preciousTime > gapMilliseconds) { //reset every 1 minutes totalCount = 0; failCount = 0; + count4xx=0; + count5xx=0; okCount=0; preciousTime = currentTime; EndpointCount.clear(); @@ -73,6 +86,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha } else { obj.put(TOTAL_REQUST, 0); obj.put(FAIL_REQUST, 0); + obj.put(FAIL4XX_REQUST, 0); + obj.put(FAIL5XX_REQUST, 0); obj.put(OK_REQUST, 0); obj.put(END_POINT, endpoint); } @@ -86,11 +101,21 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha // System.out.println("--response:"+response); if (resp.getStatus() != 200) { failCount++; + count5xx=failCount-count4xx; obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); + obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); + } + if (resp.getStatus() < 500 & resp.getStatus() > 399) { + count4xx++; + count5xx=failCount-count4xx; + obj.put(FAIL4XX_REQUST, (int) obj.get(FAIL4XX_REQUST) + 1); + obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); } } catch (Exception e) { failCount++; + count5xx=failCount-count4xx; obj.put(FAIL_REQUST, (int) obj.get(FAIL_REQUST) + 1); + obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); throw e; } // update map diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java index 61e14a5..5f5d3dd 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java @@ -8,36 +8,36 @@ @Slf4j public class MonitorInfo { - private int status; - private String msg; - private DataInfo data; + private int status; + private String msg; + private DataInfo data; - public int getStatus() { - return this.status; - } + public int getStatus() { + return this.status; + } - public MonitorInfo setStatus(int status) { - this.status = status; - return this; - } + public MonitorInfo setStatus(int status) { + this.status = status; + return this; + } - public String getMsg() { - return this.msg; - } + public String getMsg() { + return this.msg; + } - public MonitorInfo setMsg(String msg) { - this.msg = msg; - return this; - } + public MonitorInfo setMsg(String msg) { + this.msg = msg; + return this; + } - public DataInfo getDataInfo() { - return this.data; - } + public DataInfo getDataInfo() { + return this.data; + } - public MonitorInfo setDataInfo(DataInfo data) { - this.data = data; - return this; - } + public MonitorInfo setDataInfo(DataInfo data) { + this.data = data; + return this; + } // public MonitorInfo ToProtoEntity() { // Protocol.MonitorInfo.Builder builder = Protocol.MonitorInfo.newBuilder(); @@ -158,382 +158,425 @@ public MonitorInfo setDataInfo(DataInfo data) { // } - public static class DataInfo { - private int interval; - private NetInfo net; - - public int getInterval() { - return this.interval; - } - - public DataInfo setInterval(int interval) { - this.interval = interval; - return this; - } - public NetInfo getNetInfo() { - return this.net; - } - - public DataInfo setNetInfo(NetInfo net) { - this.net = net; - return this; - } - - // network monitor information - public static class NetInfo { - private int errorProtoCount; - private ApiInfo api; - private int connectionCount; - private int validConnectionCount; - private long TCPInTraffic; - private long TCPOutTraffic; - private int disconnectionCount; - private List disconnectionDetail = new ArrayList<>(); - private long UDPInTraffic; - private long UDPOutTraffic; - private LatencyInfo latency; - - public int getErrorProtoCount() { - return this.errorProtoCount; - } - - public NetInfo setErrorProtoCount(int errorProtoCount) { - this.errorProtoCount = errorProtoCount; - return this; - } - - public ApiInfo getApi() { - return this.api; - } - - public NetInfo setApi(ApiInfo api) { - this.api = api; - return this; - } - - public int getConnectionCount() { - return this.connectionCount; - } - - public NetInfo setConnectionCount(int connectionCount) { - this.connectionCount = connectionCount; - return this; - } - - public int getValidConnectionCount() { - return this.validConnectionCount; - } - - public NetInfo setValidConnectionCount(int validConnectionCount) { - this.validConnectionCount = validConnectionCount; - return this; - } - - public long getTCPInTraffic() { - return this.TCPInTraffic; - } - - public NetInfo setTCPInTraffic(long TCPInTraffic) { - this.TCPInTraffic = TCPInTraffic; - return this; - } - - public long getTCPOutTraffic() { - return this.TCPOutTraffic; - } - - public NetInfo setTCPOutTraffic(long TCPOutTraffic) { - this.TCPOutTraffic = TCPOutTraffic; - return this; - } - - public int getDisconnectionCount() { - return this.disconnectionCount; - } - - public NetInfo setDisconnectionCount(int disconnectionCount) { - this.disconnectionCount = disconnectionCount; - return this; - } - - public List getDisconnectionDetail() { - return this.disconnectionDetail; - } - - public NetInfo setDisconnectionDetail(List disconnectionDetail) { - this.disconnectionDetail = disconnectionDetail; - return this; - } - - public long getUDPInTraffic() { - return this.UDPInTraffic; - } - - public NetInfo setUDPInTraffic(long UDPInTraffic) { - this.UDPInTraffic = UDPInTraffic; - return this; - } - - public long getUDPOutTraffic() { - return this.UDPOutTraffic; - } + public static class DataInfo { + private int interval; + private NetInfo net; - public NetInfo setUDPOutTraffic(long UDPOutTraffic) { - this.UDPOutTraffic = UDPOutTraffic; - return this; - } - - public LatencyInfo getLatency() { - return this.latency; - } - - public NetInfo setLatency(LatencyInfo latency) { - this.latency = latency; - return this; - } - - // API monitor information - public static class ApiInfo { - private int totalCount; - private int totalFailCount; - private List detail = new ArrayList<>(); - - public int getTotalCount() { - return this.totalCount; - } - - public ApiInfo setTotalCount(int totalCount) { - this.totalCount = totalCount; - return this; - } - - public int getTotalFailCount() { - return this.totalFailCount; - } - - public ApiInfo setTotalFailCount(int totalFailCount) { - this.totalFailCount = totalFailCount; - return this; + public int getInterval() { + return this.interval; } - public List getApiDetailInfo() { - return this.detail; - } - - public ApiInfo setApiDetailInfo(List detail) { - this.detail = detail; - return this; - } - - public static class ApiDetailInfo { - private String name; - private int count; - private int failCount; - - public String getName() { - return this.name; - } - - public ApiDetailInfo setName(String name) { - this.name = name; + public DataInfo setInterval(int interval) { + this.interval = interval; return this; - } - - public int getCount() { - return this.count; - } - - public ApiDetailInfo setCount(int count) { - this.count = count; - return this; - } - - public int getFailCount() { - return this.failCount; - } - - public ApiDetailInfo setFailCount(int failCount) { - this.failCount = failCount; - return this; - } - } - } - - // disconnection monitor information - public static class DisconnectionDetailInfo { - private String reason; - private int count; - - public String getReason() { - return this.reason; } - public DisconnectionDetailInfo setReason(String reason) { - this.reason = reason; - return this; - } - - public int getCount() { - return this.count; - } - - public DisconnectionDetailInfo setCount(int count) { - this.count = count; - return this; - } - - } - - // latency monitor information - public static class LatencyInfo { - private int top99; - private int top95; - private int totalCount; - private int delay1S; - private int delay2S; - private int delay3S; - private List detail = new ArrayList<>(); - - public int getTop99() { - return this.top99; + public NetInfo getNetInfo() { + return this.net; } - public LatencyInfo setTop99(int top99) { - this.top99 = top99; - return this; - } - - public int getTop95() { - return this.top95; - } - - public LatencyInfo setTop95(int top95) { - this.top95 = top95; - return this; - } - - public int getTotalCount() { - return this.totalCount; - } - - public LatencyInfo setTotalCount(int totalCount) { - this.totalCount = totalCount; - return this; - } - - public int getDelay1S() { - return this.delay1S; - } - - public LatencyInfo setDelay1S(int delay1S) { - this.delay1S = delay1S; - return this; - } - - public int getDelay2S() { - return this.delay2S; - } - - public LatencyInfo setDelay2S(int delay2S) { - this.delay2S = delay2S; - return this; - } - - public int getDelay3S() { - return this.delay3S; - } - - public LatencyInfo setDelay3S(int delay3S) { - this.delay3S = delay3S; - return this; + public DataInfo setNetInfo(NetInfo net) { + this.net = net; + return this; } - public List getLatencyDetailInfo() { - return this.detail; - } + // network monitor information + public static class NetInfo { + private int errorProtoCount; + private ApiInfo api; + private int connectionCount; + private int validConnectionCount; + private long TCPInTraffic; + private long TCPOutTraffic; + private int disconnectionCount; + private List disconnectionDetail = new ArrayList<>(); + private long UDPInTraffic; + private long UDPOutTraffic; + private LatencyInfo latency; + + public int getErrorProtoCount() { + return this.errorProtoCount; + } + + public NetInfo setErrorProtoCount(int errorProtoCount) { + this.errorProtoCount = errorProtoCount; + return this; + } + + public ApiInfo getApi() { + return this.api; + } + + public NetInfo setApi(ApiInfo api) { + this.api = api; + return this; + } + + public int getConnectionCount() { + return this.connectionCount; + } + + public NetInfo setConnectionCount(int connectionCount) { + this.connectionCount = connectionCount; + return this; + } + + public int getValidConnectionCount() { + return this.validConnectionCount; + } + + public NetInfo setValidConnectionCount(int validConnectionCount) { + this.validConnectionCount = validConnectionCount; + return this; + } + + public long getTCPInTraffic() { + return this.TCPInTraffic; + } + + public NetInfo setTCPInTraffic(long TCPInTraffic) { + this.TCPInTraffic = TCPInTraffic; + return this; + } + + public long getTCPOutTraffic() { + return this.TCPOutTraffic; + } + + public NetInfo setTCPOutTraffic(long TCPOutTraffic) { + this.TCPOutTraffic = TCPOutTraffic; + return this; + } + + public int getDisconnectionCount() { + return this.disconnectionCount; + } + + public NetInfo setDisconnectionCount(int disconnectionCount) { + this.disconnectionCount = disconnectionCount; + return this; + } + + public List getDisconnectionDetail() { + return this.disconnectionDetail; + } + + public NetInfo setDisconnectionDetail(List disconnectionDetail) { + this.disconnectionDetail = disconnectionDetail; + return this; + } + + public long getUDPInTraffic() { + return this.UDPInTraffic; + } + + public NetInfo setUDPInTraffic(long UDPInTraffic) { + this.UDPInTraffic = UDPInTraffic; + return this; + } + + public long getUDPOutTraffic() { + return this.UDPOutTraffic; + } + + public NetInfo setUDPOutTraffic(long UDPOutTraffic) { + this.UDPOutTraffic = UDPOutTraffic; + return this; + } + + public LatencyInfo getLatency() { + return this.latency; + } + + public NetInfo setLatency(LatencyInfo latency) { + this.latency = latency; + return this; + } + + // API monitor information + public static class ApiInfo { + private int totalCount; + private int totalFailCount; + private int totalCount4xx; + private int totalCount5xx; + + private List detail = new ArrayList<>(); + + public int getTotalCount() { + return this.totalCount; + } + + public ApiInfo setTotalCount(int totalCount) { + this.totalCount = totalCount; + return this; + } + + public int getTotalFailCount() { + return this.totalFailCount; + } + + public ApiInfo setTotalFailCount(int totalFailCount) { + this.totalFailCount = totalFailCount; + return this; + } + + public int getTotalCount4xx() { + return this.totalCount4xx; + } + + public ApiInfo setTotalCount4xx(int totalCount4xx) { + this.totalCount4xx = totalCount4xx; + return this; + } + + public int getTotalCount5xx() { + return this.totalCount5xx; + } + + public ApiInfo setTotalCount5xx(int totalCount5xx) { + this.totalCount5xx = totalCount5xx; + return this; + } + + public List getApiDetailInfo() { + return this.detail; + } + + public ApiInfo setApiDetailInfo(List detail) { + this.detail = detail; + return this; + } + + public static class ApiDetailInfo { + private String name; + private int count; + private int failCount; + private int count4xx; + private int count5xx; + + + public String getName() { + return this.name; + } + + public ApiDetailInfo setName(String name) { + this.name = name; + return this; + } + + public int getCount() { + return this.count; + } + + public ApiDetailInfo setCount(int count) { + this.count = count; + return this; + } + + public int getFailCount() { + return this.failCount; + } + + public ApiDetailInfo setFailCount(int failCount) { + this.failCount = failCount; + return this; + } + + public int getCount4xx() { + return this.count4xx; + } + + public ApiDetailInfo setCount4xx(int count4xx) { + this.count4xx = count4xx; + return this; + } + + public int getCount5xx() { + return this.count5xx; + } + + public ApiDetailInfo setCount5xx(int count5xx) { + this.count5xx = count5xx; + return this; + } + } + } + + // disconnection monitor information + public static class DisconnectionDetailInfo { + private String reason; + private int count; + + public String getReason() { + return this.reason; + } + + public DisconnectionDetailInfo setReason(String reason) { + this.reason = reason; + return this; + } + + public int getCount() { + return this.count; + } + + public DisconnectionDetailInfo setCount(int count) { + this.count = count; + return this; + } + + } + + // latency monitor information + public static class LatencyInfo { + private int top99; + private int top95; + private int totalCount; + private int delay1S; + private int delay2S; + private int delay3S; + private List detail = new ArrayList<>(); + + public int getTop99() { + return this.top99; + } + + public LatencyInfo setTop99(int top99) { + this.top99 = top99; + return this; + } + + public int getTop95() { + return this.top95; + } + + public LatencyInfo setTop95(int top95) { + this.top95 = top95; + return this; + } + + public int getTotalCount() { + return this.totalCount; + } + + public LatencyInfo setTotalCount(int totalCount) { + this.totalCount = totalCount; + return this; + } + + public int getDelay1S() { + return this.delay1S; + } + + public LatencyInfo setDelay1S(int delay1S) { + this.delay1S = delay1S; + return this; + } + + public int getDelay2S() { + return this.delay2S; + } + + public LatencyInfo setDelay2S(int delay2S) { + this.delay2S = delay2S; + return this; + } + + public int getDelay3S() { + return this.delay3S; + } + + public LatencyInfo setDelay3S(int delay3S) { + this.delay3S = delay3S; + return this; + } + + public List getLatencyDetailInfo() { + return this.detail; + } + + public LatencyInfo setLatencyDetailInfo(List detail) { + this.detail = detail; + return this; + } + + public static class LatencyDetailInfo { + private String witness; + private int top99; + private int top95; + private int count; + private int delay1S; + private int delay2S; + private int delay3S; + + public String getWitness() { + return this.witness; + } + + public LatencyDetailInfo setWitness(String witness) { + this.witness = witness; + return this; + } + + public int getTop99() { + return this.top99; + } + + public LatencyDetailInfo setTop99(int top99) { + this.top99 = top99; + return this; + } + + public int getTop95() { + return this.top95; + } + + public LatencyDetailInfo setTop95(int top95) { + this.top95 = top95; + return this; + } + + public int getCount() { + return this.count; + } + + public LatencyDetailInfo setCount(int count) { + this.count = count; + return this; + } + + public int getDelay1S() { + return this.delay1S; + } + + public LatencyDetailInfo setDelay1S(int delay1S) { + this.delay1S = delay1S; + return this; + } + + public int getDelay2S() { + return this.delay2S; + } + + public LatencyDetailInfo setDelay2S(int delay2S) { + this.delay2S = delay2S; + return this; + } + + public int getDelay3S() { + return this.delay3S; + } + + public LatencyDetailInfo setDelay3S(int delay3S) { + this.delay3S = delay3S; + return this; + } + + } + } - public LatencyInfo setLatencyDetailInfo(List detail) { - this.detail = detail; - return this; } - public static class LatencyDetailInfo { - private String witness; - private int top99; - private int top95; - private int count; - private int delay1S; - private int delay2S; - private int delay3S; - - public String getWitness() { - return this.witness; - } - - public LatencyDetailInfo setWitness(String witness) { - this.witness = witness; - return this; - } - - public int getTop99() { - return this.top99; - } - - public LatencyDetailInfo setTop99(int top99) { - this.top99 = top99; - return this; - } - - public int getTop95() { - return this.top95; - } - - public LatencyDetailInfo setTop95(int top95) { - this.top95 = top95; - return this; - } - - public int getCount() { - return this.count; - } - - public LatencyDetailInfo setCount(int count) { - this.count = count; - return this; - } - - public int getDelay1S() { - return this.delay1S; - } - - public LatencyDetailInfo setDelay1S(int delay1S) { - this.delay1S = delay1S; - return this; - } - - public int getDelay2S() { - return this.delay2S; - } - - public LatencyDetailInfo setDelay2S(int delay2S) { - this.delay2S = delay2S; - return this; - } - - public int getDelay3S() { - return this.delay3S; - } - - public LatencyDetailInfo setDelay3S(int delay3S) { - this.delay3S = delay3S; - return this; - } - - } - } } - - - } } diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java index 8dfeee5..54013fc 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java @@ -38,6 +38,8 @@ public void setNetInfo(MonitorInfo.DataInfo data) { CommonFilter commonFilter=new CommonFilter(); apiInfo.setTotalCount(commonFilter.getInstance().getTotalCount()); apiInfo.setTotalFailCount(commonFilter.getInstance().getFailCount()); + apiInfo.setTotalCount4xx(commonFilter.getInstance().getCount4xx()); + apiInfo.setTotalCount5xx(commonFilter.getInstance().getCount5xx()); List apiDetails = new ArrayList<>(); for(Map.Entry entry: commonFilter.getInstance().getEndpointMap().entrySet()){ MonitorInfo.DataInfo.NetInfo.ApiInfo.ApiDetailInfo apiDetail = @@ -45,6 +47,8 @@ public void setNetInfo(MonitorInfo.DataInfo data) { apiDetail.setName(entry.getKey()); apiDetail.setCount((int)entry.getValue().get(CommonFilter.TOTAL_REQUST)); apiDetail.setFailCount((int)entry.getValue().get(CommonFilter.FAIL_REQUST)); + apiDetail.setCount4xx((int)entry.getValue().get(CommonFilter.FAIL4XX_REQUST)); + apiDetail.setCount5xx((int)entry.getValue().get(CommonFilter.FAIL5XX_REQUST)); apiDetails.add(apiDetail); } apiInfo.setApiDetailInfo(apiDetails); From 7edeef9ff594f06e5d3e5aef259776718f47a400 Mon Sep 17 00:00:00 2001 From: alberto Date: Fri, 21 Feb 2020 14:08:19 +0800 Subject: [PATCH 31/42] add 2xx --- .../trongeventquery/filter/CommonFilter.java | 2 ++ .../trongeventquery/monitor/MonitorInfo.java | 19 +++++++++++++++++++ .../monitor/MonitorService.java | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java index c03069c..8b02569 100644 --- a/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java +++ b/src/main/java/org/tron/trongeventquery/filter/CommonFilter.java @@ -118,6 +118,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha obj.put(FAIL5XX_REQUST, (int) obj.get(FAIL_REQUST)-(int) obj.get(FAIL4XX_REQUST)); throw e; } + obj.put(OK_REQUST, (int) obj.get(TOTAL_REQUST) - (int) obj.get(FAIL_REQUST)); + okCount=totalCount-failCount; // update map EndpointCount.put(endpoint, obj); } else { diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java index 5f5d3dd..7ae2a28 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorInfo.java @@ -297,6 +297,7 @@ public NetInfo setLatency(LatencyInfo latency) { public static class ApiInfo { private int totalCount; private int totalFailCount; + private int totalCount2xx; private int totalCount4xx; private int totalCount5xx; @@ -320,6 +321,15 @@ public ApiInfo setTotalFailCount(int totalFailCount) { return this; } + public int getTotalCount2xx() { + return this.totalCount2xx; + } + + public ApiInfo setTotalCount2xx(int totalCount2xx) { + this.totalCount2xx = totalCount2xx; + return this; + } + public int getTotalCount4xx() { return this.totalCount4xx; } @@ -353,6 +363,7 @@ public static class ApiDetailInfo { private int failCount; private int count4xx; private int count5xx; + private int count2xx; public String getName() { @@ -399,6 +410,14 @@ public ApiDetailInfo setCount5xx(int count5xx) { this.count5xx = count5xx; return this; } + public int getCount2xx() { + return this.count2xx; + } + + public ApiDetailInfo setCount2xx(int count2xx) { + this.count2xx = count2xx; + return this; + } } } diff --git a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java index 54013fc..ec8929e 100644 --- a/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java +++ b/src/main/java/org/tron/trongeventquery/monitor/MonitorService.java @@ -37,6 +37,7 @@ public void setNetInfo(MonitorInfo.DataInfo data) { MonitorInfo.DataInfo.NetInfo.ApiInfo apiInfo = new MonitorInfo.DataInfo.NetInfo.ApiInfo(); CommonFilter commonFilter=new CommonFilter(); apiInfo.setTotalCount(commonFilter.getInstance().getTotalCount()); + apiInfo.setTotalCount2xx(commonFilter.getInstance().getOkCount()); apiInfo.setTotalFailCount(commonFilter.getInstance().getFailCount()); apiInfo.setTotalCount4xx(commonFilter.getInstance().getCount4xx()); apiInfo.setTotalCount5xx(commonFilter.getInstance().getCount5xx()); @@ -47,6 +48,7 @@ public void setNetInfo(MonitorInfo.DataInfo data) { apiDetail.setName(entry.getKey()); apiDetail.setCount((int)entry.getValue().get(CommonFilter.TOTAL_REQUST)); apiDetail.setFailCount((int)entry.getValue().get(CommonFilter.FAIL_REQUST)); + apiDetail.setCount2xx((int)entry.getValue().get(CommonFilter.OK_REQUST)); apiDetail.setCount4xx((int)entry.getValue().get(CommonFilter.FAIL4XX_REQUST)); apiDetail.setCount5xx((int)entry.getValue().get(CommonFilter.FAIL5XX_REQUST)); apiDetails.add(apiDetail); From 4b8bf518653e060f3cc9c78bf5bf86320392c8dc Mon Sep 17 00:00:00 2001 From: wubinTron Date: Thu, 27 Feb 2020 18:42:20 +0800 Subject: [PATCH 32/42] remove corsFilter --- .../trongeventquery/TronEventApplication.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 4138c3a..6f8f1a5 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -37,21 +37,7 @@ public static void main(String[] args) { SpringApplication.run(TronEventApplication.class, args); shutdown(); } - - @Bean - public FilterRegistrationBean corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - source.registerCorsConfiguration("/**", config); - FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); - bean.setOrder(0); - return bean; - } - + @Bean public MongoTemplate mongoTemplate( @Value("${mongo.host}")String mongodbIp, @Value("${mongo.dbname}")String mongodbDbName, From a3915f841a8c1db73d35d43752aa0026d58d09d6 Mon Sep 17 00:00:00 2001 From: wubinTron Date: Thu, 27 Feb 2020 18:42:31 +0800 Subject: [PATCH 33/42] remove corsFilter --- .../trongeventquery/TronEventApplication.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 6f8f1a5..4138c3a 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -37,7 +37,21 @@ public static void main(String[] args) { SpringApplication.run(TronEventApplication.class, args); shutdown(); } - + + @Bean + public FilterRegistrationBean corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + source.registerCorsConfiguration("/**", config); + FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); + bean.setOrder(0); + return bean; + } + @Bean public MongoTemplate mongoTemplate( @Value("${mongo.host}")String mongodbIp, @Value("${mongo.dbname}")String mongodbDbName, From 898488f7a23a22a4a879dfaf34e4c4c8fe1d0c57 Mon Sep 17 00:00:00 2001 From: wubinTron Date: Thu, 27 Feb 2020 18:47:21 +0800 Subject: [PATCH 34/42] remove corsFilter --- .../trongeventquery/TronEventApplication.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 4138c3a..6f8f1a5 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -37,21 +37,7 @@ public static void main(String[] args) { SpringApplication.run(TronEventApplication.class, args); shutdown(); } - - @Bean - public FilterRegistrationBean corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - source.registerCorsConfiguration("/**", config); - FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); - bean.setOrder(0); - return bean; - } - + @Bean public MongoTemplate mongoTemplate( @Value("${mongo.host}")String mongodbIp, @Value("${mongo.dbname}")String mongodbDbName, From cb23e427c765ec4bf921f77e0dd758b82fbb5de8 Mon Sep 17 00:00:00 2001 From: "dev7879888190@163.com" Date: Mon, 2 Mar 2020 12:05:46 +0800 Subject: [PATCH 35/42] fix config file --- config.conf | 4 ++-- deploy.sh | 8 +++++++- .../org/tron/trongeventquery/TronEventApplication.java | 4 ---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config.conf b/config.conf index af5ca14..0214bf4 100644 --- a/config.conf +++ b/config.conf @@ -4,6 +4,6 @@ mongo.dbname=eventlog mongo.username=tron mongo.password=123456 -mongo.connectionsPerHost=8 -mongo.threadsAllowedToBlockForConnectionMultiplier=4 +mongo.connectionsPerHost=200 +mongo.threadsAllowedToBlockForConnectionMultiplier=10 mongo.deadline=10 diff --git a/deploy.sh b/deploy.sh index dbd7ea4..1ae95f5 100755 --- a/deploy.sh +++ b/deploy.sh @@ -10,6 +10,12 @@ while true; do break fi done -nohup java -jar target/troneventquery-1.0.0-SNAPSHOT.jar 2>&1 & +total=`cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print $2}'` +xmx=`echo "$total/1024/1024*0.5" | bc |awk -F. '{print $1"g"}'` +logtime=`date +%Y-%m-%d_%H-%M-%S` + nohup java -Xmx$xmx -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log\ + -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m\ + -XX:+CMSScavengeBeforeRemark -jar target/troneventquery-1.0.0-SNAPSHOT.jar + sleep 10 echo "ok!" diff --git a/src/main/java/org/tron/trongeventquery/TronEventApplication.java b/src/main/java/org/tron/trongeventquery/TronEventApplication.java index 6f8f1a5..6fe27e1 100644 --- a/src/main/java/org/tron/trongeventquery/TronEventApplication.java +++ b/src/main/java/org/tron/trongeventquery/TronEventApplication.java @@ -17,15 +17,11 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; -import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) From 6df3b0ae3697b70b92927fd6a9bcd4a696724ef2 Mon Sep 17 00:00:00 2001 From: "dev7879888190@163.com" Date: Mon, 2 Mar 2020 12:07:32 +0800 Subject: [PATCH 36/42] fix config file --- deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 1ae95f5..699762b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -11,7 +11,7 @@ while true; do fi done total=`cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print $2}'` -xmx=`echo "$total/1024/1024*0.5" | bc |awk -F. '{print $1"g"}'` +xmx=`echo "$total/1024/1024*0.6" | bc |awk -F. '{print $1"g"}'` logtime=`date +%Y-%m-%d_%H-%M-%S` nohup java -Xmx$xmx -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log\ -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m\ From dcb16e5ae7f4d3f3f2593e5df9ed5ef7f55591c7 Mon Sep 17 00:00:00 2001 From: "dev7879888190@163.com" Date: Mon, 2 Mar 2020 12:21:26 +0800 Subject: [PATCH 37/42] fix config file --- deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 699762b..85f5d98 100755 --- a/deploy.sh +++ b/deploy.sh @@ -15,7 +15,7 @@ xmx=`echo "$total/1024/1024*0.6" | bc |awk -F. '{print $1"g"}'` logtime=`date +%Y-%m-%d_%H-%M-%S` nohup java -Xmx$xmx -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log\ -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m\ - -XX:+CMSScavengeBeforeRemark -jar target/troneventquery-1.0.0-SNAPSHOT.jar + -XX:+CMSScavengeBeforeRemark -jar target/troneventquery-1.0.0-SNAPSHOT.jar >> query.log 2>&1 & sleep 10 echo "ok!" From bff95da6c12d2a3d691de8cb233f891f95a19c20 Mon Sep 17 00:00:00 2001 From: M-blockcoder Date: Thu, 4 Jun 2020 15:45:56 +0800 Subject: [PATCH 38/42] transaction data --- .../transactions/TransactionTriggerEntity.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/trongeventquery/transactions/TransactionTriggerEntity.java b/src/main/java/org/tron/trongeventquery/transactions/TransactionTriggerEntity.java index 765c953..56b8182 100644 --- a/src/main/java/org/tron/trongeventquery/transactions/TransactionTriggerEntity.java +++ b/src/main/java/org/tron/trongeventquery/transactions/TransactionTriggerEntity.java @@ -107,6 +107,10 @@ public class TransactionTriggerEntity implements Serializable { @JsonProperty(value = "latestSolidifiedBlockNumber") private long latestSolidifiedBlockNumber; + @Field(value = "data") + @JsonProperty(value = "data") + private String data; + public String getContractType() { return contractType; } @@ -118,7 +122,7 @@ public TransactionTriggerEntity(String transactionId, String blockHash, String fromAddress, String toAddress, String assetName, long assetAmount, String contractResult,long contractCallValue, String result, String contractAddress, String contractType, - long feeLimit,long timeStamp, long latestSolidifiedBlockNumber) { + long feeLimit,long timeStamp, long latestSolidifiedBlockNumber, String data) { this.transactionId = transactionId; this.blockHash = blockHash; this.blockNumber = blockNumber; @@ -141,5 +145,6 @@ public TransactionTriggerEntity(String transactionId, String blockHash, this.feeLimit = feeLimit; this.timeStamp = timeStamp; this.latestSolidifiedBlockNumber = latestSolidifiedBlockNumber; + this.data = data; } } \ No newline at end of file From e152bf9d33385cc50d321fac387c4eab3e5e50af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:02:18 +0000 Subject: [PATCH 39/42] Bump guava from 24.1-jre to 29.0-jre Bumps [guava](https://github.com/google/guava) from 24.1-jre to 29.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b574aaa..9f18031 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ com.google.guava guava - 24.1-jre + 29.0-jre From 55fc5cd4c6b76b5fa3c07f56ff9e0dd7fe6453df Mon Sep 17 00:00:00 2001 From: Sakary <> Date: Tue, 23 Nov 2021 12:03:33 +0800 Subject: [PATCH 40/42] build(deps): bump guava version to 30.0-jre --- .gitignore | 6 +++++- pom.xml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e268bf5..3689fe9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ target/* .idea/* -troneventquery.iml \ No newline at end of file +troneventquery.iml +.classpath +.factorypath +.settings/* +.vscode/* diff --git a/pom.xml b/pom.xml index 9f18031..336a6c3 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ com.google.guava guava - 29.0-jre + [30.0-jre,) From c714a45f6879f8ebd910dbec4244c46e31667b89 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Jan 2022 22:37:27 +0000 Subject: [PATCH 41/42] Bump protobuf-java from 3.5.1 to 3.16.1 Bumps [protobuf-java](https://github.com/protocolbuffers/protobuf) from 3.5.1 to 3.16.1. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/master/generate_changelog.py) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.5.1...v3.16.1) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 336a6c3..53223d5 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ com.google.protobuf protobuf-java - 3.5.1 + 3.16.1 From fa24c1bf4769f4bca11aa207b665f62f974f4e4f Mon Sep 17 00:00:00 2001 From: Wenhua Zhang Date: Tue, 25 Oct 2022 11:49:55 +0800 Subject: [PATCH 42/42] fix: upgrade fastjson --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53223d5..99b7ca4 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ com.alibaba fastjson - 1.2.49 + 2.0.16