Skip to content

Commit

Permalink
V1.7.3 (#34)
Browse files Browse the repository at this point in the history
* 1.7.3
  • Loading branch information
wangyue168git authored May 20, 2021
1 parent 3052296 commit 1c0d512
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 82 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 更新历史

### V1.7.3 (2021-05-21)
- 服务方式启动整合编译插件,配置合约即可完成导出
- sdk修复部分bug

### V1.7.2 (2021-04-21)
- SDK封装为服务,提供使用
- 服务docker化,提供快速部署方式
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class MethodMetaInfo {
/** @Fields methodName : method name */
private String methodName;

private String originName;

private String type;

/** @Fields contractName : contract name */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static String createMethodTableSql(MethodMetaInfo methodMetaInfo) {
StringBuilder sql = new StringBuilder();
DataExportContext currentContext = ExportConstant.getCurrentContext();
sql.append("CREATE TABLE ")
.append("`").append(getTableName(methodMetaInfo.getContractName(), methodMetaInfo.getMethodName()))
.append("`").append(getTableName(methodMetaInfo.getContractName(), methodMetaInfo.getMethodName() + "_method"))
.append("`")
.append(" (\n")
.append(" `pk_id` bigint(20) NOT NULL AUTO_INCREMENT,\n" +
Expand Down Expand Up @@ -207,7 +207,7 @@ public static String createEventTableSql(EventMetaInfo eventMetaInfo) {
StringBuilder sql = new StringBuilder();
DataExportContext currentContext = ExportConstant.getCurrentContext();
sql.append("CREATE TABLE ").append("`").append(
getTableName(eventMetaInfo.getContractName(), eventMetaInfo.getEventName()))
getTableName(eventMetaInfo.getContractName(), eventMetaInfo.getEventName() + "_event"))
.append("`")
.append(" (\n")
.append(" `pk_id` bigint(20) NOT NULL AUTO_INCREMENT,\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ private static void addMethodAndEventTables(List<String> tables) {
ContractDetail contractDetail = contractDetailMap.getValue();
if (CollectionUtil.isNotEmpty(contractDetail.getEventMetaInfos())) {
contractDetail.getEventMetaInfos().forEach(eventMetaInfo ->
tables.add(TableSQL.getTableName(eventMetaInfo.getContractName(), eventMetaInfo.getEventName())));
tables.add(TableSQL.getTableName(eventMetaInfo.getContractName(), eventMetaInfo.getEventName() + "_event")));
}
if (CollectionUtil.isNotEmpty(contractDetail.getMethodMetaInfos())) {
contractDetail.getMethodMetaInfos().forEach(methodMetaInfo ->
tables.add(TableSQL.getTableName(methodMetaInfo.getContractName(), methodMetaInfo.getMethodName())));
tables.add(TableSQL.getTableName(methodMetaInfo.getContractName(), methodMetaInfo.getMethodName() + "_method")));
}
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ private static void createMethodAndEventTable(Db db, List<String> blackTables, L
String tableSql = TableSQL.createMethodTableSql(methodMetaInfo);
try {
if (!tables.contains(TableSQL.getTableName(methodMetaInfo.getContractName(),
methodMetaInfo.getMethodName()))) {
methodMetaInfo.getMethodName() + "_method"))) {
db.execute(tableSql);
}
} catch (SQLException e) {
Expand All @@ -268,7 +268,7 @@ private static void createMethodAndEventTable(Db db, List<String> blackTables, L
String tableSql = TableSQL.createEventTableSql(eventMetaInfo);
try {
if (!tables.contains(TableSQL.getTableName(eventMetaInfo.getContractName(),
eventMetaInfo.getEventName()))) {
eventMetaInfo.getEventName() + "_event"))) {
db.execute(tableSql);
}
} catch (SQLException e) {
Expand All @@ -293,7 +293,7 @@ private static void createMethodAndEventShardingTable(Db db, List<String> blackT
try {
for (int i = 0; i < shardingNumberPerDatasource; i++) {
String tableName = TableSQL.getTableName(methodMetaInfo.getContractName(),
methodMetaInfo.getMethodName());
methodMetaInfo.getMethodName() + "_method");
if (!tables.contains(tableName + i)) {
db.execute(tableSql.replaceFirst(tableName, tableName + i));
}
Expand All @@ -309,7 +309,7 @@ private static void createMethodAndEventShardingTable(Db db, List<String> blackT
try {
for (int i = 0; i < shardingNumberPerDatasource; i++) {
String tableName = TableSQL.getTableName(eventMetaInfo.getContractName(),
eventMetaInfo.getEventName());
eventMetaInfo.getEventName() + "_event");
if (!tables.contains(tableName + i)) {
db.execute(tableSql.replaceFirst(tableName, tableName + i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
package com.webank.blockchain.data.export.db.dao;

import cn.hutool.core.collection.CollectionUtil;
import com.webank.blockchain.data.export.common.bo.contract.ContractDetail;
import com.webank.blockchain.data.export.common.bo.contract.EventMetaInfo;
import com.webank.blockchain.data.export.common.bo.contract.MethodMetaInfo;
import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO;
import com.webank.blockchain.data.export.common.bo.data.BlockTxDetailInfoBO;
import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO;
import com.webank.blockchain.data.export.common.bo.data.EventBO;
import com.webank.blockchain.data.export.common.bo.data.MethodBO;
import com.webank.blockchain.data.export.common.bo.data.TxRawDataBO;
import com.webank.blockchain.data.export.common.bo.data.TxReceiptRawDataBO;
import com.webank.blockchain.data.export.common.constants.ContractConstants;
import com.webank.blockchain.data.export.common.entity.DataExportContext;
import com.webank.blockchain.data.export.common.entity.ESDataSource;
import com.webank.blockchain.data.export.common.entity.ExportConstant;
Expand All @@ -38,7 +34,6 @@

import java.net.InetAddress;
import java.util.List;
import java.util.Map;

/**
* @author wesleywang
Expand All @@ -63,10 +58,6 @@ public class ESHandleDao {

public static final String BLOCK_TX_DETAIL = "blocktxdetailinfo";

public static final String METHOD = "method";

public static final String EVENT = "event";

@SneakyThrows
public static TransportClient create(DataExportContext context) {
TransportClient client;
Expand Down Expand Up @@ -106,56 +97,33 @@ public static TransportClient create(DataExportContext context) {
if (!blackTables.contains(DataType.CONTRACT_INFO_TABLE) && !ESService.indexExists(client,CONTRACT_INFO)){
ESService.createIndex(client,CONTRACT_INFO);
}
if (CollectionUtil.isNotEmpty(context.getConfig().getContractInfoList())){
Map<String, ContractDetail> contractBinaryMap = ContractConstants.getCurrentContractMaps().getContractBinaryMap();
for(Map.Entry<String, ContractDetail> entry : contractBinaryMap.entrySet()) {
ContractDetail contractDetail = entry.getValue();
if (!blackTables.contains(DataType.METHOD_TABLE)) {
for (MethodMetaInfo methodMetaInfo : contractDetail.getMethodMetaInfos()) {
String index = (contractDetail.getContractInfoBO().getContractName() + methodMetaInfo.getMethodName() +
METHOD).toLowerCase();
if (!ESService.indexExists(client, index)) {
ESService.createIndex(client, index);
}
}
}
if (!blackTables.contains(DataType.EVENT_TABLE)) {
for (EventMetaInfo eventMetaInfo : contractDetail.getEventMetaInfos()) {
String index = (contractDetail.getContractInfoBO().getContractName() + eventMetaInfo.getEventName() +
EVENT).toLowerCase();
if (!ESService.indexExists(client, index)) {
ESService.createIndex(client, index);
}
}
}
}
}

return client;
}

public static void saveBlockInfo(BlockInfoBO blockInfoBO) {
TransportClient client = ExportConstant.getCurrentContext().getEsClient();
DataExportContext context = ExportConstant.getCurrentContext();
TransportClient client = context.getEsClient();
List<DataType> blackTables = context.getConfig().getDataTypeBlackList();

if (blockInfoBO.getBlockDetailInfo() != null) {
if (!blackTables.contains(DataType.BLOCK_DETAIL_INFO_TABLE) && blockInfoBO.getBlockDetailInfo() != null) {
ESService.createDocument(client,
BLOCK_DETAIL, "_doc", String.valueOf(blockInfoBO.getBlockDetailInfo().getBlockHeight()),
blockInfoBO.getBlockDetailInfo());
}
if (blockInfoBO.getBlockRawDataBO() != null) {
if (!blackTables.contains(DataType.BLOCK_RAW_DATA_TABLE) && blockInfoBO.getBlockRawDataBO() != null) {
ESService.createDocument(client,
BLOCK_RAW_DATA, "_doc", String.valueOf(blockInfoBO.getBlockRawDataBO().getBlockHeight()),
blockInfoBO.getBlockRawDataBO());
}
if (CollectionUtil.isNotEmpty(blockInfoBO.getTxRawDataBOList())) {
if (!blackTables.contains(DataType.TX_RAW_DATA_TABLE) && CollectionUtil.isNotEmpty(blockInfoBO.getTxRawDataBOList())) {
for (TxRawDataBO txRawDataBO : blockInfoBO.getTxRawDataBOList()) {
ESService.createDocument(client,
TX_RAW_DATA, "_doc",
txRawDataBO.getTxHash(), txRawDataBO);
}
}

if (CollectionUtil.isNotEmpty(blockInfoBO.getTxReceiptRawDataBOList())) {
if (!blackTables.contains(DataType.TX_RECEIPT_RAW_DATA_TABLE) && CollectionUtil.isNotEmpty(blockInfoBO.getTxReceiptRawDataBOList())) {
for (TxReceiptRawDataBO txReceiptRawDataBO : blockInfoBO.getTxReceiptRawDataBOList()) {
ESService.createDocument(client,
TX_RECEIPT_RAW_DATA, "_doc",
Expand All @@ -164,7 +132,7 @@ public static void saveBlockInfo(BlockInfoBO blockInfoBO) {
}
}

if (CollectionUtil.isNotEmpty(blockInfoBO.getBlockTxDetailInfoList())) {
if (!blackTables.contains(DataType.BLOCK_TX_DETAIL_INFO_TABLE) && CollectionUtil.isNotEmpty(blockInfoBO.getBlockTxDetailInfoList())) {
for (BlockTxDetailInfoBO blockTxDetailInfoBO : blockInfoBO.getBlockTxDetailInfoList()) {
ESService.createDocument(client,
BLOCK_TX_DETAIL, "_doc",
Expand All @@ -173,17 +141,17 @@ public static void saveBlockInfo(BlockInfoBO blockInfoBO) {
}
}

if (CollectionUtil.isNotEmpty(blockInfoBO.getEventInfoList())) {
if (!blackTables.contains(DataType.EVENT_TABLE) && CollectionUtil.isNotEmpty(blockInfoBO.getEventInfoList())) {
for (EventBO eventBO : blockInfoBO.getEventInfoList()) {
ESService.createDocument(client,
eventBO.getTable().toLowerCase() + EVENT,
eventBO.getTable().toLowerCase(),
"_doc", eventBO.getEntity().get("tx_hash").toString(), eventBO);
}
}
if (CollectionUtil.isNotEmpty(blockInfoBO.getMethodInfoList())) {
if (!blackTables.contains(DataType.METHOD_TABLE) && CollectionUtil.isNotEmpty(blockInfoBO.getMethodInfoList())) {
for (MethodBO methodBO : blockInfoBO.getMethodInfoList()) {
ESService.createDocument(client,
methodBO.getTable().toLowerCase() + METHOD,
methodBO.getTable().toLowerCase(),
"_doc", methodBO.getEntity().get("tx_hash").toString(), methodBO);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition.NamedType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -58,6 +59,8 @@ public static List<MethodMetaInfo> parseToInfoList(String abiStr, String contrac
contractGenOffs = genOffMap.get(contractName);
}
List<MethodMetaInfo> lists = Lists.newArrayList();
Map<String,Integer> overloadingMethod = new HashMap<>();
Map<String, MethodMetaInfo> notOverMethodMap = new HashMap<>();
for (ABIDefinition abiDefinition : abiDefinitions) {
String abiType = abiDefinition.getType();
if (abiType.equals(AbiTypeConstants.ABI_EVENT_TYPE) || abiDefinition.isConstant()) {
Expand All @@ -77,7 +80,19 @@ public static List<MethodMetaInfo> parseToInfoList(String abiStr, String contrac
if (abiType.equals(AbiTypeConstants.ABI_CONSTRUCTOR_TYPE)) {
method.setMethodName("constructor");
} else {
method.setMethodName(abiDefinition.getName());
if (overloadingMethod.containsKey(abiDefinition.getName())){
int index = overloadingMethod.get(abiDefinition.getName()) + 1;
if (index == 1){
notOverMethodMap.get(abiDefinition.getName()).setMethodName(abiDefinition.getName() + "_0");
}
method.setMethodName(abiDefinition.getName() + "_" +index);
overloadingMethod.put(abiDefinition.getName(), index);
}else {
method.setMethodName(abiDefinition.getName());
overloadingMethod.put(method.getMethodName(),0);
notOverMethodMap.put(method.getMethodName(),method);
}
method.setOriginName(abiDefinition.getName());
}
method.setMethodId(abiDefinition.getMethodId(ExportConstant.getCurrentContext().getClient().getCryptoSuite())
+ "_" + contractName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ private static List<EventBO> parserEvent(Map<String, ContractInfo> contractAbiMa
continue;
}
EventMetaInfo eventMetaInfo = eventMetaInfoMap.get(entry.getKey());
int i = 0;
for (List<Object> params : entry.getValue()) {
EventBO eventBO = new EventBO();
Map<String, Object> entity = Maps.newHashMap();
int i = 0;
for (FieldVO fieldVO : eventMetaInfo.getList()) {
if (CollectionUtil.isNotEmpty(config.getIgnoreParam())
&& config.getIgnoreParam().containsKey(eventMetaInfo.getContractName())){
Expand All @@ -136,7 +136,7 @@ private static List<EventBO> parserEvent(Map<String, ContractInfo> contractAbiMa
entity.put("contract_address", tr.getContractAddress());
entity.put("block_height", Numeric.toBigInt(tr.getBlockNumber()).longValue());
eventBO.setEntity(entity);
eventBO.setTable(TableSQL.getTableName(contractName,eventMetaInfo.getEventName()));
eventBO.setTable(TableSQL.getTableName(contractName,eventMetaInfo.getEventName() + "_event"));
boList.add(eventBO);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
@Slf4j
public class MethodCrawlerHandler {


@SuppressWarnings({ "rawtypes", "unchecked" })
public static BlockMethodInfo crawl(Block block, Map<String, String> txHashContractAddressMapping) throws IOException {
BlockMethodInfo blockMethodInfo = new BlockMethodInfo();
Expand All @@ -73,12 +74,12 @@ public static BlockMethodInfo crawl(Block block, Map<String, String> txHashContr
TransactionObject to = (TransactionObject) result;
JsonTransactionResponse transaction = to.get();
Optional<TransactionReceipt> opt = ExportConstant.getCurrentContext().getClient()
.getTransactionReceipt(transaction.getHash()).getTransactionReceipt();
.getTransactionReceipt(transaction.getHash()).getTransactionReceipt();
String contractAddress = "";
if (opt.isPresent()) {
TransactionReceipt receipt = opt.get();
TxRawDataBO txRawDataBO = getTxRawDataBO(block, transaction, receipt);
contractAddress = txRawDataBO.getTo();
contractAddress = receipt.getContractAddress();
TxReceiptRawDataBO txReceiptRawDataBO = getTxReceiptRawDataBO(block, receipt, contractAddress);
txRawDataBOList.add(txRawDataBO);
txReceiptRawDataBOList.add(txReceiptRawDataBO);
Expand Down Expand Up @@ -125,7 +126,7 @@ public static MethodBO parseMethod(Block block, MethodMetaInfo methodMetaInfo, T
ExportConfig config = ExportConstant.getCurrentContext().getConfig();
MethodBO methodBO = null;
try {
List<Object> params = MethodUtils.decodeMethodInput(abi, methodMetaInfo.getMethodName(), receipt,
List<Object> params = MethodUtils.decodeMethodInput(abi, methodMetaInfo.getOriginName(), receipt,
ExportConstant.getCurrentContext().getClient());
if(CollectionUtil.isEmpty(params)) {
return null;
Expand All @@ -138,10 +139,10 @@ public static MethodBO parseMethod(Block block, MethodMetaInfo methodMetaInfo, T
entity.put("block_height", Numeric.toBigInt(receipt.getBlockNumber()).longValue());
entity.put("method_status", receipt.getStatus());
methodBO.setEntity(entity);
methodBO.setTable(TableSQL.getTableName(methodMetaInfo.getContractName(), methodMetaInfo.getMethodName()));
methodBO.setTable(TableSQL.getTableName(methodMetaInfo.getContractName(), methodMetaInfo.getMethodName() + "_method"));
TransactionResponse response;
if (!CollectionUtil.isEmpty(methodMetaInfo.getOutputList())) {
response = decoder.decodeReceiptWithValues(abi, methodMetaInfo.getMethodName(), receipt);
response = decoder.decodeReceiptWithValues(abi, methodMetaInfo.getOriginName(), receipt);
List<Object> returns = response.getValuesList();
int i = 0;
for (FieldVO fieldVO : methodMetaInfo.getOutputList()) {
Expand Down
Loading

0 comments on commit 1c0d512

Please sign in to comment.