├── .gitignore ├── ChangeLog.md ├── LICENSE ├── README.md ├── WeBankBlockchain-Data-Export-sdk ├── WeBankBlockchain-Data-Export-common │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── webank │ │ └── blockchain │ │ └── data │ │ └── export │ │ └── common │ │ ├── bo │ │ ├── contract │ │ │ ├── ContractDetail.java │ │ │ ├── ContractMapsInfo.java │ │ │ ├── EventMetaInfo.java │ │ │ ├── FieldVO.java │ │ │ └── MethodMetaInfo.java │ │ └── data │ │ │ ├── BlockContractInfoBO.java │ │ │ ├── BlockDetailInfoBO.java │ │ │ ├── BlockInfoBO.java │ │ │ ├── BlockMethodInfo.java │ │ │ ├── BlockRawDataBO.java │ │ │ ├── BlockTxDetailInfoBO.java │ │ │ ├── CommonBO.java │ │ │ ├── ContractInfoBO.java │ │ │ ├── DeployedAccountInfoBO.java │ │ │ ├── EventBO.java │ │ │ ├── MethodBO.java │ │ │ ├── TxRawDataBO.java │ │ │ └── TxReceiptRawDataBO.java │ │ ├── client │ │ ├── ChainClient.java │ │ ├── ChannelClient.java │ │ ├── RpcHttpClient.java │ │ └── StashClient.java │ │ ├── constants │ │ ├── AbiTypeConstants.java │ │ ├── BinConstant.java │ │ ├── BlockConstants.java │ │ ├── ContractConstants.java │ │ └── StatusCode.java │ │ ├── entity │ │ ├── BlockDataSource.java │ │ ├── ChainInfo.java │ │ ├── ContractInfo.java │ │ ├── DataExportContext.java │ │ ├── ESDataSource.java │ │ ├── ExportConfig.java │ │ ├── ExportConstant.java │ │ ├── ExportDataSource.java │ │ ├── MysqlDataSource.java │ │ ├── StashInfo.java │ │ └── TableSQL.java │ │ ├── enums │ │ ├── BlockCertaintyEnum.java │ │ ├── DataType.java │ │ ├── IgnoreBasicDataParam.java │ │ └── TxInfoStatusEnum.java │ │ ├── stash │ │ ├── DataStashMysqlRepo.java │ │ ├── StashBlockDataParser.java │ │ ├── entity │ │ │ ├── BlockHeader.java │ │ │ ├── BlockV2RC2.java │ │ │ ├── Log.java │ │ │ ├── TransactionDetail.java │ │ │ └── TransactionReceipt.java │ │ └── rlp │ │ │ ├── ByteArrayWrapper.java │ │ │ ├── ByteUtil.java │ │ │ ├── CompactEncoder.java │ │ │ ├── DecodeResult.java │ │ │ ├── FastByteComparisons.java │ │ │ ├── RLP.java │ │ │ ├── RLPElement.java │ │ │ ├── RLPItem.java │ │ │ ├── RLPList.java │ │ │ └── Value.java │ │ ├── subscribe │ │ ├── DefaultMsgTopic.java │ │ ├── TopicRegistry.java │ │ └── face │ │ │ ├── MsgTopicInterface.java │ │ │ └── SubscriberInterface.java │ │ ├── tools │ │ ├── AddressListUtils.java │ │ ├── AddressUtils.java │ │ ├── BigIntegerUtils.java │ │ ├── BoolUtils.java │ │ ├── BytesUtils.java │ │ ├── ClazzScanUtils.java │ │ ├── ClientUtil.java │ │ ├── DateUtils.java │ │ ├── JacksonException.java │ │ ├── JacksonUtils.java │ │ ├── MessageLoader.java │ │ ├── MethodUtils.java │ │ ├── NameValueVO.java │ │ └── ResponseUtils.java │ │ └── vo │ │ ├── CommonDataResponse.java │ │ ├── CommonResponse.java │ │ └── ValidErrorResponse.java ├── WeBankBlockchain-Data-Export-core │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── webank │ │ └── blockchain │ │ └── data │ │ └── export │ │ ├── api │ │ └── DataExportService.java │ │ ├── exception │ │ └── CustomJobExceptionHandler.java │ │ ├── service │ │ ├── BlockAsyncService.java │ │ ├── BlockCheckService.java │ │ ├── BlockCrawlService.java │ │ ├── BlockDataResetService.java │ │ ├── BlockDepotService.java │ │ ├── BlockIndexService.java │ │ ├── BlockListenerService.java │ │ ├── BlockPrepareService.java │ │ ├── BlockStoreService.java │ │ └── RollBackService.java │ │ ├── task │ │ ├── CrawlRunner.java │ │ ├── DataExportExecutor.java │ │ ├── DataPersistenceManager.java │ │ ├── DepotJob.java │ │ └── PrepareTaskJob.java │ │ └── tools │ │ ├── DataSourceUtils.java │ │ └── ElasticJobUtil.java ├── WeBankBlockchain-Data-Export-db │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── webank │ │ └── blockchain │ │ └── data │ │ └── export │ │ └── db │ │ ├── dao │ │ ├── BlockDetailInfoDAO.java │ │ ├── BlockRawDataDAO.java │ │ ├── BlockTxDetailInfoDAO.java │ │ ├── ContractInfoDAO.java │ │ ├── DeployedAccountInfoDAO.java │ │ ├── ESHandleDao.java │ │ ├── MethodAndEventDao.java │ │ ├── SaveInterface.java │ │ ├── TxRawDataDAO.java │ │ └── TxReceiptRawDataDAO.java │ │ ├── entity │ │ ├── BlockDetailInfo.java │ │ ├── BlockRawData.java │ │ ├── BlockTaskPool.java │ │ ├── BlockTxDetailInfo.java │ │ ├── ContractInfo.java │ │ ├── DeployedAccountInfo.java │ │ ├── IdEntity.java │ │ ├── TxRawData.java │ │ └── TxReceiptRawData.java │ │ ├── repository │ │ ├── BlockDetailInfoRepository.java │ │ ├── BlockRawDataRepository.java │ │ ├── BlockTaskPoolRepository.java │ │ ├── BlockTxDetailInfoRepository.java │ │ ├── ContractInfoRepository.java │ │ ├── DeployedAccountInfoRepository.java │ │ ├── RollbackInterface.java │ │ ├── TxRawDataRepository.java │ │ └── TxReceiptRawDataRepository.java │ │ ├── service │ │ ├── DataStoreService.java │ │ ├── ESService.java │ │ ├── ESStoreService.java │ │ └── MysqlStoreService.java │ │ └── tools │ │ └── BeanUtils.java ├── WeBankBlockchain-Data-Export-parser │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── webank │ │ └── blockchain │ │ └── data │ │ └── export │ │ └── parser │ │ ├── contract │ │ ├── ContractParser.java │ │ ├── EventParser.java │ │ └── MethodParser.java │ │ ├── enums │ │ └── JavaTypeEnum.java │ │ ├── facade │ │ └── ParseFacade.java │ │ ├── handler │ │ ├── BlockCrawlerHandler.java │ │ ├── ContractCrawlerHandler.java │ │ ├── EventCrawlerHandler.java │ │ └── MethodCrawlerHandler.java │ │ ├── service │ │ ├── ContractConstructorService.java │ │ └── TransactionService.java │ │ └── tools │ │ ├── ABIUtils.java │ │ ├── SolJavaTypeMappingUtils.java │ │ └── SolSqlTypeMappingUtils.java ├── build.gradle ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── webank │ │ │ └── blockchain │ │ │ └── data │ │ │ └── export │ │ │ └── ExportDataSDK.java │ └── resources │ │ └── logback.xml │ └── test │ └── java │ └── com │ └── webank │ └── blockchain │ └── data │ └── export │ └── sdk │ └── test │ └── ExportDataTest.java ├── WeBankBlockchain-Data-Export-service ├── .gitignore ├── .travis.yml ├── build.gradle ├── data-export-docker │ ├── build_export.sh │ └── config │ │ ├── abi │ │ └── HelloWorld.abi │ │ ├── application.properties │ │ └── bin │ │ └── HelloWorld.bin ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── webank │ │ │ └── blockchain │ │ │ └── data │ │ │ └── export │ │ │ ├── App.java │ │ │ ├── config │ │ │ └── ServiceConfig.java │ │ │ ├── contract │ │ │ ├── ContractParser.java │ │ │ ├── EventParser.java │ │ │ └── MethodParser.java │ │ │ ├── grafana │ │ │ ├── AtomicParas.java │ │ │ ├── GrafanaConstant.java │ │ │ ├── GrafanaDashboardParas.java │ │ │ ├── GrafanaGenerateService.java │ │ │ ├── GrafanaPanelTableParasEvent.java │ │ │ ├── GrafanaPanelTableParasMethod.java │ │ │ └── GrafanaParas.java │ │ │ ├── service │ │ │ └── ExportService.java │ │ │ └── utils │ │ │ └── PropertiesUtils.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ └── grafana │ │ ├── dashboard_default.txt │ │ └── panel_table.txt │ └── test │ └── java │ └── com │ └── webank │ └── blockchain │ └── data │ └── export │ ├── grafana │ └── GrafanaDashboardParasTest.java │ └── utils │ └── PropertiesUtilsTest.java ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── tools ├── config ├── application.properties └── solidity │ └── HelloWorld.sol ├── start.sh └── stop.sh /.gitignore: -------------------------------------------------------------------------------- 1 | ### common ### 2 | log/ 3 | src/main/resources 4 | src/test/resources 5 | 6 | ### mac ### 7 | .DS_Store 8 | 9 | ### gradle ### 10 | .gradle/ 11 | build 12 | dist/ 13 | 14 | ## eclipse ## 15 | .classpath 16 | .project 17 | .settings 18 | bin/ 19 | out/ 20 | conf/ 21 | 22 | ## integration test files 23 | nodes/ 24 | src/integration-test/resources/ 25 | build_chain.sh 26 | 27 | ### STS ### 28 | .apt_generated 29 | .factorypath 30 | .springBeans 31 | .sts4-cache 32 | 33 | ### IntelliJ IDEA ### 34 | .idea 35 | *.iws 36 | *.iml 37 | *.ipr 38 | 39 | ### NetBeans ### 40 | /nbproject/private/ 41 | /build/ 42 | /nbbuild/ 43 | /dist/ 44 | /nbdist/ 45 | /.nb-gradle/ 46 | 47 | ### Compiled class file ### 48 | *.class 49 | 50 | ### Log file ### 51 | *.log 52 | 53 | ### BlueJ files ### 54 | *.ctxt 55 | 56 | ### Mobile Tools for Java (J2ME) ### 57 | .mtj.tmp/ 58 | 59 | ### Package Files ### 60 | *.jar 61 | *.war 62 | *.nar 63 | *.ear 64 | *.zip 65 | *.tar.gz 66 | *.rar 67 | 68 | ### virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml ### 69 | hs_err_pid* 70 | 71 | ### repo ### 72 | config/ 73 | generated -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # WeBankBlockchain-Data-Export 3 | 4 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 5 | 6 | > 穿花度柳飞如箭, 7 | > 粘絮寻香似落星。 8 | > 小小微躯能负重, 9 | > 器器薄翅会乘风。 10 | > -- 吴承恩 11 | 12 | 13 | WeBankBlockchain-Data-Export 是一个基于[FISCO-BCOS](https://github.com/FISCO-BCOS/FISCO-BCOS)平台的数据导出工具。 14 | 15 | 数据导出组件WeBankBlockchain-Data-Export的目的在于降低获取区块链数据的开发门槛,提升研发效率。研发人员几乎不需要编写任何代码,只需要进行简单配置,就可以把数据导出到Mysql数据库。 16 | 17 | WeBankBlockchain-Data-Export可以导出区块链上的基础数据,如当前块高、交易总量等。如果配置了FISCO-BCOS上运行合约的相关信息,还可导出链上合约的业务数据,包括event、构造函数、合约地址、执行函数的信息等。 18 | 19 | **此版本只支持**[FISCO BCOS 2.0](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/)及以上版本。 20 | 21 | 22 | ## 关键特性 23 | 24 | - 支持JSON-RPC、Channel通道、数据仓库源等方式导出数据 25 | 26 | - 支持服务和docker方式部署 27 | 28 | - 支持多数据源,支持分库分表 29 | 30 | - 支持ES存储 31 | 32 | - 支持多活部署,多节点自动导出 33 | 34 | - 支持自定义导出数据内容 35 | 36 | - 提供SDK的集成方式 37 | 38 | - 支持可视化的监控页面 39 | 40 | 41 | ## 环境要求 42 | 43 | 在使用本组件前,请确认系统环境已安装相关依赖软件,清单如下: 44 | 45 | | 依赖软件 | 说明 |备注| 46 | | --- | --- | --- | 47 | | FISCO-BCOS | >= 2.0, 1.x版本请参考V0.5版本 dev分支 | 48 | | Bash | 需支持Bash(理论上来说支持所有ksh、zsh等其他unix shell,但未测试)| 49 | | Java | JDK[1.8] || 50 | | Git | 下载的安装包使用Git | | 51 | | MySQL | >= mysql-community-server[5.7] | 理论上来说支持主流数据库,但未测试| 52 | | zookeeper | >= zookeeper[3.4] | 只有在进行集群部署的时候需要安装| 53 | | docker | >= docker[18.0.0] | 只有需要可视化监控页面的时候才需要安装| 54 | | ElasticSearch | >= elasticsearch [7.0] | 只有在需要ES存储时安装 | 55 | 56 | 57 | ## 文档 58 | - [**中文**](https://data-doc.readthedocs.io/zh_CN/latest/docs/WeBankBlockchain-Data-Export/index.html) 59 | - [**快速安装**](https://data-doc.readthedocs.io/zh_CN/latest/docs/WeBankBlockchain-Data-Export/install.html) 60 | 61 | 62 | ## 贡献代码 63 | 欢迎参与本项目的社区建设: 64 | - 如项目对您有帮助,欢迎点亮我们的小星星(点击项目右上方Star按钮)。 65 | - 欢迎提交代码(Pull requests)。 66 | - [提问和提交BUG](https://github.com/WeBankBlockchain/WeBankBlockchain-Data-Export/issues)。 67 | - 如果发现代码存在安全漏洞,请在[这里](https://security.webank.com)上报。 68 | 69 | 70 | ## License 71 | ![license](http://img.shields.io/badge/license-Apache%20v2-blue.svg) 72 | 73 | 开源协议为[Apache License 2.0](http://www.apache.org/licenses/). 详情参考[LICENSE](../LICENSE)。 74 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | /bin/ 4 | bin/* 5 | config/* 6 | /.gradle/ 7 | 8 | 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | /nbproject/private/ 27 | /build/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | src/main/scripts 34 | src/main/resources 35 | 36 | ## contracts ## 37 | src/main/java/com/webank/bcosexport/generated 38 | src/main/java/com/webank/blockchain.data.export/generated 39 | src/main/java/org 40 | my.log* 41 | *.log 42 | 43 | src/test/java/com/webank/webaseexport/contract/ 44 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/build.gradle: -------------------------------------------------------------------------------- 1 | clean { 2 | println "delete ${projectDir}/dist" 3 | delete "${projectDir}/dist" 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/contract/ContractDetail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.contract; 15 | 16 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 17 | import lombok.Data; 18 | import lombok.experimental.Accessors; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * ContractMethodInfo 24 | * 25 | * @Description: ContractMethodInfo storages all contracts info for parsing method data. 26 | * @author graysonzhang 27 | * @data 2018-12-17 11:48:31 28 | * 29 | */ 30 | @Data 31 | @Accessors(chain = true) 32 | public class ContractDetail { 33 | 34 | private ContractInfoBO contractInfoBO; 35 | 36 | private List methodMetaInfos; 37 | 38 | private List eventMetaInfos; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/contract/ContractMapsInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.contract; 15 | 16 | import lombok.Data; 17 | import lombok.experimental.Accessors; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * ContractMapsInfo 23 | * 24 | * @Description: ContractMapsInfo storages contract info, that will used to parse method data. 25 | * @author graysonzhang 26 | * @data 2018-12-17 14:55:20 27 | * 28 | */ 29 | @Data 30 | @Accessors(chain = true) 31 | public class ContractMapsInfo { 32 | 33 | /** @Fields methodIdMap : use to storage methodId map , key:methodId, value:(contractName, methodName) */ 34 | private Map methodIdMap; 35 | 36 | /** @Fields contractBinaryMap : use to storage contract binary map, key:contract binary, value:contract name */ 37 | private Map contractBinaryMap; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/contract/EventMetaInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.contract; 15 | 16 | import lombok.Data; 17 | import lombok.NoArgsConstructor; 18 | import lombok.experimental.Accessors; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * EventMetaInfo 24 | * 25 | * @Description: EventMetaInfo storages event config data for parsing event data 26 | * @author maojiayu 27 | * @author graysonzhang 28 | * @data 2018-11-08 22:03:20 29 | * 30 | */ 31 | @Data 32 | @NoArgsConstructor 33 | @Accessors(chain = true) 34 | public class EventMetaInfo { 35 | 36 | /** @Fields eventName : event name */ 37 | private String eventName; 38 | 39 | /** @Fields contractName : contract name */ 40 | private String contractName; 41 | 42 | /** @Fields list : event filed list */ 43 | private List list; 44 | } 45 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/contract/FieldVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.contract; 15 | 16 | import lombok.Data; 17 | import lombok.experimental.Accessors; 18 | 19 | /** 20 | * FieldVO stores one single field of a contract field. 21 | * 22 | * @author maojiayu 23 | * @data Dec 28, 2018 5:06:04 PM 24 | * 25 | */ 26 | @Data 27 | @Accessors(chain = true) 28 | public class FieldVO { 29 | private String sqlName; 30 | private String solidityName; 31 | private String javaName; 32 | private String sqlType; 33 | private String solidityType; 34 | private String javaType; 35 | private String javaCapName; // 首字母大写 36 | private String typeMethod; // 转化方法 37 | 38 | } 39 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/contract/MethodMetaInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.contract; 15 | 16 | import java.util.List; 17 | 18 | import lombok.Data; 19 | import lombok.experimental.Accessors; 20 | 21 | /** 22 | * MethodMetaInfo 23 | * 24 | * @Description: MethodMetaInfo storages method config data for parsing method data. 25 | * @author graysonzhang 26 | * @data 2018-12-17 14:20:00 27 | * 28 | */ 29 | @Data 30 | @Accessors(chain = true) 31 | public class MethodMetaInfo { 32 | 33 | /** @Fields methodId : method id */ 34 | private String methodId; 35 | 36 | /** @Fields methodName : method name */ 37 | private String methodName; 38 | 39 | private String originName; 40 | 41 | private String type; 42 | 43 | /** @Fields contractName : contract name */ 44 | private String contractName; 45 | 46 | /** @Fields fieldsList : method input param list */ 47 | private List fieldsList; 48 | 49 | private List outputList; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/BlockContractInfoBO.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.bo.data; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author wesleywang 12 | * @Description: 13 | * @date 2020/10/26 14 | */ 15 | @Data 16 | @AllArgsConstructor 17 | @Accessors(chain = true) 18 | public class BlockContractInfoBO { 19 | 20 | private Map txHashContractAddressMapping; 21 | 22 | private List deployedAccountInfoBOS; 23 | } 24 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/BlockDetailInfoBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import lombok.Data; 17 | import lombok.experimental.Accessors; 18 | 19 | import java.util.Date; 20 | 21 | /** 22 | * BlockDetailInfo 23 | * 24 | * @Description: BlockDetailInfo 25 | * @author maojiayu 26 | * @data Jul 1, 2019 4:16:27 PM 27 | * 28 | */ 29 | @Data 30 | @Accessors(chain = true) 31 | public class BlockDetailInfoBO { 32 | 33 | /** @Fields blockHeight : block height */ 34 | private long blockHeight; 35 | 36 | /** @Fields blockHash : block hash */ 37 | private String blockHash; 38 | 39 | /** @Fields txCount : transaction's count in block */ 40 | private int txCount; 41 | 42 | /** @Fields blockTimeStamp : block timestamp */ 43 | private Date blockTimeStamp; 44 | 45 | private short status; 46 | 47 | public enum Status { 48 | TODO, COMPLETED 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/BlockInfoBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import lombok.Data; 17 | import lombok.experimental.Accessors; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * BlockInfoBO 23 | * 24 | * @Description: BlockInfoBO 25 | * @author maojiayu 26 | * @data Jul 1, 2019 8:55:51 PM 27 | * 28 | */ 29 | @Data 30 | @Accessors(chain = true) 31 | public class BlockInfoBO { 32 | private BlockDetailInfoBO blockDetailInfo; 33 | 34 | private BlockRawDataBO blockRawDataBO; 35 | 36 | private List txRawDataBOList; 37 | 38 | private List deployedAccountInfoBOS; 39 | 40 | private List txReceiptRawDataBOList; 41 | 42 | private List blockTxDetailInfoList; 43 | 44 | private List eventInfoList; 45 | 46 | private List methodInfoList; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/BlockMethodInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import lombok.Data; 17 | import lombok.experimental.Accessors; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * BlockMethodInfo 24 | * 25 | * @Description: BlockMethodInfo 26 | * @author maojiayu 27 | * @data Jul 3, 2019 2:59:33 PM 28 | * 29 | */ 30 | @Data 31 | @Accessors(chain = true) 32 | public class BlockMethodInfo { 33 | 34 | private List blockTxDetailInfoList; 35 | 36 | private List txRawDataBOList; 37 | 38 | private List txReceiptRawDataBOList; 39 | 40 | private List methodInfoList; 41 | 42 | private Map txHashContractNameMapping; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/BlockRawDataBO.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.bo.data; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2020/10/23 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | public class BlockRawDataBO { 16 | 17 | private String blockHash; 18 | private long blockHeight; 19 | private String blockObject; 20 | private Date blockTimeStamp; 21 | private String parentHash; 22 | private String logsBloom; 23 | private String transactionsRoot; 24 | private String receiptsRoot; 25 | private String dbHash; 26 | private String stateRoot; 27 | private String sealer; 28 | private String sealerList; 29 | private String extraData; 30 | private String gasLimit; 31 | private String gasUsed; 32 | private String signatureList; 33 | private String transactionList; 34 | } 35 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/BlockTxDetailInfoBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import com.fasterxml.jackson.annotation.JsonInclude; 17 | import lombok.Data; 18 | import lombok.experimental.Accessors; 19 | 20 | import java.util.Date; 21 | 22 | /** 23 | * BlockTxDetailInfo 24 | * 25 | * @Description: BlockTxDetailInfo 26 | * @author maojiayu 27 | * @data Jul 1, 2019 4:16:12 PM 28 | * 29 | */ 30 | @Data 31 | @Accessors(chain = true) 32 | @JsonInclude(JsonInclude.Include.NON_NULL) 33 | public class BlockTxDetailInfoBO { 34 | 35 | /** @Fields blockHeight : block height */ 36 | private String blockHeight; 37 | 38 | /** @Fields blockHash : block hash */ 39 | private String blockHash; 40 | 41 | /** @Fields contractName : contract name */ 42 | private String contractName; 43 | 44 | /** @Fields methodName : contract method name */ 45 | private String methodName; 46 | 47 | /** @Fields txHash : transaction hash */ 48 | private String txHash; 49 | 50 | /** @Fields txFrom : transaction' s from */ 51 | private String txFrom; 52 | 53 | /** @Fields txTo : transaction's to */ 54 | private String txTo; 55 | 56 | /** @Fields blockTimeStamp : block timestamp */ 57 | private Date blockTimeStamp; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/CommonBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import lombok.Data; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * CommonBO 22 | * 23 | * @Description: CommonBO 24 | * @author maojiayu 25 | * @data Jul 7, 2019 3:05:17 PM 26 | * 27 | */ 28 | @Data 29 | public class CommonBO { 30 | private String table; 31 | private Map entity; 32 | } 33 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/ContractInfoBO.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.bo.data; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | /** 8 | * @author wesleywang 9 | * @Description: 10 | * @date 2020/10/26 11 | */ 12 | @Data 13 | @Accessors(chain = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | public class ContractInfoBO { 16 | 17 | private String contractName; 18 | 19 | private String contractBinary; 20 | 21 | private String contractABI; 22 | 23 | private short version; 24 | 25 | private String abiHash; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/DeployedAccountInfoBO.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.bo.data; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @author wesleywang 11 | * @Description: 12 | * @date 2020/10/26 13 | */ 14 | @Data 15 | @Accessors(chain = true) 16 | @JsonInclude(JsonInclude.Include.NON_NULL) 17 | public class DeployedAccountInfoBO { 18 | 19 | private String contractName; 20 | 21 | private String contractAddress; 22 | 23 | private long blockHeight; 24 | 25 | private Date blockTimeStamp; 26 | 27 | private String abiHash; 28 | 29 | private String txHash; 30 | 31 | private String binary; 32 | } 33 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/EventBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.experimental.Accessors; 19 | 20 | /** 21 | * EventBo 22 | * 23 | * @Description: EventBo 24 | * @author maojiayu 25 | * @data Jul 2, 2019 3:34:31 PM 26 | * 27 | */ 28 | @Data 29 | @EqualsAndHashCode(callSuper = false) 30 | @Accessors(chain = true) 31 | public class EventBO extends CommonBO{ 32 | 33 | private String toAddress; 34 | } 35 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/MethodBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.bo.data; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.experimental.Accessors; 19 | 20 | /** 21 | * EventBo 22 | * 23 | * @Description: EventBo 24 | * @author maojiayu 25 | * @data Jul 2, 2019 3:34:31 PM 26 | * 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | @EqualsAndHashCode(callSuper = false) 31 | public class MethodBO extends CommonBO{ 32 | 33 | private String toAddress; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/TxRawDataBO.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.bo.data; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2020/10/26 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | public class TxRawDataBO { 16 | 17 | private long blockHeight; 18 | 19 | private String blockHash; 20 | 21 | private String txHash; 22 | 23 | private String txIndex; 24 | 25 | private Date blockTimeStamp; 26 | 27 | private String from; 28 | private String gas; 29 | private String input; 30 | private String nonce; 31 | private String to; 32 | private String value; 33 | private String gasPrice; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/bo/data/TxReceiptRawDataBO.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.bo.data; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * @author wesleywang 11 | * @Description: 12 | * @date 2020/10/26 13 | */ 14 | @Data 15 | @Accessors(chain = true) 16 | @JsonInclude(JsonInclude.Include.NON_NULL) 17 | public class TxReceiptRawDataBO { 18 | 19 | private long blockHeight; 20 | 21 | private String blockHash; 22 | 23 | private String txHash; 24 | 25 | private Date blockTimeStamp; 26 | 27 | private String txIndex; 28 | private String root; 29 | private String from; 30 | private String to; 31 | private String gasUsed; 32 | private String contractAddress; 33 | private String logs; 34 | private String logsBloom; 35 | private String status; 36 | private String input; 37 | private String output; 38 | private String txProof; 39 | private String receiptProof; 40 | private String message; 41 | } 42 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/client/ChainClient.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.client; 2 | 3 | 4 | import org.fisco.bcos.sdk.client.protocol.response.BcosBlock; 5 | import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; 6 | import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; 7 | import org.fisco.bcos.sdk.crypto.CryptoSuite; 8 | 9 | import java.math.BigInteger; 10 | 11 | /** 12 | * @author wesleywang 13 | * @Description: 14 | * @date 2021/2/25 15 | */ 16 | public interface ChainClient { 17 | 18 | BcosBlock.Block getBlockByNumber(BigInteger blockNumber); 19 | 20 | BigInteger getBlockNumber(); 21 | 22 | String getCode(String address); 23 | 24 | CryptoSuite getCryptoSuite(); 25 | 26 | BcosTransaction getTransactionByHash(String transactionHash); 27 | 28 | BcosTransactionReceipt getTransactionReceipt(String transactionHash); 29 | } 30 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/client/ChannelClient.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.client; 2 | 3 | import com.webank.blockchain.data.export.common.entity.ChainInfo; 4 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 5 | import com.webank.blockchain.data.export.common.tools.ClientUtil; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.fisco.bcos.sdk.client.Client; 8 | import org.fisco.bcos.sdk.client.protocol.response.BcosBlock; 9 | import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; 10 | import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; 11 | import org.fisco.bcos.sdk.config.exceptions.ConfigException; 12 | import org.fisco.bcos.sdk.crypto.CryptoSuite; 13 | 14 | import java.math.BigInteger; 15 | 16 | /** 17 | * @author wesleywang 18 | * @Description: 19 | * @date 2021/2/25 20 | */ 21 | @Slf4j 22 | public class ChannelClient implements ChainClient { 23 | 24 | private Client client; 25 | 26 | public ChannelClient() throws ConfigException { 27 | ChainInfo chainInfo = ExportConstant.getCurrentContext().getChainInfo(); 28 | try { 29 | client = ClientUtil.getClient(chainInfo); 30 | } catch (ConfigException e) { 31 | log.error("channel client build failed , reason : ", e); 32 | throw e; 33 | } 34 | } 35 | 36 | @Override 37 | public BcosBlock.Block getBlockByNumber(BigInteger blockNumber) { 38 | return client.getBlockByNumber(blockNumber,true).getBlock(); 39 | } 40 | 41 | @Override 42 | public BigInteger getBlockNumber() { 43 | return client.getBlockNumber().getBlockNumber(); 44 | } 45 | 46 | @Override 47 | public String getCode(String address) { 48 | return client.getCode(address).getCode(); 49 | } 50 | 51 | @Override 52 | public CryptoSuite getCryptoSuite() { 53 | return client.getCryptoSuite(); 54 | } 55 | 56 | @Override 57 | public BcosTransaction getTransactionByHash(String transactionHash) { 58 | return client.getTransactionByHash(transactionHash); 59 | } 60 | 61 | @Override 62 | public BcosTransactionReceipt getTransactionReceipt(String hash) { 63 | return client.getTransactionReceipt(hash); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/client/StashClient.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.client; 2 | 3 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 4 | import com.webank.blockchain.data.export.common.stash.DataStashMysqlRepo; 5 | import com.webank.blockchain.data.export.common.stash.StashBlockDataParser; 6 | import lombok.Data; 7 | import org.fisco.bcos.sdk.client.protocol.response.BcosBlock; 8 | import org.fisco.bcos.sdk.client.protocol.response.BcosTransaction; 9 | import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; 10 | import org.fisco.bcos.sdk.crypto.CryptoSuite; 11 | 12 | import java.math.BigInteger; 13 | 14 | /** 15 | * @author wesleywang 16 | * @Description: 17 | * @date 2021/3/3 18 | */ 19 | @Data 20 | public class StashClient implements ChainClient { 21 | 22 | private DataStashMysqlRepo stashMysqlRepo; 23 | 24 | private StashBlockDataParser blockDataParser; 25 | 26 | private CryptoSuite cryptoSuite; 27 | 28 | public StashClient () { 29 | cryptoSuite = new CryptoSuite(ExportConstant.getCurrentContext().getStashInfo().getCryptoTypeConfig()); 30 | stashMysqlRepo = DataStashMysqlRepo.create(); 31 | blockDataParser = new StashBlockDataParser(stashMysqlRepo, cryptoSuite); 32 | } 33 | 34 | @Override 35 | public BcosBlock.Block getBlockByNumber(BigInteger blockNumber) { 36 | String blockStr = stashMysqlRepo.queryBlock(blockNumber.longValue()); 37 | return blockDataParser.parse(blockStr); 38 | } 39 | 40 | @Override 41 | public BigInteger getBlockNumber() { 42 | long blockNumber = stashMysqlRepo.queryBlockNumber(); 43 | return BigInteger.valueOf(blockNumber); 44 | } 45 | 46 | @Override 47 | public String getCode(String address) { 48 | return stashMysqlRepo.queryCode(address); 49 | } 50 | 51 | @Override 52 | public CryptoSuite getCryptoSuite() { 53 | return cryptoSuite; 54 | } 55 | 56 | @Override 57 | public BcosTransaction getTransactionByHash(String transactionHash) { 58 | return blockDataParser.getTransaction(transactionHash); 59 | } 60 | 61 | @Override 62 | public BcosTransactionReceipt getTransactionReceipt(String transactionHash) { 63 | return blockDataParser.getReceipt(transactionHash); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/constants/AbiTypeConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.constants; 15 | 16 | /** 17 | * AbiTypeConstants 18 | * 19 | * @Description: AbiTypeConstants 20 | * @author graysonzhang 21 | * @data 2018-12-4 20:02:13 22 | * 23 | */ 24 | public class AbiTypeConstants { 25 | 26 | /** @Fields ABI_FUNCTION_TYPE : contract function type */ 27 | public static final String ABI_FUNCTION_TYPE = "function"; 28 | 29 | /** @Fields ABI_CONSTRUCTOR_TYPE : contract constructor type */ 30 | public static final String ABI_CONSTRUCTOR_TYPE = "constructor"; 31 | 32 | /** @Fields ABI_EVENT_TYPE : contract event type */ 33 | public static final String ABI_EVENT_TYPE = "event"; 34 | 35 | /** @Fields ABI_CONST_TYPE : contract const method type */ 36 | public static final String ABI_CONST_TYPE = "const"; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/constants/BinConstant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.constants; 15 | 16 | /** 17 | * BinConstant 18 | * 19 | * @Description: BinConstant 20 | * @author maojiayu 21 | * @data Jun 13, 2019 3:08:06 PM 22 | * 23 | */ 24 | public class BinConstant { 25 | 26 | public static final int META_DATA_HASH_LENGTH = 64 + 4; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/constants/BlockConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.constants; 15 | 16 | /** 17 | * BlockForkConstants 18 | * 19 | * @Description: BlockForkConstants 20 | * @author maojiayu 21 | * @data Apr 1, 2019 3:56:30 PM 22 | * 23 | */ 24 | public class BlockConstants { 25 | 26 | public static final int MAX_FORK_CERTAINTY_BLOCK_NUMBER = 6; 27 | public static final int DEPOT_TIME_OUT = 300; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/constants/ContractConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.constants; 15 | 16 | import com.webank.blockchain.data.export.common.bo.contract.ContractMapsInfo; 17 | 18 | /** 19 | * ContractConstants 20 | * 21 | * @Description: ContractConstants 22 | * @author maojiayu 23 | * @data Jul 23, 2019 10:19:34 AM 24 | * 25 | */ 26 | public class ContractConstants { 27 | 28 | public static final String EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000"; 29 | 30 | public final static ThreadLocal contractMapsInfo = new ThreadLocal<>(); 31 | 32 | 33 | public static ContractMapsInfo getCurrentContractMaps() { 34 | return contractMapsInfo.get(); 35 | } 36 | 37 | public static void setCurrentContractMaps(ContractMapsInfo maps) { 38 | contractMapsInfo.set(maps); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/constants/StatusCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.constants; 15 | 16 | /** 17 | * Common Status Code. 18 | * 19 | * @author maojiayu 20 | * @data Dec 28, 2018 5:24:46 PM 21 | * 22 | */ 23 | public class StatusCode { 24 | public static int SUCCESS = 0; // 成功 25 | public static int EXECUTE_ERROR = 2; // 执行错误 26 | public static int SESSION_EXPIRED = 3; // 会话已经过期,请重新登录 27 | public static int UNAUTH = 4; // 用户无权限访问 28 | public static int APP_OUTER_DEPENDENCY_ERROR = 5; // 外部依赖错误 29 | public static int EXCEPTION_OCCUR = 6; // 发生异常 30 | public static int PARAMETER_ERROR = 7; // 参数错误 31 | public static int RESULT_EMPTY = 8; // 不存在请求内容 32 | public static int STATUS_ERROR = 9; // 状态错误 33 | } 34 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/BlockDataSource.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | /** 4 | * @author wesleywang 5 | * @Description: 6 | * @date 2021/3/3 7 | */ 8 | public class BlockDataSource { 9 | } 10 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/ChainInfo.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | /** 8 | * @author wesleywang 9 | * @Description: 10 | * @date 2020/12/16 11 | */ 12 | @EqualsAndHashCode(callSuper = true) 13 | @Data 14 | @Builder 15 | public class ChainInfo extends BlockDataSource { 16 | 17 | private String nodeStr; 18 | private int groupId; 19 | private String certPath; 20 | //0-ECDSA,1-SM 21 | private int cryptoTypeConfig; 22 | private String rpcUrl; 23 | } 24 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/ContractInfo.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | /** 7 | * @author wesleywang 8 | * @Description: 9 | * @date 2020/12/25 10 | */ 11 | @Data 12 | @Accessors(chain = true) 13 | public class ContractInfo { 14 | 15 | private String contractName; 16 | 17 | private String abi; 18 | 19 | private String binary; 20 | 21 | private short version; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/DataExportContext.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import com.webank.blockchain.data.export.common.client.ChainClient; 4 | import com.webank.blockchain.data.export.common.subscribe.TopicRegistry; 5 | import lombok.Data; 6 | import org.elasticsearch.client.transport.TransportClient; 7 | import org.fisco.bcos.sdk.transaction.codec.decode.TransactionDecoderInterface; 8 | 9 | import javax.sql.DataSource; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author wesleywang 14 | * @Description: 15 | * @date 2020/12/16 16 | */ 17 | @Data 18 | @SuppressWarnings("deprecation") 19 | public class DataExportContext { 20 | 21 | private DataSource dataSource; 22 | 23 | private ExportDataSource exportDataSource; 24 | 25 | private TransportClient esClient; 26 | 27 | private ESDataSource esConfig; 28 | 29 | private ChainInfo chainInfo; 30 | 31 | private StashInfo stashInfo; 32 | 33 | private DataSource stashDataSource; 34 | 35 | private ExportConfig config; 36 | 37 | private ChainClient client; 38 | 39 | private boolean autoCreateTable; 40 | 41 | private TransactionDecoderInterface decoder; 42 | 43 | private Map contractInfoMap; 44 | 45 | private TopicRegistry topicRegistry; 46 | 47 | public String sqlScript = String.format("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 48 | TableSQL.BLOCK_DETAIL_INFO, TableSQL.BLOCK_RAW_DATA, TableSQL.BLOCK_TASK_POOL, 49 | TableSQL.BLOCK_TX_DETAIL_INFO, TableSQL.DEPLOYED_ACCOUNT_INFO, 50 | TableSQL.TX_RECEIPT_RAW_DATA, TableSQL.TX_RAW_DATA, TableSQL.CONTRACT_INFO); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/ESDataSource.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author wesleywang 7 | * @Description: 8 | * @date 2020/12/17 9 | */ 10 | @Data 11 | public class ESDataSource { 12 | 13 | private boolean enable; 14 | private String clusterName; 15 | private String ip; 16 | private int port; 17 | } 18 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/ExportConfig.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import com.webank.blockchain.data.export.common.enums.DataType; 4 | import com.webank.blockchain.data.export.common.subscribe.TopicRegistry; 5 | import lombok.Data; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * @author wesleywang 13 | * @Description: 14 | * @date 2020/12/16 15 | */ 16 | @Data 17 | public class ExportConfig { 18 | 19 | private int crawlBatchUnit = 1000; 20 | private long frequency = 5; 21 | 22 | private long startBlockHeight = 0; 23 | private String startDate; 24 | 25 | private List dataTypeBlackList = DataType.getDefault(); 26 | 27 | /** 28 | * ex: Map 29 | */ 30 | private Map> generatedOff = new HashMap<>(); 31 | 32 | /** 33 | * ex: Map>> 34 | */ 35 | private Map>> ignoreParam = new HashMap<>(); 36 | 37 | /** 38 | * ex: Map>> 39 | */ 40 | private Map> ignoreBasicDataTableParam = new HashMap<>(); 41 | 42 | /** 43 | * ex: Map>> 44 | */ 45 | private Map>> paramSQLType = new HashMap<>(); 46 | 47 | private String tablePrefix = ""; 48 | 49 | private String tablePostfix= ""; 50 | 51 | private String namePrefix = ""; 52 | 53 | private String namePostfix = ""; 54 | 55 | private List contractInfoList; 56 | 57 | private boolean multiLiving; 58 | private String zookeeperServiceLists; 59 | private String zookeeperNamespace; 60 | private String prepareTaskJobCron = "0/"+ frequency + " * * * * ?"; 61 | private String dataFlowJobCron = "0/"+ frequency + " * * * * ?"; 62 | private String dataFlowJobItemParameters = "0=A,1=B,2=C,3=D,4=E,5=F,6=G,7=H"; 63 | private int dataFlowJobShardingTotalCount = 8; 64 | private TopicRegistry topicRegistry = new TopicRegistry(); 65 | } 66 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/ExportConstant.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | 4 | import cn.hutool.db.DbUtil; 5 | import cn.hutool.log.level.Level; 6 | import com.google.common.collect.Lists; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author wesleywang 12 | * @Description: 13 | * @date 2020/12/16 14 | */ 15 | public class ExportConstant { 16 | 17 | static { 18 | DbUtil.setShowSqlGlobal(true,false,true, Level.INFO); 19 | } 20 | 21 | public static final ThreadLocal context = new ThreadLocal<>(); 22 | 23 | public static DataExportContext getCurrentContext() { 24 | return context.get(); 25 | } 26 | 27 | public static void setCurrentContext(DataExportContext currentContext) { 28 | context.set(currentContext); 29 | } 30 | 31 | public static final String BLOCK_TASK_POOL_DAO = "block_task_pool_dao"; 32 | 33 | public static final String BLOCK_DETAIL_DAO = "block_detail_info_dao"; 34 | 35 | public static final String BLOCK_RAW_DAO = "block_raw_data_dao"; 36 | 37 | public static final String BLOCK_TX_DETAIL_DAO = "block_tx_detail_info_dao"; 38 | 39 | public static final String TX_RAW_DAO = "tx_raw_data_dao"; 40 | 41 | public static final String TX_RECEIPT_RAW_DAO = "tx_receipt_raw_data_dao"; 42 | 43 | public static final String DEPLOYED_ACCOUNT_DAO = "deployed_account_info_dao"; 44 | 45 | public static final String CONTRACT_INFO_DAO = "contract_info_dao"; 46 | 47 | public static final String BLOCK_DETAIL_INFO_TABLE = "block_detail_info"; 48 | 49 | public static final String BLOCK_TASK_POOL_TABLE = "block_task_pool"; 50 | 51 | public static final String BLOCK_RAW_DATA_TABLE = "block_raw_data"; 52 | 53 | public static final String BLOCK_TX_DETAIL_INFO_TABLE = "block_tx_detail_info"; 54 | 55 | public static final String DEPLOYED_ACCOUNT_INFO_TABLE = "deployed_account_info"; 56 | 57 | public static final String TX_RAW_DATA_TABLE = "tx_raw_data"; 58 | 59 | public static final String TX_RECEIPT_RAW_DATA_TABLE = "tx_receipt_raw_data"; 60 | 61 | public static final String CONTRACT_INFO_TABLE = "contract_info"; 62 | 63 | public static final List tables = Lists.newArrayList( 64 | BLOCK_DETAIL_INFO_TABLE, 65 | BLOCK_TASK_POOL_TABLE, 66 | BLOCK_RAW_DATA_TABLE, 67 | BLOCK_TX_DETAIL_INFO_TABLE, 68 | DEPLOYED_ACCOUNT_INFO_TABLE, 69 | TX_RAW_DATA_TABLE, 70 | TX_RECEIPT_RAW_DATA_TABLE, 71 | CONTRACT_INFO_TABLE); 72 | } 73 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/ExportDataSource.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2020/12/16 12 | */ 13 | @Data 14 | @Builder 15 | public class ExportDataSource { 16 | 17 | private boolean autoCreateTable; 18 | 19 | private boolean sharding; 20 | 21 | private int shardingNumberPerDatasource; 22 | 23 | private List mysqlDataSources; 24 | 25 | private ESDataSource esDataSource; 26 | } 27 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/MysqlDataSource.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author wesleywang 8 | * @Description: 9 | * @date 2020/12/17 10 | */ 11 | @Data 12 | @Builder 13 | public class MysqlDataSource { 14 | 15 | private String jdbcUrl; 16 | private String user; 17 | private String pass; 18 | } 19 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/entity/StashInfo.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.entity; 2 | 3 | 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2021/3/3 12 | */ 13 | 14 | @EqualsAndHashCode(callSuper = true) 15 | @Data 16 | @Builder 17 | public class StashInfo extends BlockDataSource { 18 | private String jdbcUrl; 19 | private String user; 20 | private String pass; 21 | private int cryptoTypeConfig; 22 | } 23 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/enums/BlockCertaintyEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.enums; 15 | 16 | import lombok.AllArgsConstructor; 17 | import lombok.Getter; 18 | 19 | /** 20 | * BlockCertaintyEnum 21 | * 22 | * @Description: BlockCertaintyEnum 23 | * @author maojiayu 24 | * @data Apr 1, 2019 3:58:30 PM 25 | * 26 | */ 27 | @AllArgsConstructor 28 | @Getter 29 | public enum BlockCertaintyEnum { 30 | UNCERTAIN(0), FIXED(1); 31 | private int certainty; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/enums/DataType.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.enums; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import cn.hutool.core.collection.ListUtil; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | 8 | import java.util.Collections; 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | /** 13 | * @author wesleywang 14 | * @Description: 15 | * @date 2020/12/23 16 | */ 17 | @AllArgsConstructor 18 | @Getter 19 | public enum DataType { 20 | 21 | NULL("null"), 22 | BLOCK_DETAIL_INFO_TABLE("block_detail_info"), 23 | BLOCK_RAW_DATA_TABLE("block_raw_data"), 24 | BLOCK_TX_DETAIL_INFO_TABLE("block_tx_detail_info"), 25 | TX_RAW_DATA_TABLE("tx_raw_data"), 26 | TX_RECEIPT_RAW_DATA_TABLE("tx_receipt_raw_data"), 27 | DEPLOYED_ACCOUNT_INFO_TABLE("deployed_account_info"), 28 | CONTRACT_INFO_TABLE("contract_info"), 29 | BLOCK_TASK_POOL_TABLE("block_task_pool"), 30 | EVENT_TABLE("event"), 31 | METHOD_TABLE("method"); 32 | 33 | 34 | private String tableName; 35 | 36 | public static List getDefault(){ 37 | return ListUtil.toList(NULL); 38 | } 39 | 40 | public static DataType getDataType(String tableName){ 41 | for(DataType dataType : DataType.values()){ 42 | if (dataType.tableName.equals(tableName)){ 43 | return dataType; 44 | } 45 | } 46 | return NULL; 47 | } 48 | 49 | public static List getTables(List dataTypes){ 50 | if (CollectionUtil.isEmpty(dataTypes)) { 51 | return Collections.emptyList(); 52 | } 53 | return dataTypes.stream().map(DataType::getTableName).collect(Collectors.toList()); 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/enums/IgnoreBasicDataParam.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.enums; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | /** 7 | * @author wesleywang 8 | * @Description: 9 | * @date 2021/6/23 10 | */ 11 | @AllArgsConstructor 12 | @Getter 13 | public class IgnoreBasicDataParam { 14 | 15 | @Getter 16 | public enum IgnoreBasicDataTable { 17 | BLOCK_RAW_DATA_TABLE, 18 | TX_RAW_DATA_TABLE, 19 | TX_RECEIPT_RAW_DATA_TABLE; 20 | 21 | IgnoreBasicDataTable() { } 22 | } 23 | 24 | @Getter 25 | public enum BlockRawDataParams { 26 | DB_HASH, 27 | EXTRA_DATA, 28 | GAS_LIMIT, 29 | GAS_USED, 30 | LOGS_BLOOM, 31 | PARENT_HASH, 32 | RECEIPTS_ROOT, 33 | SEALER, 34 | SEALER_LIST, 35 | SIGNATURE_LIST, 36 | STATE_ROOT, 37 | TRANSACTION_LIST, 38 | TRANSACTIONS_ROOT; 39 | 40 | BlockRawDataParams() { } 41 | } 42 | 43 | @Getter 44 | public enum TxReceiptRawDataParams { 45 | FROM, 46 | GAS_USED, 47 | LOGS, 48 | INPUT, 49 | MESSAGE, 50 | OUTPUT, 51 | LOGS_BLOOM, 52 | ROOT, 53 | TO, 54 | TX_INDEX, 55 | TX_PROOF, 56 | RECEIPT_PROOF; 57 | 58 | TxReceiptRawDataParams() { } 59 | } 60 | 61 | @Getter 62 | public enum TxRawDataParams { 63 | FROM, 64 | GAS, 65 | GAS_PRICE, 66 | INPUT, 67 | NONCE, 68 | VALUE, 69 | TO; 70 | 71 | 72 | TxRawDataParams() { } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/enums/TxInfoStatusEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.enums; 15 | 16 | import lombok.AllArgsConstructor; 17 | import lombok.Getter; 18 | 19 | /** 20 | * TxInfoStatusEnum 21 | * 22 | * @Description: TxInfoStatusEnum 23 | * @author maojiayu 24 | * @data Dec 13, 2018 8:48:55 PM 25 | * 26 | */ 27 | @AllArgsConstructor 28 | @Getter 29 | public enum TxInfoStatusEnum { 30 | 31 | INIT(0), DOING(1), DONE(2), ERROR(3), TIMEOUT(4), RESET(5); 32 | private int status; 33 | } 34 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/DataStashMysqlRepo.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.stash; 2 | 3 | import cn.hutool.db.Db; 4 | import cn.hutool.db.Entity; 5 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | import java.sql.SQLException; 9 | 10 | /** 11 | * @author wesleywang 12 | * @Description: 13 | * @date 2021/3/3 14 | */ 15 | @Slf4j 16 | public class DataStashMysqlRepo { 17 | 18 | private final Db stashDb; 19 | 20 | public static DataStashMysqlRepo create() { 21 | return new DataStashMysqlRepo(); 22 | } 23 | 24 | public DataStashMysqlRepo() { 25 | stashDb = Db.use(ExportConstant.getCurrentContext().getStashDataSource()); 26 | } 27 | 28 | public String queryBlock(long blockHeight){ 29 | try { 30 | return stashDb.queryString( 31 | "select value from _sys_hash_2_block_ where _num_ = ? ", blockHeight); 32 | } catch (SQLException e) { 33 | log.error(" DataStashMysqlRepo queryBlock failed ", e); 34 | } 35 | return null; 36 | } 37 | 38 | public long queryBlockHeight(String transactionHash){ 39 | try { 40 | Number height = stashDb.queryNumber( 41 | "select _num_ from _sys_tx_hash_2_block_ where _hash_ = ? ", transactionHash); 42 | if (height == null) { 43 | return -1; 44 | } 45 | return height.longValue(); 46 | } catch (SQLException e) { 47 | log.warn(" DataStashMysqlRepo queryBlock failed ", e); 48 | } 49 | return -1; 50 | } 51 | 52 | 53 | public long queryBlockNumber(){ 54 | try { 55 | return stashDb.count(Entity.create("_sys_hash_2_block_")) - 1; 56 | } catch (SQLException e) { 57 | log.error(" DataStashMysqlRepo queryBlockNumber failed ", e); 58 | } 59 | return -1; 60 | } 61 | 62 | public String queryCode(String contractAddress) { 63 | try { 64 | String contractTable = "c_" + contractAddress.replace("0x",""); 65 | return stashDb.queryString( 66 | "select value from " + contractTable + " where " + contractTable +".key = ?", "code"); 67 | } catch (SQLException e) { 68 | if (e.getErrorCode() == 1146 || e.getMessage().contains("doesn't exist")) { 69 | log.warn("the stash table contractAddress: {} not find ", contractAddress); 70 | return null; 71 | } 72 | log.warn("DataStashMysqlRepo queryCode failed ", e); 73 | } 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/entity/Log.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.stash.entity; 2 | 3 | import com.webank.blockchain.data.export.common.stash.rlp.ByteUtil; 4 | import com.webank.blockchain.data.export.common.stash.rlp.RLPList; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | import lombok.experimental.Accessors; 8 | import org.fisco.bcos.sdk.abi.datatypes.Address; 9 | import org.fisco.bcos.sdk.utils.Numeric; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author wesleywang 15 | * @Description: 16 | * @date 2021/3/4 17 | */ 18 | @Data 19 | @Accessors 20 | @EqualsAndHashCode 21 | public class Log { 22 | 23 | private String address; 24 | private List topics; 25 | private String data; 26 | 27 | 28 | public Log(RLPList rlp) { 29 | this.address = new Address(ByteUtil.bytesToBigInteger(rlp.get(0).getRLPData())).getValue(); 30 | this.topics = ((RLPList) rlp.get(1)).getList(); 31 | this.data = Numeric.toHexString(rlp.get(2).getRLPData()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/entity/TransactionDetail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.entity; 15 | 16 | import com.webank.blockchain.data.export.common.stash.rlp.ByteUtil; 17 | import com.webank.blockchain.data.export.common.stash.rlp.RLPList; 18 | import lombok.Data; 19 | import lombok.EqualsAndHashCode; 20 | import lombok.experimental.Accessors; 21 | import org.fisco.bcos.sdk.abi.datatypes.Address; 22 | import org.fisco.bcos.sdk.utils.Numeric; 23 | 24 | import java.math.BigInteger; 25 | 26 | /** 27 | * TransactionDetail 28 | * 29 | * @Description: TransactionDetail 30 | * @author maojiayu 31 | * @data Sep 10, 2019 8:02:42 PM 32 | * 33 | */ 34 | @Data 35 | @Accessors 36 | @EqualsAndHashCode 37 | public class TransactionDetail { 38 | private BigInteger nonce; 39 | private BigInteger gasPrice; 40 | private BigInteger gas; 41 | private BigInteger blockLimit; 42 | private Address receiveAddress; 43 | private BigInteger value; 44 | private String data; 45 | private BigInteger chainId; 46 | private BigInteger groupId; 47 | private String v; 48 | private BigInteger r; 49 | private BigInteger s; 50 | private String extraData; 51 | private String hash; 52 | 53 | public TransactionDetail(RLPList rlpHeader) { 54 | this.nonce = ByteUtil.bytesToBigInteger(rlpHeader.get(0).getRLPData()); 55 | this.gasPrice = ByteUtil.bytesToBigInteger(rlpHeader.get(1).getRLPData()); 56 | this.gas = ByteUtil.bytesToBigInteger(rlpHeader.get(2).getRLPData()); 57 | this.blockLimit = ByteUtil.bytesToBigInteger(rlpHeader.get(3).getRLPData()); 58 | this.receiveAddress = new Address(ByteUtil.bytesToBigInteger(rlpHeader.get(4).getRLPData())); 59 | this.value = ByteUtil.bytesToBigInteger(rlpHeader.get(5).getRLPData()); 60 | this.data = Numeric.toHexString(rlpHeader.get(6).getRLPData()); 61 | this.chainId = ByteUtil.bytesToBigInteger(rlpHeader.get(7).getRLPData()); 62 | this.groupId = ByteUtil.bytesToBigInteger(rlpHeader.get(8).getRLPData()); 63 | this.extraData = Numeric.toHexString(rlpHeader.get(9).getRLPData()); 64 | this.v = Numeric.toHexString(rlpHeader.get(10).getRLPData()); 65 | this.r = ByteUtil.bytesToBigInteger(rlpHeader.get(11).getRLPData()); 66 | this.s = ByteUtil.bytesToBigInteger(rlpHeader.get(12).getRLPData()); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/entity/TransactionReceipt.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.entity; 15 | 16 | import com.webank.blockchain.data.export.common.stash.rlp.ByteUtil; 17 | import com.webank.blockchain.data.export.common.stash.rlp.RLP; 18 | import com.webank.blockchain.data.export.common.stash.rlp.RLPElement; 19 | import com.webank.blockchain.data.export.common.stash.rlp.RLPList; 20 | import lombok.Data; 21 | import lombok.EqualsAndHashCode; 22 | import lombok.experimental.Accessors; 23 | import org.fisco.bcos.sdk.abi.datatypes.Address; 24 | import org.fisco.bcos.sdk.utils.Numeric; 25 | 26 | import java.math.BigInteger; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | /** 31 | * TransactionRecipt 32 | * 33 | * @Description: TransactionReceipt 34 | * @author maojiayu 35 | * @data Sep 25, 2019 10:36:21 AM 36 | * 37 | */ 38 | @Data 39 | @EqualsAndHashCode 40 | @Accessors(chain = true) 41 | public class TransactionReceipt { 42 | private String stateRoot; 43 | private BigInteger gasUsed; 44 | private String contractAddress; 45 | private String logsBloom; 46 | private long status; 47 | private String output; 48 | private List logs; 49 | 50 | public TransactionReceipt(RLPList rlpTransactionReceipt) { 51 | this.stateRoot = Numeric.toHexString(rlpTransactionReceipt.get(0).getRLPData()); 52 | this.gasUsed = ByteUtil.bytesToBigInteger(rlpTransactionReceipt.get(1).getRLPData()); 53 | this.contractAddress = new Address(ByteUtil.bytesToBigInteger(rlpTransactionReceipt.get(2).getRLPData())).getValue(); 54 | this.logsBloom = Numeric.toHexString(rlpTransactionReceipt.get(3).getRLPData()); 55 | this.status = ByteUtil.bytesToBigInteger(rlpTransactionReceipt.get(4).getRLPData()).longValue(); 56 | this.output = Numeric.toHexString(rlpTransactionReceipt.get(5).getRLPData()); 57 | this.logs = parseLogs(rlpTransactionReceipt.get(6).getRLPData()); 58 | } 59 | 60 | 61 | public static List parseLogs(byte[] logs){ 62 | List list = new ArrayList<>(); 63 | if(Numeric.toHexString(logs).equals("0xc0")) { 64 | return list; 65 | } 66 | RLPList result = (RLPList) RLP.decode2(logs).get(0); 67 | for (RLPElement rlpElement : result) { 68 | RLPList rlpElements = (RLPList) rlpElement; 69 | Log log = new Log(rlpElements); 70 | list.add(log); 71 | } 72 | return list; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/rlp/ByteArrayWrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.rlp; 15 | 16 | 17 | 18 | import org.fisco.bcos.sdk.utils.Hex; 19 | 20 | import java.io.Serializable; 21 | import java.util.Arrays; 22 | 23 | 24 | public class ByteArrayWrapper implements Comparable, Serializable { 25 | 26 | private static final long serialVersionUID = 19037950584492274L; 27 | private final byte[] bytes; 28 | private int hashCode = 0; 29 | 30 | public ByteArrayWrapper(byte[] data) { 31 | if (data == null) 32 | throw new NullPointerException("ByteArrayWrapper bytes is null"); 33 | this.bytes = data; 34 | this.hashCode = Arrays.hashCode(data); 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return hashCode; 40 | } 41 | 42 | @Override 43 | public int compareTo(ByteArrayWrapper o) { 44 | return FastByteComparisons.compareTo( 45 | bytes, 0, bytes.length, 46 | o.getData(), 0, o.getData().length); 47 | } 48 | 49 | public byte[] getData() { 50 | return bytes; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return bytes ==null? "" : Hex.toHexString(bytes); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/rlp/CompactEncoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.rlp; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import static org.bouncycastle.util.encoders.Hex.encode; 20 | 21 | 22 | public class CompactEncoder { 23 | private final static Map hexMap = new HashMap<>(); 24 | 25 | static { 26 | hexMap.put('0', (byte) 0x0); 27 | hexMap.put('1', (byte) 0x1); 28 | hexMap.put('2', (byte) 0x2); 29 | hexMap.put('3', (byte) 0x3); 30 | hexMap.put('4', (byte) 0x4); 31 | hexMap.put('5', (byte) 0x5); 32 | hexMap.put('6', (byte) 0x6); 33 | hexMap.put('7', (byte) 0x7); 34 | hexMap.put('8', (byte) 0x8); 35 | hexMap.put('9', (byte) 0x9); 36 | hexMap.put('a', (byte) 0xa); 37 | hexMap.put('b', (byte) 0xb); 38 | hexMap.put('c', (byte) 0xc); 39 | hexMap.put('d', (byte) 0xd); 40 | hexMap.put('e', (byte) 0xe); 41 | hexMap.put('f', (byte) 0xf); 42 | } 43 | 44 | public static byte[] binToNibblesNoTerminator(byte[] str) { 45 | byte[] hexEncoded = encode(str); 46 | for (int i = 0; i < hexEncoded.length; ++i) { 47 | byte b = hexEncoded[i]; 48 | hexEncoded[i] = hexMap.get((char) b); 49 | } 50 | return hexEncoded; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/rlp/DecodeResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.rlp; 15 | 16 | import java.io.Serializable; 17 | 18 | @SuppressWarnings("serial") 19 | public class DecodeResult implements Serializable { 20 | 21 | private int position; 22 | private Object decodedObject; 23 | 24 | public DecodeResult(int pos, Object decoded) { 25 | this.position = pos; 26 | this.decodedObject = decoded; 27 | } 28 | 29 | public int getPos() { 30 | return position; 31 | } 32 | 33 | public Object getDecoded() { 34 | return decodedObject; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/rlp/RLPElement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.rlp; 15 | 16 | import java.io.Serializable; 17 | 18 | /** 19 | * Wrapper class for decoded elements from an RLP encoded byte array. 20 | * 21 | * @author Roman Mandeleil 22 | * @since 01.04.2014 23 | */ 24 | public interface RLPElement extends Serializable { 25 | 26 | byte[] getRLPData(); 27 | } 28 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/rlp/RLPItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.rlp; 15 | 16 | import lombok.Data; 17 | 18 | 19 | /** 20 | * RLPItem 21 | * 22 | * @Description: RLPItem 23 | * @author maojiayu 24 | * @data Sep 25, 2019 4:01:51 PM 25 | * 26 | */ 27 | @Data 28 | public class RLPItem implements RLPElement { 29 | 30 | private static final long serialVersionUID = 7867984796230853830L; 31 | private final byte[] rlpData; 32 | 33 | public RLPItem(byte[] rlpData) { 34 | this.rlpData = rlpData; 35 | } 36 | 37 | public byte[] getRLPData() { 38 | if (rlpData.length == 0) 39 | return null; 40 | return rlpData; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/stash/rlp/RLPList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.stash.rlp; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import org.fisco.bcos.sdk.utils.Numeric; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * RLPList 25 | * 26 | * @Description: RLPList 27 | * @author maojiayu 28 | * @data Sep 4, 2019 4:21:50 PM 29 | * 30 | */ 31 | @Data 32 | @EqualsAndHashCode(callSuper=false) 33 | public class RLPList extends ArrayList implements RLPElement{ 34 | 35 | private static final long serialVersionUID = -2763960600461380063L; 36 | 37 | private byte[] RLPData; 38 | 39 | public List getList() { 40 | List result = new ArrayList<>(); 41 | for (RLPElement e : this) { 42 | result.add(Numeric.toHexString(e.getRLPData())); 43 | } 44 | return result; 45 | } 46 | } -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/subscribe/DefaultMsgTopic.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.subscribe; 2 | 3 | import com.webank.blockchain.data.export.common.subscribe.face.MsgTopicInterface; 4 | import com.webank.blockchain.data.export.common.subscribe.face.SubscriberInterface; 5 | 6 | import java.util.concurrent.ConcurrentHashMap; 7 | 8 | /** 9 | * @author aaronchu 10 | * @Description 11 | * @date 2021/09/01 12 | */ 13 | public class DefaultMsgTopic implements MsgTopicInterface { 14 | 15 | private ConcurrentHashMap, Boolean> subscribers = new ConcurrentHashMap<>(); 16 | 17 | public void publish(TMsg msg, Object context){ 18 | this.subscribers.forEachKey(1, subscriber -> { 19 | if(subscriber.shouldProcess(msg, context)){ 20 | subscriber.process(msg); 21 | } 22 | }); 23 | } 24 | 25 | public void addSubscriber(SubscriberInterface subscriber){ 26 | this.subscribers.putIfAbsent(subscriber, true); 27 | } 28 | 29 | public void removeSubscriber(SubscriberInterface subscriber){ 30 | this.subscribers.remove(subscriber); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/subscribe/TopicRegistry.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.subscribe; 2 | 3 | import com.webank.blockchain.data.export.common.bo.data.*; 4 | import com.webank.blockchain.data.export.common.subscribe.face.MsgTopicInterface; 5 | import lombok.Data; 6 | 7 | /** 8 | * @author aaronchu 9 | * @Description 10 | * @date 2021/09/01 11 | */ 12 | @Data 13 | public class TopicRegistry { 14 | 15 | private MsgTopicInterface blockTopic = new DefaultMsgTopic<>(); 16 | 17 | private MsgTopicInterface txTopic = new DefaultMsgTopic<>(); 18 | 19 | private MsgTopicInterface txReceiptTopic = new DefaultMsgTopic<>(); 20 | 21 | private MsgTopicInterface methodTopic = new DefaultMsgTopic<>(); 22 | 23 | private MsgTopicInterface eventTopic = new DefaultMsgTopic<>(); 24 | } 25 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/subscribe/face/MsgTopicInterface.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.subscribe.face; 2 | 3 | /** 4 | * @author aaronchu 5 | * @Description 6 | * @date 2021/09/01 7 | */ 8 | public interface MsgTopicInterface { 9 | 10 | void publish(TMsg msg, Object context); 11 | 12 | void addSubscriber(SubscriberInterface subscriber); 13 | 14 | void removeSubscriber(SubscriberInterface subscriber); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/subscribe/face/SubscriberInterface.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.subscribe.face; 2 | 3 | import com.webank.blockchain.data.export.common.subscribe.DefaultMsgTopic; 4 | 5 | /** 6 | * @author aaronchu 7 | * @Description 8 | * @date 2021/09/01 9 | */ 10 | public interface SubscriberInterface { 11 | 12 | boolean shouldProcess(TMsg msg, Object context); 13 | 14 | void process(TMsg msg); 15 | 16 | default void subscribe(DefaultMsgTopic msg) { 17 | msg.addSubscriber(this); 18 | } 19 | 20 | default void unsubscribe(DefaultMsgTopic msg){ 21 | msg.removeSubscriber(this); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/AddressListUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | import org.fisco.bcos.sdk.abi.datatypes.Address; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | 23 | /** 24 | * AddressListUtils 25 | * 26 | * @Description: AddressListUtils 27 | * @author maojiayu 28 | * @data Dec 28, 2018 6:13:58 PM 29 | * 30 | */ 31 | public class AddressListUtils { 32 | 33 | public static List

toAddressList(List strList) { 34 | if (strList.isEmpty()) { 35 | return new ArrayList
(); 36 | } else { 37 | return strList.stream().map(str -> { 38 | return new Address(str); 39 | }).collect(Collectors.toList()); 40 | } 41 | } 42 | 43 | public static List addressToStrList(List
adressList) { 44 | if (adressList.isEmpty()) { 45 | return new ArrayList(); 46 | } else { 47 | return adressList.stream().map(addr -> { 48 | return addr.toString().trim(); 49 | }).collect(Collectors.toList()); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/BigIntegerUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | import cn.hutool.core.convert.Convert; 17 | 18 | import java.math.BigInteger; 19 | 20 | /** 21 | * BigIntegerUtils 22 | * 23 | * @Description: BigIntegerUtils 24 | * @author maojiayu 25 | * @data Dec 18, 2018 10:55:41 AM 26 | * 27 | */ 28 | public class BigIntegerUtils { 29 | 30 | public static long toLong(BigInteger bi) { 31 | return bi.longValue(); 32 | } 33 | 34 | public static long toLong(Object obj) { 35 | return Convert.toLong(obj); 36 | } 37 | 38 | 39 | public static int toInteger(BigInteger bi) { 40 | return bi.intValue(); 41 | } 42 | 43 | public static int toInteger(Object obj) { 44 | BigInteger bi = (BigInteger) obj; 45 | return bi.intValue(); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/BoolUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | /** 17 | * BoolUtils 18 | * 19 | * @Description: BoolUtils 20 | * @author maojiayu 21 | * @data Mar 12, 2019 3:14:31 PM 22 | * 23 | */ 24 | public class BoolUtils { 25 | 26 | public static boolean toBoolean(Boolean bool) { 27 | return bool.booleanValue(); 28 | } 29 | 30 | public static boolean toBoolean(Object obj) { 31 | Boolean bool = (Boolean) obj; 32 | return bool.booleanValue(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/ClientUtil.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.common.tools; 2 | 3 | import com.google.common.collect.Maps; 4 | import com.webank.blockchain.data.export.common.entity.ChainInfo; 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.fisco.bcos.sdk.BcosSDK; 7 | import org.fisco.bcos.sdk.client.Client; 8 | import org.fisco.bcos.sdk.config.ConfigOption; 9 | import org.fisco.bcos.sdk.config.exceptions.ConfigException; 10 | import org.fisco.bcos.sdk.config.model.ConfigProperty; 11 | import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @author wesleywang 19 | * @Description: 20 | * @date 2020/12/17 21 | */ 22 | public class ClientUtil { 23 | 24 | public static CryptoKeyPair cryptoKeyPair(ChainInfo chainInfo) throws ConfigException { 25 | Client client = getClient(chainInfo); 26 | return client.getCryptoSuite().createKeyPair(); 27 | } 28 | 29 | public static Client getClient(ChainInfo chainInfo) throws ConfigException { 30 | BcosSDK sdk = getSDK(chainInfo); 31 | return sdk.getClient(chainInfo.getGroupId()); 32 | } 33 | 34 | public static BcosSDK getSDK(ChainInfo chainInfo) throws ConfigException { 35 | ConfigProperty configProperty = new ConfigProperty(); 36 | setPeers(configProperty,chainInfo); 37 | setCertPath(configProperty,chainInfo); 38 | ConfigOption option = new ConfigOption(configProperty); 39 | return new BcosSDK(option); 40 | } 41 | 42 | public static void setPeers(ConfigProperty configProperty, ChainInfo chainInfo) { 43 | String[] nodes = StringUtils.split(chainInfo.getNodeStr(), ";"); 44 | List peers = Arrays.asList(nodes); 45 | Map network = Maps.newHashMapWithExpectedSize(1); 46 | network.put("peers", peers); 47 | configProperty.setNetwork(network); 48 | } 49 | 50 | public static void setCertPath(ConfigProperty configProperty, ChainInfo chainInfo) { 51 | Map cryptoMaterial = Maps.newHashMapWithExpectedSize(1); 52 | cryptoMaterial.put("certPath", chainInfo.getCertPath()); 53 | configProperty.setCryptoMaterial(cryptoMaterial); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/DateUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | import cn.hutool.core.date.DateUtil; 17 | import cn.hutool.core.util.HexUtil; 18 | import org.apache.commons.lang3.StringUtils; 19 | 20 | import java.util.Date; 21 | 22 | /** 23 | * DateUtils 24 | * 25 | * @Description: DateUtils 26 | * @author maojiayu 27 | * @data Oct 22, 2020 7:54:07 PM 28 | * 29 | */ 30 | public class DateUtils { 31 | 32 | public static Date hexStrToDate(String hexString) { 33 | if (StringUtils.startsWithIgnoreCase(hexString, "0x")) { 34 | hexString = StringUtils.substring(hexString, 2); 35 | } 36 | return DateUtil.date(HexUtil.toBigInteger(hexString).longValue()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/JacksonException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | /** 17 | * JacksonException 18 | * 19 | * @Description: JacksonException 20 | * @author maojiayu 21 | * @data Dec 28, 2018 3:45:52 PM 22 | * 23 | */ 24 | public class JacksonException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = -3313868940376241665L; 27 | 28 | public JacksonException() { 29 | super(); 30 | } 31 | 32 | public JacksonException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public JacksonException(String message) { 37 | super(message); 38 | } 39 | 40 | public JacksonException(Throwable cause) { 41 | super(cause); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/MessageLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | import lombok.extern.slf4j.Slf4j; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.util.Properties; 21 | 22 | 23 | /** 24 | * Load error messages defined in config. 25 | * 26 | * @author maojiayu 27 | * @data Dec 28, 2018 5:17:30 PM 28 | * 29 | */ 30 | @Slf4j 31 | public class MessageLoader { 32 | private static Properties properties = new Properties(); 33 | 34 | static { 35 | InputStream is = MessageLoader.class.getClassLoader().getResourceAsStream("error.properties"); 36 | if (is != null) { 37 | try { 38 | properties.load(is); 39 | } catch (IOException e) { 40 | log.error("", e); 41 | throw new RuntimeException(e); 42 | } 43 | } else { 44 | throw new RuntimeException("error.properties not found"); 45 | } 46 | } 47 | 48 | public static String getMessage(String name) { 49 | return properties.getProperty(name, null); 50 | } 51 | 52 | public static String getMessage(String name, Object...args) { 53 | String template = properties.getProperty(name, null); 54 | return String.format(template, args); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/tools/NameValueVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.tools; 15 | 16 | import lombok.AllArgsConstructor; 17 | import lombok.Data; 18 | import lombok.NoArgsConstructor; 19 | import lombok.experimental.Accessors; 20 | 21 | /** 22 | * NameValueVO: common vo. 23 | * 24 | * @author maojiayu 25 | * @data Dec 28, 2018 3:54:40 PM 26 | * 27 | */ 28 | @Data 29 | @NoArgsConstructor 30 | @AllArgsConstructor 31 | @Accessors(chain = true) 32 | public class NameValueVO { 33 | private String name; 34 | private T value; 35 | } 36 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/vo/CommonDataResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.vo; 15 | 16 | import lombok.AllArgsConstructor; 17 | import lombok.Data; 18 | import lombok.EqualsAndHashCode; 19 | import lombok.NoArgsConstructor; 20 | import lombok.experimental.Accessors; 21 | 22 | 23 | /** 24 | * CommonDataResponse 25 | * 26 | * @Description: CommonDataResponse 27 | * @author maojiayu 28 | * @data Dec 28, 2018 6:01:15 PM 29 | * 30 | */ 31 | @Data 32 | @NoArgsConstructor 33 | @AllArgsConstructor 34 | @Accessors(chain = true) 35 | @EqualsAndHashCode(callSuper = true) 36 | public class CommonDataResponse extends CommonResponse { 37 | private T data; 38 | } 39 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/vo/CommonResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.vo; 15 | 16 | import com.fasterxml.jackson.annotation.JsonInclude; 17 | import com.webank.blockchain.data.export.common.constants.StatusCode; 18 | import lombok.AllArgsConstructor; 19 | import lombok.Data; 20 | import lombok.NoArgsConstructor; 21 | import lombok.experimental.Accessors; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * CommonResponse 27 | * 28 | * @author maojiayu 29 | * @data Dec 28, 2018 6:02:57 PM 30 | * 31 | */ 32 | @Data 33 | @NoArgsConstructor 34 | @AllArgsConstructor 35 | @Accessors(chain = true) 36 | @JsonInclude(JsonInclude.Include.NON_NULL) 37 | public class CommonResponse { 38 | protected int status = 0; 39 | protected Msg msg; 40 | public static CommonResponse SUCCESS = new CommonResponse(); 41 | public static CommonResponse UNLOGIN = new CommonResponse(StatusCode.SESSION_EXPIRED, "user not login"); 42 | public static CommonResponse UNAUTH = new CommonResponse(StatusCode.UNAUTH, "user no auth"); 43 | public static CommonResponse SYSERROR = new CommonResponse(StatusCode.EXECUTE_ERROR, "execute error"); 44 | public static CommonResponse NOBLOCK = new CommonResponse(StatusCode.PARAMETER_ERROR, "no block data"); 45 | 46 | public CommonResponse(int status, String error) { 47 | this.status = status; 48 | this.msg = new Msg().setGlobal(error); 49 | } 50 | 51 | @Data 52 | @Accessors(chain = true) 53 | @JsonInclude(JsonInclude.Include.NON_NULL) 54 | public static class Msg { 55 | private String global; 56 | private Map fields; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-common/src/main/java/com/webank/blockchain/data/export/common/vo/ValidErrorResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.common.vo; 15 | 16 | import com.webank.blockchain.data.export.common.constants.StatusCode; 17 | import lombok.Data; 18 | import lombok.EqualsAndHashCode; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.HashMap; 22 | 23 | /** 24 | * ValidErrorResponse, wrap the basic valid error usage of MVC. 25 | * 26 | * @author maojiayu 27 | * @data Dec 28, 2018 6:05:45 PM 28 | * 29 | */ 30 | @Data 31 | @Accessors(chain = true) 32 | @EqualsAndHashCode(callSuper = true) 33 | public class ValidErrorResponse extends CommonResponse { 34 | public ValidErrorResponse() { 35 | this.status = StatusCode.PARAMETER_ERROR; 36 | msg = new Msg().setGlobal("").setFields(new HashMap<>()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | /bin/ 4 | bin/* 5 | #config/* 6 | /.gradle/ 7 | 8 | 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | /nbproject/private/ 27 | /build/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | src/main/scripts 34 | src/main/resources 35 | 36 | ## contracts ## 37 | src/main/java/com/webank/bcosbee/generated 38 | src/main/java/com/webank/blockchain.data.export/core/generated 39 | src/main/java/org 40 | my.log* 41 | *.log 42 | 43 | src/test/java/com/webank/webasebee/contract/ 44 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/build.gradle: -------------------------------------------------------------------------------- 1 | clean { 2 | println "delete ${projectDir}/dist" 3 | delete "${projectDir}/dist" 4 | } 5 | dependencies { 6 | implementation project(':WeBankBlockchain-Data-Export-parser') 7 | implementation project(':WeBankBlockchain-Data-Export-common') 8 | implementation project(':WeBankBlockchain-Data-Export-db') 9 | } 10 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/api/DataExportService.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.api; 2 | 3 | import java.util.Map; 4 | import java.util.stream.Collectors; 5 | 6 | import com.webank.blockchain.data.export.common.entity.BlockDataSource; 7 | import com.webank.blockchain.data.export.common.entity.ChainInfo; 8 | import com.webank.blockchain.data.export.common.entity.ContractInfo; 9 | import com.webank.blockchain.data.export.common.entity.DataExportContext; 10 | import com.webank.blockchain.data.export.common.entity.ExportConfig; 11 | import com.webank.blockchain.data.export.common.entity.ExportDataSource; 12 | import com.webank.blockchain.data.export.common.entity.StashInfo; 13 | import com.webank.blockchain.data.export.task.DataExportExecutor; 14 | 15 | import cn.hutool.core.collection.CollectionUtil; 16 | 17 | /** 18 | * @author wesleywang 19 | * @Description: 20 | * @date 2020/12/16 21 | */ 22 | public class DataExportService { 23 | 24 | public static DataExportExecutor create(ExportDataSource dataSource, BlockDataSource blockDataSource, ExportConfig config) throws Exception { 25 | return new DataExportExecutor(buildContext(dataSource, blockDataSource, config)); 26 | } 27 | 28 | public static void start(DataExportExecutor exportExecutor) { 29 | exportExecutor.start(); 30 | } 31 | 32 | public static void stop(DataExportExecutor exportExecutor) { 33 | exportExecutor.stop(); 34 | } 35 | 36 | private static DataExportContext buildContext(ExportDataSource dataSource, BlockDataSource blockDataSource, ExportConfig config) throws Exception { 37 | DataExportContext context = new DataExportContext(); 38 | if (CollectionUtil.isNotEmpty(config.getContractInfoList())) { 39 | Map contractInfoMap = config.getContractInfoList().stream() 40 | .collect(Collectors.toMap(ContractInfo::getContractName, e->e)); 41 | context.setContractInfoMap(contractInfoMap); 42 | } 43 | if (blockDataSource instanceof ChainInfo){ 44 | context.setChainInfo((ChainInfo) blockDataSource); 45 | } 46 | if (blockDataSource instanceof StashInfo){ 47 | context.setStashInfo((StashInfo) blockDataSource); 48 | } 49 | context.setConfig(config); 50 | context.setExportDataSource(dataSource); 51 | context.setEsConfig(dataSource.getEsDataSource()); 52 | context.setAutoCreateTable(dataSource.isAutoCreateTable()); 53 | context.setTopicRegistry(config.getTopicRegistry()); 54 | return context; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/exception/CustomJobExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.blockchain.data.export.exception; 17 | 18 | 19 | import lombok.extern.slf4j.Slf4j; 20 | import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler; 21 | 22 | /** 23 | * CustomJobExceptionHandler 24 | * 25 | * @Description: CustomJobExceptionHandler 26 | * @author maojiayu 27 | * @data Jan 10, 2019 2:17:17 PM 28 | * 29 | */ 30 | @Slf4j 31 | public class CustomJobExceptionHandler implements JobErrorHandler { 32 | 33 | @Override 34 | public void handleException(String jobName, Throwable cause) { 35 | log.error(String.format("Job %s {} exception occur in job processing", jobName), cause); 36 | } 37 | 38 | @Override 39 | public String getType() { 40 | return null; 41 | } 42 | } -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/service/BlockAsyncService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.service; 15 | 16 | import org.fisco.bcos.sdk.client.protocol.response.BcosBlock.Block; 17 | 18 | /** 19 | * BlockAsyncService 20 | * 21 | * @Description: BlockAsyncService 22 | * @author maojiayu 23 | * @data Jun 27, 2019 3:54:56 PM 24 | * 25 | */ 26 | public class BlockAsyncService { 27 | 28 | public static void handleSingleBlock(Block b, long total) { 29 | BlockDepotService.process(b, total); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/service/BlockCrawlService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.service; 15 | 16 | import com.google.common.base.Stopwatch; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 19 | import com.webank.blockchain.data.export.parser.facade.ParseFacade; 20 | import lombok.extern.slf4j.Slf4j; 21 | import org.fisco.bcos.sdk.client.protocol.response.BcosBlock.Block; 22 | 23 | import java.io.IOException; 24 | import java.math.BigInteger; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | /** 28 | * BlockCrawlService 29 | * 30 | * @Description: BlockCrawlService 31 | * @author maojiayu 32 | * @data 2019-07-05 16:06:12 33 | * 34 | */ 35 | @Slf4j 36 | public class BlockCrawlService { 37 | /** 38 | * parse a Block to BlockInfoBO by using parser tools. 39 | * 40 | * @param blockHeight 41 | * @return BlockInfoBO, which include all the structs of a block containing contract info. 42 | * @throws IOException 43 | */ 44 | public static BlockInfoBO parse(long blockHeight) throws IOException { 45 | BigInteger bigBlockHeight = new BigInteger(Long.toString(blockHeight)); 46 | Block block = getBlock(bigBlockHeight); 47 | return parse(block); 48 | } 49 | 50 | public static BlockInfoBO parse(Block block) throws IOException { 51 | Stopwatch st1 = Stopwatch.createStarted(); 52 | BlockInfoBO blockInfo = ParseFacade.parse(block); 53 | log.info("bcosCrawlerMap block:{} succeed, bcosCrawlerMap.handleReceipt useTime: {}", 54 | block.getNumber().longValue(), st1.stop().elapsed(TimeUnit.MILLISECONDS)); 55 | return blockInfo; 56 | } 57 | 58 | public static Block getBlock(BigInteger blockHeightNumber) throws IOException { 59 | Stopwatch stopwatch = Stopwatch.createStarted(); 60 | log.debug("get block number: {}", blockHeightNumber); 61 | Block block = ExportConstant.getCurrentContext().getClient() 62 | .getBlockByNumber(blockHeightNumber); 63 | Stopwatch st1 = stopwatch.stop(); 64 | log.info("get block:{} succeed, eth.getBlock useTime: {}", blockHeightNumber, 65 | st1.elapsed(TimeUnit.MILLISECONDS)); 66 | return block; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/service/BlockListenerService.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.service; 2 | 3 | import com.webank.blockchain.data.export.common.bo.data.*; 4 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 5 | import com.webank.blockchain.data.export.common.subscribe.TopicRegistry; 6 | import com.webank.blockchain.data.export.db.entity.TxRawData; 7 | 8 | /** 9 | * @author aaronchu 10 | * @Description 11 | * @date 2021/08/31 12 | */ 13 | public class BlockListenerService { 14 | 15 | public static void onBlock(BlockInfoBO blockInfoBO){ 16 | TopicRegistry subscribers = ExportConstant.getCurrentContext().getTopicRegistry(); 17 | if(subscribers == null) return; 18 | if(subscribers.getBlockTopic() != null){ 19 | subscribers.getBlockTopic().publish(blockInfoBO, null); 20 | } 21 | 22 | if(subscribers.getTxTopic() != null && blockInfoBO.getTxRawDataBOList() != null){ 23 | for(TxRawDataBO rawData: blockInfoBO.getTxRawDataBOList()){ 24 | subscribers.getTxTopic().publish(rawData, blockInfoBO); 25 | } 26 | } 27 | 28 | 29 | if(subscribers.getTxReceiptTopic() != null && blockInfoBO.getTxReceiptRawDataBOList() != null){ 30 | for(TxReceiptRawDataBO rawData: blockInfoBO.getTxReceiptRawDataBOList()){ 31 | subscribers.getTxReceiptTopic().publish(rawData, blockInfoBO); 32 | } 33 | } 34 | 35 | if(subscribers.getMethodTopic() != null && blockInfoBO.getMethodInfoList() != null){ 36 | for(MethodBO methodBO:blockInfoBO.getMethodInfoList()){ 37 | subscribers.getMethodTopic().publish(methodBO, blockInfoBO); 38 | } 39 | } 40 | 41 | if(subscribers.getEventTopic() != null && blockInfoBO.getEventInfoList() != null){ 42 | for(EventBO eventBO:blockInfoBO.getEventInfoList()){ 43 | subscribers.getEventTopic().publish(eventBO, blockInfoBO); 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/service/BlockStoreService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.service; 15 | 16 | import cn.hutool.core.collection.CollectionUtil; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.db.service.DataStoreService; 19 | import com.webank.blockchain.data.export.task.DataPersistenceManager; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * BlockStoreService 25 | * 26 | * @Description: BlockStoreService 27 | * @author maojiayu 28 | * @data Jul 5, 2019 4:09:23 PM 29 | * 30 | */ 31 | public class BlockStoreService { 32 | 33 | public static void store(BlockInfoBO blockInfo) { 34 | List dataStoreServiceList = DataPersistenceManager.getCurrentManager().getDataStoreServiceList(); 35 | if (CollectionUtil.isEmpty(dataStoreServiceList)) { 36 | return; 37 | } 38 | for (DataStoreService dataStoreService : dataStoreServiceList) { 39 | dataStoreService.storeBlockInfoBO(blockInfo); 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/service/RollBackService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.service; 15 | 16 | import com.webank.blockchain.data.export.task.DataPersistenceManager; 17 | 18 | /** 19 | * RollBackService, rollback 20 | * 21 | * @Description: RollBackService 22 | * @author maojiayu 23 | * @data 2018-12-27 15:59:41 24 | * 25 | */ 26 | public class RollBackService { 27 | 28 | /** 29 | * Do rollback, including events, methods, accounts, and details. 30 | * 31 | * @param 32 | */ 33 | public static void rollback(long start, long end) { 34 | DataPersistenceManager.getCurrentManager().getRollbackOneInterfaceList() 35 | .forEach(v -> { 36 | v.rollback(start, end); 37 | }); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-core/src/main/java/com/webank/blockchain/data/export/tools/ElasticJobUtil.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.tools; 2 | 3 | import org.apache.shardingsphere.elasticjob.api.JobConfiguration; 4 | import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter; 5 | import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration; 6 | import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter; 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2020/12/22 12 | */ 13 | public class ElasticJobUtil { 14 | 15 | public static CoordinatorRegistryCenter createRegistryCenter(String zookeeperServiceLists, String zookeeperNamespace) { 16 | CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration( 17 | zookeeperServiceLists,zookeeperNamespace)); 18 | regCenter.init(); 19 | return regCenter; 20 | } 21 | 22 | public static JobConfiguration createJobConfiguration(String jobName, String cron, 23 | int shardingCount, String shardingItemParameters) { 24 | return JobConfiguration.newBuilder(jobName, shardingCount) 25 | .cron(cron).shardingItemParameters(shardingItemParameters).build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | /bin/ 4 | bin/* 5 | config/* 6 | /.gradle/ 7 | 8 | 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | /nbproject/private/ 27 | /build/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | src/main/scripts 34 | src/main/resources 35 | 36 | ## contracts ## 37 | src/main/java/com/webank/bcosbee/generated 38 | src/main/java/com/webank/webasebee/db/generated 39 | src/main/java/org 40 | my.log* 41 | *.log 42 | 43 | src/test/java/com/webank/webasebee/contract/ 44 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/build.gradle: -------------------------------------------------------------------------------- 1 | clean { 2 | println "delete ${projectDir}/dist" 3 | delete "${projectDir}/dist" 4 | } 5 | 6 | dependencies { 7 | implementation project(':WeBankBlockchain-Data-Export-common') 8 | implementation project(':WeBankBlockchain-Data-Export-parser') 9 | } 10 | 11 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/BlockDetailInfoDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | import com.webank.blockchain.data.export.common.bo.data.BlockDetailInfoBO; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.db.entity.BlockDetailInfo; 19 | import com.webank.blockchain.data.export.db.repository.BlockDetailInfoRepository; 20 | 21 | import cn.hutool.core.bean.BeanUtil; 22 | import lombok.AllArgsConstructor; 23 | 24 | /** 25 | * BlockDetailInfoDAO 26 | * 27 | * @author maojiayu 28 | * @data Dec 12, 2018 2:45:13 PM 29 | * 30 | */ 31 | @AllArgsConstructor 32 | public class BlockDetailInfoDAO implements SaveInterface { 33 | 34 | private final BlockDetailInfoRepository blockDetailInfoRepository; 35 | 36 | public void save(BlockDetailInfoBO bo) { 37 | BlockDetailInfo blockDetailInfo = new BlockDetailInfo(); 38 | BeanUtil.copyProperties(bo, blockDetailInfo, true); 39 | save(blockDetailInfo); 40 | } 41 | 42 | public void save(BlockDetailInfo blockDetailInfo) { 43 | blockDetailInfoRepository.save(blockDetailInfo); 44 | } 45 | 46 | @Override 47 | public void save(BlockInfoBO t) { 48 | save(t.getBlockDetailInfo()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/BlockRawDataDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | import cn.hutool.core.bean.BeanUtil; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.common.bo.data.BlockRawDataBO; 19 | import com.webank.blockchain.data.export.db.entity.BlockRawData; 20 | import com.webank.blockchain.data.export.db.repository.BlockRawDataRepository; 21 | import lombok.AllArgsConstructor; 22 | 23 | /** 24 | * @author wesleywang 25 | * @Description: 26 | * @date 2020/10/23 27 | */ 28 | @AllArgsConstructor 29 | public class BlockRawDataDAO implements SaveInterface { 30 | 31 | private BlockRawDataRepository blockRawDataRepository; 32 | 33 | public void save(BlockRawDataBO blockRawDataBO) { 34 | BlockRawData blockRawData = new BlockRawData(); 35 | BeanUtil.copyProperties(blockRawDataBO, blockRawData, true); 36 | save(blockRawData); 37 | } 38 | 39 | public void save(BlockRawData blockRawData) { 40 | blockRawDataRepository.save(blockRawData); 41 | } 42 | 43 | @Override 44 | public void save(BlockInfoBO blockInfoBO) { 45 | save(blockInfoBO.getBlockRawDataBO()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/ContractInfoDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | import cn.hutool.core.bean.BeanUtil; 17 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 18 | import com.webank.blockchain.data.export.db.entity.ContractInfo; 19 | import com.webank.blockchain.data.export.db.repository.ContractInfoRepository; 20 | import lombok.AllArgsConstructor; 21 | 22 | /** 23 | * @author wesleywang 24 | * @Description: 25 | * @date 2020/10/26 26 | */ 27 | @AllArgsConstructor 28 | public class ContractInfoDAO implements SaveInterface { 29 | 30 | private ContractInfoRepository contractInfoRepository; 31 | 32 | public void save(ContractInfo contractInfo) { 33 | contractInfoRepository.save(contractInfo); 34 | } 35 | 36 | @Override 37 | public void save(ContractInfoBO contractInfoBO) { 38 | ContractInfo contractInfo = contractInfoRepository.findByAbiHash(contractInfoBO.getAbiHash()); 39 | if(contractInfo != null){ 40 | return; 41 | } 42 | contractInfo = new ContractInfo(); 43 | BeanUtil.copyProperties(contractInfoBO, contractInfo, true); 44 | save(contractInfo); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/DeployedAccountInfoDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | import cn.hutool.core.bean.BeanUtil; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.common.bo.data.DeployedAccountInfoBO; 19 | import com.webank.blockchain.data.export.db.entity.DeployedAccountInfo; 20 | import com.webank.blockchain.data.export.db.repository.DeployedAccountInfoRepository; 21 | import lombok.AllArgsConstructor; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author wesleywang 27 | * @Description: 28 | * @date 2020/10/26 29 | */ 30 | @AllArgsConstructor 31 | public class DeployedAccountInfoDAO implements SaveInterface { 32 | 33 | private DeployedAccountInfoRepository deployedAccountInfoRepository; 34 | 35 | public void save(DeployedAccountInfo deployedAccountInfo) { 36 | deployedAccountInfoRepository.save(deployedAccountInfo); 37 | } 38 | 39 | public void save(List deployedAccountInfoBOS) { 40 | deployedAccountInfoBOS.forEach(this::save); 41 | } 42 | 43 | 44 | public void save(DeployedAccountInfoBO deployedAccountInfoBO) { 45 | DeployedAccountInfo deployedAccountInfo = new DeployedAccountInfo(); 46 | BeanUtil.copyProperties(deployedAccountInfoBO, deployedAccountInfo, true); 47 | save(deployedAccountInfo); 48 | } 49 | 50 | @Override 51 | public void save(BlockInfoBO blockInfoBO) { 52 | save(blockInfoBO.getDeployedAccountInfoBOS()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/MethodAndEventDao.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.db.dao; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import cn.hutool.db.Db; 5 | import cn.hutool.db.Entity; 6 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 7 | import com.webank.blockchain.data.export.common.bo.data.CommonBO; 8 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 9 | import lombok.extern.slf4j.Slf4j; 10 | 11 | import java.sql.SQLException; 12 | import java.util.Date; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * @author wesleywang 18 | * @Description: 19 | * @date 2020/12/28 20 | */ 21 | @Slf4j 22 | public class MethodAndEventDao implements SaveInterface { 23 | 24 | @Override 25 | public void save(BlockInfoBO blockInfoBO) { 26 | save(blockInfoBO.getEventInfoList()); 27 | save(blockInfoBO.getMethodInfoList()); 28 | } 29 | 30 | private void save(List list){ 31 | if (CollectionUtil.isEmpty(list)) { 32 | return; 33 | } 34 | list.forEach(eventBO -> { 35 | try { 36 | Entity entity = Entity.create(eventBO.getTable()); 37 | for (Map.Entry entry : eventBO.getEntity().entrySet()){ 38 | entity.set(entry.getKey(), entry.getValue()); 39 | } 40 | entity.set("depot_updatetime", new Date()); 41 | Db.use(ExportConstant.getCurrentContext().getDataSource()).insert(entity); 42 | } catch (SQLException e) { 43 | log.error("save failed ", e); 44 | } 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/SaveInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | /** 17 | * SaveInterface declares a interface which must be saved. 18 | * 19 | * @author maojiayu 20 | * @data Dec 13, 2018 8:27:46 PM 21 | * 22 | */ 23 | public interface SaveInterface { 24 | 25 | void save(T t); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/TxRawDataDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | import cn.hutool.core.bean.BeanUtil; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.common.bo.data.TxRawDataBO; 19 | import com.webank.blockchain.data.export.db.entity.TxRawData; 20 | import com.webank.blockchain.data.export.db.repository.TxRawDataRepository; 21 | import lombok.AllArgsConstructor; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author wesleywang 27 | * @Description: 28 | * @date 2020/10/26 29 | */ 30 | @AllArgsConstructor 31 | public class TxRawDataDAO implements SaveInterface { 32 | 33 | private TxRawDataRepository txRawDataRepository; 34 | 35 | public void save(TxRawData txRawData) { 36 | txRawDataRepository.save(txRawData); 37 | 38 | } 39 | 40 | public void save(List txRawDataList) { 41 | txRawDataList.forEach(this :: save); 42 | } 43 | 44 | public void save(TxRawDataBO txRawDataBO) { 45 | TxRawData txRawData = new TxRawData(); 46 | BeanUtil.copyProperties(txRawDataBO,txRawData,true); 47 | save(txRawData); 48 | } 49 | 50 | @Override 51 | public void save(BlockInfoBO blockInfoBO) { 52 | save(blockInfoBO.getTxRawDataBOList()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/dao/TxReceiptRawDataDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.dao; 15 | 16 | import cn.hutool.core.bean.BeanUtil; 17 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 18 | import com.webank.blockchain.data.export.common.bo.data.TxReceiptRawDataBO; 19 | import com.webank.blockchain.data.export.db.entity.TxReceiptRawData; 20 | import com.webank.blockchain.data.export.db.repository.TxReceiptRawDataRepository; 21 | import lombok.AllArgsConstructor; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author wesleywang 27 | * @Description: 28 | * @date 2020/10/26 29 | */ 30 | @AllArgsConstructor 31 | public class TxReceiptRawDataDAO implements SaveInterface { 32 | 33 | private TxReceiptRawDataRepository txReceiptRawDataRepository; 34 | 35 | public void save(TxReceiptRawData txReceiptRawData) { 36 | txReceiptRawDataRepository.save(txReceiptRawData); 37 | } 38 | 39 | public void save(List txReceiptRawDataBOList) { 40 | txReceiptRawDataBOList.forEach(this :: save); 41 | } 42 | 43 | public void save(TxReceiptRawDataBO txReceiptRawDataBO) { 44 | TxReceiptRawData txReceiptRawData = new TxReceiptRawData(); 45 | BeanUtil.copyProperties(txReceiptRawDataBO,txReceiptRawData,true); 46 | save(txReceiptRawData); 47 | } 48 | 49 | @Override 50 | public void save(BlockInfoBO blockInfoBO) { 51 | save(blockInfoBO.getTxReceiptRawDataBOList()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/BlockDetailInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.ToString; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * BlockDetailInfo entity storage of block detail info. 25 | * 26 | * @Description: BlockDetailInfo 27 | * @author graysonzhang 28 | * @data 2018-11-14 17:45:16 29 | * 30 | */ 31 | @SuppressWarnings("serial") 32 | @Data 33 | @Accessors(chain = true) 34 | @ToString(callSuper = true) 35 | @EqualsAndHashCode(callSuper = true) 36 | public class BlockDetailInfo extends IdEntity { 37 | 38 | /** @Fields blockHeight : block height */ 39 | private long blockHeight; 40 | 41 | /** @Fields blockHash : block hash */ 42 | private String blockHash; 43 | 44 | /** @Fields txCount : transaction's count in block */ 45 | private short txCount; 46 | 47 | /** @Fields blockTimeStamp : block timestamp */ 48 | private Date blockTimeStamp; 49 | 50 | /** @Fields status : block process status */ 51 | private short status; 52 | 53 | /** @Fields updatetime : depot update time */ 54 | protected Date depotUpdatetime = new Date(); 55 | 56 | public enum Status { 57 | TODO, COMPLETED 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/BlockRawData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.ToString; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * @author wesleywang 25 | * @Description: 26 | * @date 2020/10/23 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | @ToString(callSuper = true) 31 | @EqualsAndHashCode(callSuper = true) 32 | public class BlockRawData extends IdEntity { 33 | private static final long serialVersionUID = -6636726869135248569L; 34 | 35 | /** @Fields blockHash : block hash */ 36 | private String blockHash; 37 | 38 | /** @Fields blockHeight : block height */ 39 | private long blockHeight; 40 | 41 | /** @Fields blockTimeStamp : block timestamp */ 42 | private Date blockTimeStamp; 43 | 44 | private String parentHash; 45 | 46 | private String logsBloom; 47 | 48 | private String transactionsRoot; 49 | 50 | private String receiptsRoot; 51 | 52 | private String dbHash; 53 | 54 | private String stateRoot; 55 | 56 | private String sealer; 57 | 58 | private String sealerList; 59 | 60 | private String extraData; 61 | 62 | private String gasLimit; 63 | 64 | private String gasUsed; 65 | 66 | private String signatureList; 67 | 68 | private String transactionList; 69 | 70 | /** @Fields updatetime : depot update time */ 71 | protected Date depotUpdatetime = new Date(); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/BlockTaskPool.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import com.fasterxml.jackson.annotation.JsonInclude; 17 | import lombok.Data; 18 | import lombok.EqualsAndHashCode; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * BlockTaskPool 25 | * 26 | * @Description: BlockTaskPool 27 | * @author maojiayu 28 | * @data Apr 1, 2019 3:04:00 PM 29 | * 30 | */ 31 | @Data 32 | @Accessors(chain = true) 33 | @EqualsAndHashCode(callSuper = true) 34 | @JsonInclude(JsonInclude.Include.NON_NULL) 35 | public class BlockTaskPool extends IdEntity { 36 | 37 | private static final long serialVersionUID = 5987912520917085396L; 38 | 39 | private long blockHeight; 40 | 41 | /** @Fields syncStatus : sync status of transactions */ 42 | private short syncStatus; 43 | 44 | /** @Fields certainty : certainty of fork check */ 45 | private short certainty; 46 | 47 | private short handleItem = 0; 48 | 49 | /** @Fields updatetime : update time */ 50 | protected Date depotUpdatetime; 51 | } 52 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/BlockTxDetailInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import com.fasterxml.jackson.annotation.JsonInclude; 17 | import lombok.Data; 18 | import lombok.EqualsAndHashCode; 19 | import lombok.ToString; 20 | import lombok.experimental.Accessors; 21 | 22 | import java.util.Date; 23 | 24 | /** 25 | * BlockTxDetailInfo 26 | * 27 | * @Description: BlockTxDetailInfo 28 | * @author graysonzhang 29 | * @data 2018-12-20 14:38:18 30 | * 31 | */ 32 | @SuppressWarnings("serial") 33 | @Data 34 | @Accessors(chain = true) 35 | @ToString(callSuper = true) 36 | @EqualsAndHashCode(callSuper = true) 37 | @JsonInclude(JsonInclude.Include.NON_NULL) 38 | public class BlockTxDetailInfo extends IdEntity { 39 | 40 | /** @Fields blockHeight : block height */ 41 | private long blockHeight; 42 | 43 | /** @Fields blockHash : block hash */ 44 | private String blockHash; 45 | 46 | /** @Fields contractName : contract name */ 47 | private String contractName; 48 | 49 | /** @Fields methodName : contract method name */ 50 | private String methodName; 51 | 52 | /** @Fields txHash : transaction hash */ 53 | private String txHash; 54 | 55 | /** @Fields txFrom : transaction' s from */ 56 | private String txFrom; 57 | 58 | /** @Fields txTo : transaction's to */ 59 | private String txTo; 60 | 61 | /** @Fields blockTimeStamp : block timestamp */ 62 | private Date blockTimeStamp; 63 | 64 | /** @Fields updatetime : depot update time */ 65 | protected Date depotUpdatetime = new Date(); 66 | } 67 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/ContractInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.ToString; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * @author wesleywang 25 | * @Description: 26 | * @date 2020/10/26 27 | */ 28 | @EqualsAndHashCode(callSuper = true) 29 | @Data 30 | @Accessors(chain = true) 31 | @ToString(callSuper = true) 32 | public class ContractInfo extends IdEntity { 33 | private static final long serialVersionUID = 5724687955937639884L; 34 | 35 | protected String abiHash; 36 | 37 | private String contractABI; 38 | 39 | private String contractBinary; 40 | 41 | private short version = 1; 42 | 43 | private String contractName; 44 | 45 | /** @Fields updatetime : depot update time */ 46 | protected Date depotUpdatetime = new Date(); 47 | } 48 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/DeployedAccountInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.ToString; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * @author wesleywang 25 | * @Description: 26 | * @date 2020/10/26 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | @ToString(callSuper = true) 31 | @EqualsAndHashCode(callSuper = true) 32 | public class DeployedAccountInfo extends IdEntity { 33 | /** @Fields serialVersionUID : TODO */ 34 | private static final long serialVersionUID = 8671861939859734978L; 35 | 36 | /** @Fields contractName : contract name */ 37 | private String contractName; 38 | 39 | /** @Fields contractAddress : contract address */ 40 | private String contractAddress; 41 | 42 | /** @Fields blockHeight : block height */ 43 | private long blockHeight; 44 | 45 | /** @Fields blockTimeStamp : block timestamp */ 46 | private Date blockTimeStamp; 47 | 48 | private String abiHash; 49 | 50 | /** @Fields updatetime : depot update time */ 51 | protected Date depotUpdatetime = new Date(); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/IdEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.experimental.Accessors; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * IdEntity 23 | * 24 | * @Description: IdEntity 25 | * @author maojiayu 26 | * @data Dec 28, 2018 6:05:11 PM 27 | * 28 | */ 29 | @Data 30 | @Accessors(chain = true) 31 | public abstract class IdEntity implements Serializable { 32 | 33 | private static final long serialVersionUID = 5903397383140175895L; 34 | /** @Fields pkId : primary key */ 35 | protected Long pkId; 36 | } 37 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/TxRawData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.ToString; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * @author wesleywang 25 | * @Description: 26 | * @date 2020/10/23 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | @ToString(callSuper = true) 31 | @EqualsAndHashCode(callSuper = true) 32 | public class TxRawData extends IdEntity { 33 | private static final long serialVersionUID = -2666867877669597503L; 34 | 35 | /** @Fields blockHeight : block height */ 36 | private long blockHeight; 37 | 38 | /** @Fields blockHash : block hash */ 39 | private String blockHash; 40 | 41 | /** @Fields txHash : transaction hash */ 42 | private String txHash; 43 | 44 | private String txIndex; 45 | 46 | /** @Fields blockTimeStamp : block timestamp */ 47 | private Date blockTimeStamp; 48 | 49 | private String from; 50 | 51 | private String gas; 52 | 53 | private String input; 54 | 55 | private String nonce; 56 | 57 | private String to; 58 | 59 | private String value; 60 | 61 | private String gasPrice; 62 | 63 | /** @Fields updatetime : depot update time */ 64 | protected Date depotUpdatetime = new Date(); 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/entity/TxReceiptRawData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.entity; 15 | 16 | import lombok.Data; 17 | import lombok.EqualsAndHashCode; 18 | import lombok.ToString; 19 | import lombok.experimental.Accessors; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * @author wesleywang 25 | * @Description: 26 | * @date 2020/10/23 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | @ToString(callSuper = true) 31 | @EqualsAndHashCode(callSuper = true) 32 | public class TxReceiptRawData extends IdEntity { 33 | private static final long serialVersionUID = 2319335707392149645L; 34 | 35 | /** @Fields blockHeight : block height */ 36 | private long blockHeight; 37 | 38 | /** @Fields blockHash : block hash */ 39 | private String blockHash; 40 | 41 | /** @Fields txHash : transaction hash */ 42 | private String txHash; 43 | 44 | /** @Fields blockTimeStamp : block timestamp */ 45 | private Date blockTimeStamp; 46 | 47 | private String txIndex; 48 | 49 | private String root; 50 | 51 | private String from; 52 | 53 | private String to; 54 | 55 | private String gasUsed; 56 | 57 | private String contractAddress; 58 | 59 | private String logs; 60 | 61 | private String logsBloom; 62 | 63 | private String status; 64 | 65 | private String input; 66 | 67 | private String output; 68 | 69 | private String txProof; 70 | 71 | private String receiptProof; 72 | 73 | private String message; 74 | 75 | /** @Fields updatetime : depot update time */ 76 | protected Date depotUpdatetime = new Date(); 77 | 78 | } 79 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/repository/BlockRawDataRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.repository; 15 | 16 | import cn.hutool.db.DaoTemplate; 17 | import cn.hutool.db.Db; 18 | import cn.hutool.db.Entity; 19 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 20 | import com.webank.blockchain.data.export.db.entity.BlockRawData; 21 | import lombok.AllArgsConstructor; 22 | import lombok.extern.slf4j.Slf4j; 23 | 24 | import java.sql.SQLException; 25 | 26 | /** 27 | * @author wesleywang 28 | * @Description: 29 | * @date 2020/10/23 30 | */ 31 | @Slf4j 32 | @AllArgsConstructor 33 | public class BlockRawDataRepository implements RollbackInterface { 34 | 35 | private DaoTemplate blockRawDataDao; 36 | 37 | private final String tableName; 38 | 39 | 40 | public void rollback(long blockHeight){ 41 | try { 42 | blockRawDataDao.del(Entity.create(tableName).set("block_height",">= " + blockHeight)); 43 | } catch (SQLException e) { 44 | log.error(" BlockRawDataRepository rollback failed ", e); 45 | } 46 | } 47 | 48 | public void rollback(long startBlockHeight, long endBlockHeight){ 49 | try { 50 | Db.use(ExportConstant.getCurrentContext().getDataSource()).execute( 51 | "delete from " + tableName +" where block_height >= ? and block_height< ?",startBlockHeight,endBlockHeight); 52 | } catch (SQLException e) { 53 | log.error(" BlockRawDataRepository rollback failed ", e); 54 | } 55 | } 56 | 57 | 58 | public void save(BlockRawData blockRawData) { 59 | try { 60 | Entity entity = Entity.parse(blockRawData,true,true); 61 | entity.setTableName(tableName); 62 | blockRawDataDao.addForGeneratedKey(entity); 63 | } catch (SQLException e) { 64 | log.error(" BlockRawDataRepository save failed ", e); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/repository/ContractInfoRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.repository; 15 | 16 | import cn.hutool.db.DaoTemplate; 17 | import cn.hutool.db.Entity; 18 | import com.webank.blockchain.data.export.db.entity.ContractInfo; 19 | import com.webank.blockchain.data.export.db.tools.BeanUtils; 20 | import lombok.AllArgsConstructor; 21 | import lombok.extern.slf4j.Slf4j; 22 | 23 | import java.sql.SQLException; 24 | 25 | /** 26 | * @author wesleywang 27 | * @Description: 28 | * @date 2020/10/26 29 | */ 30 | @Slf4j 31 | @AllArgsConstructor 32 | public class ContractInfoRepository { 33 | 34 | private DaoTemplate contractDao; 35 | 36 | private String tableName; 37 | 38 | public void save(ContractInfo contractInfo) { 39 | try { 40 | Entity entity = Entity.parse(contractInfo,true,true); 41 | entity.setTableName(tableName); 42 | contractDao.add(entity); 43 | } catch (SQLException e) { 44 | log.error("ContractInfoRepository save failed ", e); 45 | } 46 | } 47 | 48 | public ContractInfo findByAbiHash(String abiHash) { 49 | Entity entity = null; 50 | try { 51 | entity = contractDao.get("abi_hash",abiHash); 52 | } catch (SQLException e) { 53 | log.error(" BlockTaskPoolRepository findTopByOrderByBlockHeightDesc failed ", e); 54 | } 55 | if (entity == null){ 56 | return null; 57 | } 58 | return BeanUtils.toBean(entity, ContractInfo.class); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/repository/DeployedAccountInfoRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.repository; 15 | 16 | import cn.hutool.db.DaoTemplate; 17 | import cn.hutool.db.Entity; 18 | import com.webank.blockchain.data.export.db.entity.DeployedAccountInfo; 19 | import lombok.AllArgsConstructor; 20 | import lombok.extern.slf4j.Slf4j; 21 | 22 | import java.sql.SQLException; 23 | 24 | /** 25 | * @author wesleywang 26 | * @Description: 27 | * @date 2020/10/26 28 | */ 29 | @Slf4j 30 | @AllArgsConstructor 31 | public class DeployedAccountInfoRepository { 32 | 33 | private DaoTemplate deployedAccountInfoDao; 34 | 35 | private String tableName; 36 | 37 | 38 | public void save(DeployedAccountInfo deployedAccountInfo) { 39 | try { 40 | Entity entity = Entity.parse(deployedAccountInfo,true,true); 41 | entity.setTableName(tableName); 42 | deployedAccountInfoDao.addForGeneratedKey(entity); 43 | } catch (SQLException e) { 44 | log.error(" DeployedAccountInfoRepository save failed ", e); 45 | } 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/repository/RollbackInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.repository; 15 | 16 | /** 17 | * RollbackOneInterface 18 | * 19 | * @Description: RollbackOneInterface 20 | * @author maojiayu 21 | * @data Dec 13, 2018 10:53:39 AM 22 | * 23 | */ 24 | public interface RollbackInterface { 25 | /* 26 | * @see com.webank.blockchain.data.export.sys.db.repository.RollbackInterface#rollback(long) 27 | */ 28 | void rollback(long blockHeight); 29 | 30 | /** 31 | * rollback from startBlockHeight to endBlockHeight, including startBlockHeight, but not including endBlockHeight. 32 | * 33 | * @param startBlockHeight 34 | * @param endBlockHeight 35 | */ 36 | void rollback(long startBlockHeight, long endBlockHeight); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/repository/TxRawDataRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.repository; 15 | 16 | import cn.hutool.db.DaoTemplate; 17 | import cn.hutool.db.Db; 18 | import cn.hutool.db.Entity; 19 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 20 | import com.webank.blockchain.data.export.db.entity.TxRawData; 21 | import lombok.AllArgsConstructor; 22 | import lombok.extern.slf4j.Slf4j; 23 | 24 | import java.sql.SQLException; 25 | 26 | /** 27 | * @author wesleywang 28 | * @Description: 29 | * @date 2020/10/23 30 | */ 31 | @Slf4j 32 | @AllArgsConstructor 33 | public class TxRawDataRepository implements RollbackInterface { 34 | 35 | 36 | private DaoTemplate txRawDataDao; 37 | 38 | private String tableName; 39 | 40 | /* 41 | * @see com.webank.blockchain.data.export.sys.db.repository.RollbackInterface#rollback(long) 42 | */ 43 | public void rollback(long blockHeight){ 44 | try { 45 | txRawDataDao.del(Entity.create(tableName).set("block_height",">= " + blockHeight)); 46 | } catch (SQLException e) { 47 | log.error(" TxRawDataRepository rollback failed ", e); 48 | } 49 | } 50 | 51 | /* 52 | * @see com.webank.blockchain.data.export.sys.db.repository.RollbackInterface#rollback(long) 53 | */ 54 | public void rollback(long startBlockHeight, long endBlockHeight){ 55 | try { 56 | Db.use(ExportConstant.getCurrentContext().getDataSource()).execute( 57 | "delete from " + tableName + " where block_height >= ? and block_height< ?",startBlockHeight,endBlockHeight); 58 | } catch (SQLException e) { 59 | log.error(" TxRawDataRepository rollback failed ", e); 60 | } 61 | } 62 | 63 | public void save(TxRawData txRawData) { 64 | try { 65 | Entity entity = Entity.parse(txRawData,true,true); 66 | entity.setTableName(tableName); 67 | txRawDataDao.addForGeneratedKey(entity); 68 | } catch (SQLException e) { 69 | log.error(" TxRawDataRepository save failed ", e); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/repository/TxReceiptRawDataRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.repository; 15 | 16 | import cn.hutool.db.DaoTemplate; 17 | import cn.hutool.db.Db; 18 | import cn.hutool.db.Entity; 19 | import com.webank.blockchain.data.export.common.entity.ExportConstant; 20 | import com.webank.blockchain.data.export.db.entity.TxReceiptRawData; 21 | import lombok.AllArgsConstructor; 22 | import lombok.extern.slf4j.Slf4j; 23 | 24 | import java.sql.SQLException; 25 | 26 | /** 27 | * @author wesleywang 28 | * @Description: 29 | * @date 2020/10/23 30 | */ 31 | @Slf4j 32 | @AllArgsConstructor 33 | public class TxReceiptRawDataRepository implements RollbackInterface { 34 | 35 | private DaoTemplate txReceiptRawDataDao; 36 | 37 | private String tableName; 38 | 39 | 40 | /* 41 | * @see com.webank.blockchain.data.export.sys.db.repository.RollbackInterface#rollback(long) 42 | */ 43 | @Override 44 | public void rollback(long blockHeight){ 45 | try { 46 | txReceiptRawDataDao.del(Entity.create(tableName).set("block_height",">= " + blockHeight)); 47 | } catch (SQLException e) { 48 | log.error(" TxRawDataRepository rollback failed ", e); 49 | } 50 | } 51 | 52 | /* 53 | * @see com.webank.blockchain.data.export.sys.db.repository.RollbackInterface#rollback(long) 54 | */ 55 | @Override 56 | public void rollback(long startBlockHeight, long endBlockHeight){ 57 | try { 58 | Db.use(ExportConstant.getCurrentContext().getDataSource()).execute( 59 | "delete from "+ tableName + " where block_height >= ? and block_height< ?",startBlockHeight,endBlockHeight); 60 | } catch (SQLException e) { 61 | log.error(" TxRawDataRepository rollback failed ", e); 62 | } 63 | } 64 | 65 | public void save(TxReceiptRawData txReceiptRawData) { 66 | try { 67 | Entity entity = Entity.parse(txReceiptRawData,true,true); 68 | entity.setTableName(tableName); 69 | txReceiptRawDataDao.addForGeneratedKey(entity); 70 | } catch (SQLException e) { 71 | log.error(" TxRawDataRepository save failed ", e); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/service/DataStoreService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.service; 15 | 16 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 17 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 18 | 19 | /** 20 | * @author wesleywang 21 | * @Description: 22 | * @date 2020/10/26 23 | */ 24 | 25 | public interface DataStoreService { 26 | 27 | void storeBlockInfoBO(BlockInfoBO blockInfo); 28 | 29 | void storeContractInfo(ContractInfoBO contractInfoBO); 30 | } 31 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/service/ESStoreService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.service; 15 | 16 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 17 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 18 | import com.webank.blockchain.data.export.db.dao.ESHandleDao; 19 | import lombok.Data; 20 | import lombok.extern.slf4j.Slf4j; 21 | 22 | /** 23 | * @author wesleywang 24 | * @Description: 25 | * @date 2020/10/26 26 | */ 27 | @Slf4j 28 | @Data 29 | public class ESStoreService implements DataStoreService { 30 | 31 | @Override 32 | public void storeBlockInfoBO(BlockInfoBO blockInfo) { 33 | try { 34 | ESHandleDao.saveBlockInfo(blockInfo); 35 | } catch (Exception e) { 36 | log.error("ES storeBlockInfoBO failed, reason : " , e); 37 | } 38 | } 39 | 40 | @Override 41 | public void storeContractInfo(ContractInfoBO contractInfoBO) { 42 | try { 43 | ESHandleDao.saveContractInfo(contractInfoBO); 44 | } catch (Exception e) { 45 | log.error("ES storeContractInfo failed, reason : " , e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/service/MysqlStoreService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.db.service; 15 | 16 | import com.webank.blockchain.data.export.common.bo.data.BlockInfoBO; 17 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 18 | import com.webank.blockchain.data.export.db.dao.ContractInfoDAO; 19 | import com.webank.blockchain.data.export.db.dao.SaveInterface; 20 | import lombok.Data; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author wesleywang 26 | * @Description: 27 | * @date 2020/10/26 28 | */ 29 | @Data 30 | public class MysqlStoreService implements DataStoreService { 31 | 32 | private List> saveInterfaceList; 33 | 34 | private ContractInfoDAO contractInfoDAO; 35 | 36 | @Override 37 | public void storeBlockInfoBO(BlockInfoBO blockInfo) { 38 | saveInterfaceList.forEach(saveInterface -> { 39 | saveInterface.save(blockInfo); 40 | }); 41 | } 42 | 43 | @Override 44 | public void storeContractInfo(ContractInfoBO contractInfoBO) { 45 | contractInfoDAO.save(contractInfoBO); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-db/src/main/java/com/webank/blockchain/data/export/db/tools/BeanUtils.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.db.tools; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import cn.hutool.core.util.ReflectUtil; 5 | import cn.hutool.db.Entity; 6 | 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2020/12/17 12 | */ 13 | public class BeanUtils { 14 | 15 | public static T toBean(Entity entity, Class clazz) { 16 | return BeanUtil.fillBeanWithMap(entity, ReflectUtil.newInstance(clazz), true, true); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-parser/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | /bin/ 4 | bin/* 5 | config/* 6 | /.gradle/ 7 | 8 | 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | /nbproject/private/ 27 | /build/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | src/main/scripts 34 | src/main/resources 35 | 36 | ## contracts ## 37 | src/main/java/com/webank/bcosbee/generated 38 | src/main/java/com/webank/blockchain.data.export/parser/generated 39 | src/main/java/org 40 | my.log* 41 | *.log 42 | 43 | src/test/java/com/webank/webasebee/contract/ 44 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-parser/build.gradle: -------------------------------------------------------------------------------- 1 | clean { 2 | println "delete ${projectDir}/dist" 3 | delete "${projectDir}/dist" 4 | } 5 | 6 | dependencies { 7 | implementation project(':WeBankBlockchain-Data-Export-common') 8 | } 9 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-parser/src/main/java/com/webank/blockchain/data/export/parser/contract/ContractParser.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.parser.contract; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import cn.hutool.crypto.digest.MD5; 5 | import com.webank.blockchain.data.export.common.bo.contract.ContractDetail; 6 | import com.webank.blockchain.data.export.common.bo.contract.ContractMapsInfo; 7 | import com.webank.blockchain.data.export.common.bo.contract.MethodMetaInfo; 8 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 9 | import com.webank.blockchain.data.export.common.entity.ContractInfo; 10 | import lombok.extern.slf4j.Slf4j; 11 | 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * @author wesleywang 18 | * @Description: 19 | * @date 2020/12/25 20 | */ 21 | @Slf4j 22 | public class ContractParser { 23 | 24 | public static ContractMapsInfo initContractMaps(List contractInfoList){ 25 | if (CollectionUtil.isEmpty(contractInfoList)){ 26 | return null; 27 | } 28 | ContractMapsInfo contractMapsInfo = new ContractMapsInfo(); 29 | Map methodIdMap = new HashMap<>(); 30 | Map contractBinaryMap = new HashMap<>(); 31 | contractMapsInfo.setContractBinaryMap(contractBinaryMap); 32 | contractMapsInfo.setMethodIdMap(methodIdMap); 33 | MD5 md5 = MD5.create(); 34 | for (ContractInfo entry : contractInfoList) { 35 | ContractDetail contractDetail = new ContractDetail(); 36 | ContractInfoBO contractInfoBO = new ContractInfoBO(); 37 | String abi = entry.getAbi(); 38 | if (abi == null) { 39 | log.error("abi is null !!! please set it"); 40 | } 41 | String binary = entry.getBinary(); 42 | if (binary == null) { 43 | log.error("binary is null !!! please set it"); 44 | } 45 | contractInfoBO.setContractABI(abi); 46 | contractInfoBO.setAbiHash(md5.digestHex(abi)); 47 | contractInfoBO.setContractBinary(binary); 48 | contractInfoBO.setContractName(entry.getContractName()); 49 | contractDetail.setContractInfoBO(contractInfoBO); 50 | contractDetail.setMethodMetaInfos(MethodParser.parseToInfoList(abi,entry.getContractName())); 51 | contractDetail.setEventMetaInfos(EventParser.parseToInfoList(abi,entry.getContractName())); 52 | for (MethodMetaInfo methodMetaInfo : contractDetail.getMethodMetaInfos()) { 53 | methodIdMap.put(methodMetaInfo.getMethodId(), methodMetaInfo); 54 | contractBinaryMap.put(binary, contractDetail); 55 | } 56 | } 57 | return contractMapsInfo; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-parser/src/main/java/com/webank/blockchain/data/export/parser/enums/JavaTypeEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.parser.enums; 15 | 16 | import lombok.AllArgsConstructor; 17 | import lombok.Getter; 18 | import lombok.extern.slf4j.Slf4j; 19 | import org.apache.commons.lang3.StringUtils; 20 | 21 | /** 22 | * JavaTypeEnum 23 | * 24 | * @Description: JavaTypeEnum 25 | * @author maojiayu 26 | * @data Apr 18, 2019 11:29:46 AM 27 | * 28 | */ 29 | @AllArgsConstructor 30 | @Getter 31 | @Slf4j 32 | public enum JavaTypeEnum { 33 | 34 | BIGINTEGER("BigInteger", "Long", "bigint", "BigIntegerUtils.toLong"), 35 | Long("long", "Long", "bigint", "BigIntegerUtils.toLong"), 36 | BOOL("Boolean", "String", "varchar(8)", "String.valueOf"), 37 | STRING("String", "String", "varchar(4096)", "String.valueOf"), 38 | ByteArray("byte[]", "String", "text", "String.valueOf" ), 39 | LISTByteArray("List", "String", "text", "String.valueOf" ), 40 | LISTString("List", "String", "text", "String.valueOf" ), 41 | LISTBigInteger("List", "String", "varchar(4096)", "String.valueOf" ), 42 | LIST("List", "String", "text", "JacksonUtils.toJson" ) 43 | ; 44 | 45 | private String javaType; 46 | private String entityType; 47 | private String sqlType; 48 | private String typeMethod; 49 | 50 | public static JavaTypeEnum parse(String javaType) { 51 | for (JavaTypeEnum type : JavaTypeEnum.values()) { 52 | if ((type.getJavaType().equalsIgnoreCase(StringUtils.substringBefore(javaType, "<")) 53 | && !javaType.contains(">")) || type.getJavaType().equalsIgnoreCase(javaType)) { 54 | return type; 55 | } 56 | } 57 | log.error("javaType {} can't be converted.", javaType); 58 | return null; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/WeBankBlockchain-Data-Export-parser/src/main/java/com/webank/blockchain/data/export/parser/tools/ABIUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.parser.tools; 15 | 16 | import com.fasterxml.jackson.databind.ObjectMapper; 17 | import lombok.extern.slf4j.Slf4j; 18 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 19 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinitionFactory; 20 | import org.fisco.bcos.sdk.abi.wrapper.ContractABIDefinition; 21 | import org.fisco.bcos.sdk.crypto.CryptoSuite; 22 | import org.fisco.bcos.sdk.utils.ObjectMapperFactory; 23 | 24 | import java.io.IOException; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * ABIUtils 30 | * 31 | * @Description: ABIUtils 32 | * @author maojiayu 33 | * @data Nov 19, 2020 5:53:37 PM 34 | * 35 | */ 36 | @Slf4j 37 | public class ABIUtils { 38 | 39 | public static Map> getEventsAbiDefs(String abi, CryptoSuite cryptoSuite) { 40 | ABIDefinitionFactory abiDefinitionFactory = new ABIDefinitionFactory(cryptoSuite); 41 | ContractABIDefinition contractABIDefinition = abiDefinitionFactory.loadABI(abi); 42 | Map> events = contractABIDefinition.getEvents(); 43 | return events; 44 | } 45 | 46 | /** 47 | * Get contract abi list by contract class. 48 | * @param abi abi of contract 49 | * @return AbiDefinition[] array of ABIDefinition 50 | */ 51 | public static ABIDefinition[] getContractAbiList(String abi) { 52 | 53 | ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); 54 | ABIDefinition[] abiDefinition = null; 55 | 56 | try { 57 | abiDefinition = objectMapper.readValue(abi, ABIDefinition[].class); 58 | } catch (IOException e) { 59 | log.error("IOException: {}", e.getMessage()); 60 | } 61 | return abiDefinition; 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Dec 17 17:51:17 CST 2020 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'data-export-sdk' 2 | include 'WeBankBlockchain-Data-Export-core', 3 | 'WeBankBlockchain-Data-Export-parser', 4 | 'WeBankBlockchain-Data-Export-common', 5 | 'WeBankBlockchain-Data-Export-db' 6 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ./log/logFile-%d{yyyy-MM-dd}.log 7 | 30 8 | 9 | 10 | 11 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 12 | 13 | 14 | 15 | 100MB 16 | 17 | 18 | 19 | 20 | 21 | %green(%d{yyyy-MM-dd HH:mm:ss.SSS}) %magenta([%thread]) %highlight(%-5level) %cyan(%logger{36}) - %msg%n 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-sdk/src/test/java/com/webank/blockchain/data/export/sdk/test/ExportDataTest.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.sdk.test; 2 | 3 | import com.webank.blockchain.data.export.ExportDataSDK; 4 | import com.webank.blockchain.data.export.common.entity.ChainInfo; 5 | import com.webank.blockchain.data.export.common.entity.ExportDataSource; 6 | import com.webank.blockchain.data.export.common.entity.MysqlDataSource; 7 | import com.webank.blockchain.data.export.task.DataExportExecutor; 8 | import org.fisco.bcos.sdk.config.exceptions.ConfigException; 9 | import org.junit.Test; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * @author wesleywang 16 | * @Description: 17 | * @date 2020/12/21 18 | */ 19 | public class ExportDataTest { 20 | 21 | @Test 22 | public void shardingTest() throws Exception { 23 | //配置其中[]内容配置即可测试 24 | MysqlDataSource mysqlDataSourc = MysqlDataSource.builder() 25 | .jdbcUrl("jdbc:mysql://[ip]:3306/[database]") 26 | .pass("password") 27 | .user("username") 28 | .build(); 29 | MysqlDataSource mysqlDataSourc1 = MysqlDataSource.builder() 30 | .jdbcUrl("jdbc:mysql://[ip]:3306/[database]") 31 | .pass("password") 32 | .user("username") 33 | .build(); 34 | List mysqlDataSourceList = new ArrayList<>(); 35 | mysqlDataSourceList.add(mysqlDataSourc); 36 | mysqlDataSourceList.add(mysqlDataSourc1); 37 | ExportDataSource dataSource = ExportDataSource.builder() 38 | .mysqlDataSources(mysqlDataSourceList) 39 | .autoCreateTable(true) 40 | .sharding(true) 41 | .shardingNumberPerDatasource(2) 42 | .build(); 43 | DataExportExecutor exportExecutor = ExportDataSDK.create(dataSource, ChainInfo.builder() 44 | .nodeStr("[ip]:[port]") 45 | .certPath("config") 46 | .groupId(1).build()); 47 | ExportDataSDK.start(exportExecutor); 48 | Thread.sleep(60 *1000L); 49 | ExportDataSDK.stop(exportExecutor); 50 | } 51 | 52 | @Test 53 | public void singleTest() throws Exception { 54 | MysqlDataSource mysqlDataSourc = MysqlDataSource.builder() 55 | .jdbcUrl("jdbc:mysql://[ip]:[port]/[database]") 56 | .pass("password") 57 | .user("username") 58 | .build(); 59 | List mysqlDataSourceList = new ArrayList<>(); 60 | mysqlDataSourceList.add(mysqlDataSourc); 61 | ExportDataSource dataSource = ExportDataSource.builder() 62 | .mysqlDataSources(mysqlDataSourceList) 63 | .autoCreateTable(true) 64 | .build(); 65 | DataExportExecutor exportExecutor = ExportDataSDK.create(dataSource, ChainInfo.builder() 66 | .nodeStr("[ip]:[port]") 67 | .certPath("config") 68 | .groupId(1).build()); 69 | ExportDataSDK.start(exportExecutor); 70 | Thread.sleep(60 *1000L); 71 | ExportDataSDK.stop(exportExecutor); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/.gitignore: -------------------------------------------------------------------------------- 1 | ### common ### 2 | log/ 3 | src/main/resources 4 | src/test/resources 5 | WeBankBlockchain-Data-Export-sdk/*.properties 6 | WeBankBlockchain-Data-Export-sdk/*.gpg 7 | 8 | ### mac ### 9 | .DS_Store 10 | 11 | ### gradle ### 12 | .gradle/ 13 | build 14 | dist/ 15 | 16 | ## eclipse ## 17 | .classpath 18 | .project 19 | .settings 20 | bin/ 21 | out/ 22 | conf/ 23 | 24 | ## integration test files 25 | nodes/ 26 | src/integration-test/resources/ 27 | build_chain.sh 28 | 29 | ### STS ### 30 | .apt_generated 31 | .factorypath 32 | .springBeans 33 | .sts4-cache 34 | 35 | ### IntelliJ IDEA ### 36 | .idea 37 | *.iws 38 | *.iml 39 | *.ipr 40 | 41 | ### NetBeans ### 42 | /nbproject/private/ 43 | /build/ 44 | /nbbuild/ 45 | /dist/ 46 | /nbdist/ 47 | /.nb-gradle/ 48 | 49 | ### Compiled class file ### 50 | *.class 51 | 52 | ### Log file ### 53 | *.log 54 | 55 | ### BlueJ files ### 56 | *.ctxt 57 | 58 | ### Mobile Tools for Java (J2ME) ### 59 | .mtj.tmp/ 60 | 61 | ### Package Files ### 62 | *.jar 63 | *.war 64 | *.nar 65 | *.ear 66 | *.zip 67 | *.tar.gz 68 | *.rar 69 | 70 | ### virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml ### 71 | hs_err_pid* 72 | 73 | ### repo ### 74 | config/ 75 | generated 76 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | - code_refactor_2020.01 5 | 6 | matrix: 7 | fast_finish: true 8 | include: 9 | - language: java 10 | jdk: openjdk8 11 | os: linux 12 | sudo: required 13 | after_success: 14 | - bash <(curl -s https://codecov.io/bash) 15 | 16 | - language: java 17 | jdk: openjdk9 18 | os: linux 19 | sudo: required 20 | 21 | - language: java 22 | jdk: openjdk10 23 | os: linux 24 | sudo: required 25 | 26 | - language: java 27 | jdk: openjdk11 28 | os: linux 29 | sudo: required 30 | 31 | cache: 32 | directories: 33 | - $HOME/.gradle/caches/ 34 | - $HOME/.gradle/wrapper/ 35 | 36 | before_script: 37 | - mv config/contract_example config/contract 38 | - chmod +x gradlew 39 | 40 | script: 41 | - ./gradlew test bootJar 42 | 43 | after_success: 44 | - bash <(curl -s https://codecov.io/bash) 45 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/build.gradle: -------------------------------------------------------------------------------- 1 | bootJar { 2 | destinationDir file('dist') 3 | archiveName "Data-Export-" + version + '.jar' 4 | doLast { 5 | copy { 6 | from file('tools/') 7 | into 'dist/' 8 | } 9 | copy { 10 | from configurations.runtime 11 | into 'dist/lib' 12 | } 13 | copy { 14 | from file('src/main/resources/application.properties') 15 | into 'dist/config/' 16 | } 17 | } 18 | } 19 | 20 | clean { 21 | println "delete ${projectDir}/dist" 22 | delete "${projectDir}/dist" 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/data-export-docker/config/abi/HelloWorld.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"n","type":"string"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/data-export-docker/config/bin/HelloWorld.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b506040805190810160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6102d7806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680634ed3885e146100515780636d4ce63c146100ba575b600080fd5b34801561005d57600080fd5b506100b8600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061014a565b005b3480156100c657600080fd5b506100cf610164565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561010f5780820151818401526020810190506100f4565b50505050905090810190601f16801561013c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b8060009080519060200190610160929190610206565b5050565b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101fc5780601f106101d1576101008083540402835291602001916101fc565b820191906000526020600020905b8154815290600101906020018083116101df57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061024757805160ff1916838001178555610275565b82800160010185558215610275579182015b82811115610274578251825591602001919060010190610259565b5b5090506102829190610286565b5090565b6102a891905b808211156102a457600081600090555060010161028c565b5090565b905600a165627a7a72305820aa8d37bec7b8a85e32740629893aa0bd0894e6eadefe527bc854f28f9493d1fd0029 -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/Data-Export/16101f24294d0f1740dec0de6754e6d60d8cb099/WeBankBlockchain-Data-Export-service/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 06 15:32:48 CST 2021 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/App.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | 8 | /** 9 | * @author wesleywang 10 | * @Description: 11 | * @date 2021/3/30 12 | */ 13 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) 14 | @EnableConfigurationProperties 15 | public class App { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(App.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/contract/ContractParser.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.contract; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import com.webank.blockchain.data.export.common.bo.contract.ContractDetail; 5 | import com.webank.blockchain.data.export.common.bo.contract.ContractMapsInfo; 6 | import com.webank.blockchain.data.export.common.bo.contract.MethodMetaInfo; 7 | import com.webank.blockchain.data.export.common.bo.data.ContractInfoBO; 8 | import com.webank.blockchain.data.export.common.entity.ContractInfo; 9 | import com.webank.blockchain.data.export.config.ServiceConfig; 10 | import lombok.extern.slf4j.Slf4j; 11 | 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * @author wesleywang 18 | * @Description: 19 | * @date 2020/12/25 20 | */ 21 | @Slf4j 22 | public class ContractParser { 23 | 24 | public static ContractMapsInfo initContractMaps(List contractInfoList, ServiceConfig config){ 25 | if (CollectionUtil.isEmpty(contractInfoList)){ 26 | return null; 27 | } 28 | ContractMapsInfo contractMapsInfo = new ContractMapsInfo(); 29 | Map methodIdMap = new HashMap<>(); 30 | Map contractBinaryMap = new HashMap<>(); 31 | contractMapsInfo.setContractBinaryMap(contractBinaryMap); 32 | contractMapsInfo.setMethodIdMap(methodIdMap); 33 | for (ContractInfo entry : contractInfoList) { 34 | ContractDetail contractDetail = new ContractDetail(); 35 | ContractInfoBO contractInfoBO = new ContractInfoBO(); 36 | String abi = entry.getAbi(); 37 | if (abi == null) { 38 | log.error("abi is null !!! please set it"); 39 | } 40 | String binary = entry.getBinary(); 41 | if (binary == null) { 42 | log.error("binary is null !!! please set it"); 43 | } 44 | contractInfoBO.setContractABI(abi); 45 | contractInfoBO.setContractBinary(binary); 46 | contractInfoBO.setContractName(entry.getContractName()); 47 | contractDetail.setContractInfoBO(contractInfoBO); 48 | contractDetail.setMethodMetaInfos(MethodParser.parseToInfoList(abi,entry.getContractName(),config)); 49 | contractDetail.setEventMetaInfos(EventParser.parseToInfoList(abi,entry.getContractName(),config)); 50 | for (MethodMetaInfo methodMetaInfo : contractDetail.getMethodMetaInfos()) { 51 | methodIdMap.put(methodMetaInfo.getMethodId(), methodMetaInfo); 52 | contractBinaryMap.put(binary, contractDetail); 53 | } 54 | } 55 | return contractMapsInfo; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/grafana/AtomicParas.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.grafana; 15 | 16 | import java.util.Map; 17 | 18 | /** 19 | * AtomicParas 20 | * 21 | * @Description: AtomicParas 22 | * @author maojiayu 23 | * @data Mar 27, 2019 5:07:07 PM 24 | * 25 | */ 26 | public interface AtomicParas { 27 | /** 28 | * @Description: wrap the render data to a map. And the render data is basically read from a pojo. 29 | * @param: @param t 30 | * @return: Map 31 | */ 32 | public Map getMap(T t); 33 | 34 | /** 35 | * @Description: return the path of template. 36 | * @return: String 37 | */ 38 | public String getTemplatePath(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/grafana/GrafanaConstant.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.grafana; 2 | 3 | /** 4 | * @author wesleywang 5 | * @Description: 6 | * @date 2021/4/1 7 | */ 8 | public class GrafanaConstant { 9 | 10 | public static final String GRAFANA_PANEL_TABLE_PATH = "templates/grafana/panel_table.txt"; 11 | public static final String GRAFANA_DASHBOARD_PATH = "templates/grafana/dashboard_default.txt"; 12 | public static final String GENERATED_GRAFANA_DEFAULT_DASHBOARD_PATH = "default_dashboard.json"; 13 | } 14 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/grafana/GrafanaDashboardParas.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.grafana; 15 | 16 | import com.google.common.collect.Maps; 17 | import com.webank.blockchain.data.export.config.ServiceConfig; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.io.File; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import static com.webank.blockchain.data.export.grafana.GrafanaConstant.GENERATED_GRAFANA_DEFAULT_DASHBOARD_PATH; 26 | import static com.webank.blockchain.data.export.grafana.GrafanaConstant.GRAFANA_DASHBOARD_PATH; 27 | 28 | /** 29 | * GrafanaDashboardParas 30 | * 31 | * @Description: GrafanaDashboardParas 32 | * @author maojiayu 33 | * @data Mar 28, 2019 11:12:50 AM 34 | * 35 | */ 36 | @Component 37 | public class GrafanaDashboardParas implements GrafanaParas> { 38 | 39 | @Autowired 40 | private ServiceConfig config; 41 | 42 | @Override 43 | public Map getMap(List infoList) { 44 | final String prefix = config.getTablePrefix(); 45 | final String suffix = config.getTablePostfix(); 46 | final Map map = Maps.newConcurrentMap(); 47 | map.put("panels", infoList); 48 | map.put("block_task_pool", prefix + "block_task_pool" + suffix); 49 | map.put("block_detail_info", prefix + "block_detail_info" + suffix); 50 | map.put("block_tx_detail_info", prefix + "block_tx_detail_info" + suffix); 51 | map.put("deployed_account_info", prefix + "deployed_account_info" + suffix); 52 | return map; 53 | } 54 | 55 | @Override 56 | public String getTemplatePath() { 57 | return GRAFANA_DASHBOARD_PATH; 58 | } 59 | 60 | @Override 61 | public String getGeneratedFilePath() { 62 | return File.separator 63 | + GENERATED_GRAFANA_DEFAULT_DASHBOARD_PATH; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/grafana/GrafanaPanelTableParasEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.grafana; 15 | 16 | import cn.hutool.core.util.StrUtil; 17 | import com.google.common.collect.Maps; 18 | import com.webank.blockchain.data.export.common.bo.contract.EventMetaInfo; 19 | import com.webank.blockchain.data.export.common.bo.contract.FieldVO; 20 | import com.webank.blockchain.data.export.config.ServiceConfig; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.stereotype.Component; 23 | import org.springframework.util.StringUtils; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import static com.webank.blockchain.data.export.grafana.GrafanaConstant.GRAFANA_PANEL_TABLE_PATH; 29 | 30 | /** 31 | * GrafanaPanelParas 32 | * 33 | * @Description: GrafanaPanelParas 34 | * @author maojiayu 35 | * @data Mar 27, 2019 4:48:14 PM 36 | * 37 | */ 38 | @Component 39 | public class GrafanaPanelTableParasEvent implements AtomicParas { 40 | 41 | @Autowired 42 | private ServiceConfig config; 43 | 44 | @Override 45 | public Map getMap(EventMetaInfo info) { 46 | List list = info.getList(); 47 | Map map = Maps.newLinkedHashMap(); 48 | map.put("list", list); 49 | 50 | String className = info.getContractName() + StringUtils.capitalize(info.getEventName()); 51 | String tableName = getTableName(info.getContractName(),info.getEventName() + "_event"); 52 | map.put("table_name", tableName); 53 | map.put("title", className); 54 | return map; 55 | } 56 | 57 | public String getTableName(String contractName,String name){ 58 | String tablePrefix = config.getTablePrefix(); 59 | String tablePostfix = config.getTablePostfix(); 60 | return tablePrefix + contractName + "_" + StrUtil.toUnderlineCase(name) + tablePostfix; 61 | } 62 | 63 | @Override 64 | public String getTemplatePath() { 65 | return GRAFANA_PANEL_TABLE_PATH; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/grafana/GrafanaPanelTableParasMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.grafana; 15 | 16 | import cn.hutool.core.util.StrUtil; 17 | import com.google.common.collect.Maps; 18 | import com.webank.blockchain.data.export.common.bo.contract.FieldVO; 19 | import com.webank.blockchain.data.export.common.bo.contract.MethodMetaInfo; 20 | import com.webank.blockchain.data.export.config.ServiceConfig; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.stereotype.Component; 23 | import org.springframework.util.StringUtils; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import static com.webank.blockchain.data.export.grafana.GrafanaConstant.GRAFANA_PANEL_TABLE_PATH; 29 | 30 | /** 31 | * GrafanaPanelParas 32 | * 33 | * @Description: GrafanaPanelParas 34 | * @author maojiayu 35 | * @data Mar 27, 2019 4:48:14 PM 36 | * 37 | */ 38 | @Component 39 | public class GrafanaPanelTableParasMethod implements AtomicParas { 40 | 41 | @Autowired 42 | private ServiceConfig config; 43 | 44 | @Override 45 | public Map getMap(MethodMetaInfo info) { 46 | List list = info.getFieldsList(); 47 | Map map = Maps.newLinkedHashMap(); 48 | map.put("list", list); 49 | 50 | String className = info.getContractName() + StringUtils.capitalize(info.getMethodName()); 51 | String tableName = getTableName(info.getContractName(),info.getMethodName() + "_method"); 52 | map.put("table_name", tableName); 53 | map.put("title", className); 54 | return map; 55 | } 56 | 57 | public String getTableName(String contractName,String name){ 58 | String tablePrefix = config.getTablePrefix(); 59 | String tablePostfix = config.getTablePostfix(); 60 | return tablePrefix + contractName + "_" + StrUtil.toUnderlineCase(name) + tablePostfix; 61 | } 62 | 63 | @Override 64 | public String getTemplatePath() { 65 | return GRAFANA_PANEL_TABLE_PATH; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/java/com/webank/blockchain/data/export/grafana/GrafanaParas.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Webank. 3 | * 4 | *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 | * except in compliance with the License. You may obtain a copy of the License at 6 | * 7 | *

http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | *

Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | package com.webank.blockchain.data.export.grafana; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * GrafanaParas 20 | * 21 | * @Description: GrafanaParas 22 | * @author maojiayu 23 | * @param 24 | * @data Mar 28, 2019 11:05:12 AM 25 | * 26 | */ 27 | public interface GrafanaParas extends AtomicParas> { 28 | 29 | public String getGeneratedFilePath(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/main/resources/templates/grafana/panel_table.txt: -------------------------------------------------------------------------------- 1 | { 2 | "columns": [], 3 | "datasource": "MySQL", 4 | "fontSize": "110%", 5 | "gridPos": { 6 | "h": 8, 7 | "w": 24, 8 | "x": ${gridXPos}, 9 | "y": ${gridYPos} 10 | }, 11 | "id": ${id}, 12 | "links": [], 13 | "pageSize": 10, 14 | "scroll": true, 15 | "showHeader": true, 16 | "sort": { 17 | "col": 0, 18 | "desc": true 19 | }, 20 | "styles": [ 21 | { 22 | "alias": "depot_updatetime", 23 | "dateFormat": "YYYY-MM-DD HH:mm:ss", 24 | "pattern": "depot_updatetime", 25 | "type": "number" 26 | }, 27 | { 28 | "alias": "", 29 | "colorMode": "value", 30 | "colors": [ 31 | "#73BF69", 32 | "rgba(237, 129, 40, 0.89)", 33 | "rgba(245, 54, 54, 0.9)" 34 | ], 35 | "decimals": 0, 36 | "pattern": "block_height", 37 | "thresholds": [], 38 | "type": "string", 39 | "unit": "short" 40 | }, 41 | { 42 | "alias": "", 43 | "colorMode": "value", 44 | "colors": [ 45 | "#73BF69", 46 | "rgba(237, 129, 40, 0.89)", 47 | "rgba(245, 54, 54, 0.9)" 48 | ], 49 | "decimals": 0, 50 | "pattern": "pk_id", 51 | "thresholds": [], 52 | "type": "string", 53 | "unit": "short" 54 | } 55 | ], 56 | "targets": [ 57 | { 58 | "format": "table", 59 | "group": [], 60 | "metricColumn": "none", 61 | "rawQuery": true, 62 | "rawSql": "select * from ${table_name} order by depot_updatetime;", 63 | "refId": "A", 64 | "select": [ 65 | [ 66 | { 67 | "params": [ 68 | "value" 69 | ], 70 | "type": "column" 71 | } 72 | ] 73 | ], 74 | "timeColumn": "time", 75 | "where": [ 76 | { 77 | "name": "$__timeFilter", 78 | "params": [], 79 | "type": "macro" 80 | } 81 | ] 82 | } 83 | ], 84 | "timeFrom": null, 85 | "timeShift": null, 86 | "title": "${title}", 87 | "transform": "table", 88 | "type": "table" 89 | } -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/test/java/com/webank/blockchain/data/export/grafana/GrafanaDashboardParasTest.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.grafana; 2 | 3 | 4 | import com.google.common.collect.ImmutableList; 5 | import com.google.common.collect.ImmutableMap; 6 | import com.google.common.collect.Maps; 7 | import com.webank.blockchain.data.export.config.ServiceConfig; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.mockito.Mock; 11 | import org.mockito.MockitoAnnotations; 12 | import org.springframework.test.util.ReflectionTestUtils; 13 | 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | import static org.junit.Assert.assertTrue; 18 | import static org.mockito.Mockito.when; 19 | 20 | 21 | public class GrafanaDashboardParasTest { 22 | private static String PREFIX = "prefix"; 23 | private static String SUFFIX = "suffix"; 24 | private static List INFOLIST = ImmutableList.of("test-str1"); 25 | 26 | @Mock 27 | private ServiceConfig mockServiceConfig; 28 | 29 | @Before 30 | public void setUp() { 31 | MockitoAnnotations.initMocks(this); 32 | when(mockServiceConfig.getTablePrefix()).thenReturn(PREFIX); 33 | when(mockServiceConfig.getTablePostfix()).thenReturn(SUFFIX); 34 | } 35 | 36 | @Test 37 | public void testGetMap() { 38 | Map expectedMap = ImmutableMap.of( 39 | "panels", INFOLIST, 40 | "block_task_pool", PREFIX + "block_task_pool" + SUFFIX, 41 | "block_detail_info", PREFIX + "block_detail_info" + SUFFIX, 42 | "block_tx_detail_info", PREFIX + "block_tx_detail_info" + SUFFIX, 43 | "deployed_account_info", PREFIX + "deployed_account_info" + SUFFIX 44 | ); 45 | GrafanaDashboardParas grafanaDashboardParas = new GrafanaDashboardParas(); 46 | ReflectionTestUtils.setField(grafanaDashboardParas, "config", mockServiceConfig); 47 | Map actualMap = grafanaDashboardParas.getMap(INFOLIST); 48 | assertTrue(Maps.difference(expectedMap, actualMap).areEqual()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WeBankBlockchain-Data-Export-service/src/test/java/com/webank/blockchain/data/export/utils/PropertiesUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.webank.blockchain.data.export.utils; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.mockito.Mock; 6 | import org.mockito.MockitoAnnotations; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.test.util.ReflectionTestUtils; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.mockito.Mockito.when; 12 | 13 | 14 | public class PropertiesUtilsTest { 15 | @Mock 16 | private Environment mockEnvironment; 17 | 18 | @Before 19 | public void setUp() { 20 | MockitoAnnotations.initMocks(this); 21 | when(mockEnvironment.getProperty("com.webank.blockchain")).thenReturn("expectedEnv"); 22 | } 23 | 24 | @Test 25 | public void testGetProperty() { 26 | PropertiesUtils propertiesUtils = new PropertiesUtils(); 27 | ReflectionTestUtils.setField(propertiesUtils, "environment", mockEnvironment); 28 | String env = propertiesUtils.getProperty("com", "webank", "blockchain"); 29 | assertEquals("expectedEnv", env); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "org.springframework.boot" version "2.2.8.RELEASE" 3 | id "io.spring.dependency-management" version "1.0.9.RELEASE" 4 | id 'eclipse' 5 | id 'idea' 6 | id 'maven' 7 | id 'java' 8 | } 9 | 10 | allprojects { 11 | repositories { 12 | maven { 13 | url "http://maven.aliyun.com/nexus/content/groups/public/" 14 | } 15 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 16 | maven { url "https://dl.bintray.com/ethereum/maven/" } 17 | mavenLocal() 18 | jcenter() 19 | } 20 | } 21 | 22 | subprojects{ 23 | version = "1.7.9" 24 | group = 'com.webank' 25 | } 26 | 27 | def log4j_version="2.16.0" 28 | List logger = [ 29 | "org.apache.logging.log4j:log4j-api:$log4j_version", 30 | "org.apache.logging.log4j:log4j-core:$log4j_version", 31 | "org.apache.logging.log4j:log4j-to-slf4j:$log4j_version", 32 | ] 33 | 34 | project(':WeBankBlockchain-Data-Export-service') { 35 | apply plugin: "java" 36 | apply plugin: "org.springframework.boot" 37 | apply plugin: "io.spring.dependency-management" 38 | springBoot { 39 | buildInfo() 40 | } 41 | def solcVersion = rootProject.hasProperty('solcVersion') ? solcVersion : "0.6.10.0" 42 | 43 | javadoc { 44 | def defaultEncoding = 'UTF-8' 45 | options.encoding = defaultEncoding 46 | options.addBooleanOption('Xdoclint:none', true) 47 | } 48 | 49 | dependencies { 50 | compile logger 51 | implementation 'org.springframework.boot:spring-boot-starter-web' 52 | compile 'org.springframework.boot:spring-boot-starter-data-jpa' 53 | compileOnly 'org.projectlombok:lombok:1.18.10' 54 | annotationProcessor 'org.projectlombok:lombok:1.18.10' 55 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 56 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 57 | } 58 | implementation ('com.webank:solc-gradle-plugin:1.0.0'){ 59 | exclude group: 'org.slf4j', module: 'slf4j-log4j12' 60 | } 61 | implementation project(':WeBankBlockchain-Data-Export-sdk') 62 | implementation('com.ibeetl:beetl:2.9.3') 63 | implementation "org.fisco-bcos:solcJ:${solcVersion}" 64 | testImplementation "junit:junit:4.13" 65 | } 66 | } 67 | 68 | configurations { 69 | all { 70 | exclude group: 'org.slf4j', module: 'slf4j-log4j12' 71 | resolutionStrategy.cacheChangingModulesFor 0, 'seconds' 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/Data-Export/16101f24294d0f1740dec0de6754e6d60d8cb099/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Apr 02 15:47:37 CST 2021 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Data-Export' 2 | include 'WeBankBlockchain-Data-Export-service','WeBankBlockchain-Data-Export-sdk' 3 | -------------------------------------------------------------------------------- /tools/config/solidity/HelloWorld.sol: -------------------------------------------------------------------------------- 1 | pragma solidity>=0.4.24 <0.6.11; 2 | 3 | contract HelloWorld { 4 | string name; 5 | 6 | constructor() public { 7 | name = "Hello, World!"; 8 | } 9 | 10 | function get() public view returns (string memory) { 11 | return name; 12 | } 13 | 14 | function set(string memory n) public { 15 | name = n; 16 | } 17 | } -------------------------------------------------------------------------------- /tools/start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | LANG=zh_CN.UTF-8 3 | 4 | CONFIGPATH="./config/application.properties" 5 | solcVersion=`awk -F '=' '$1~/system.solcVersion/{print $2;exit}' ${CONFIGPATH}` 6 | 7 | cd ../WeBankBlockchain-Data-Export-service 8 | 9 | function LOG_INFO() 10 | { 11 | local content=${1} 12 | echo -e "\033[32m"${content}"\033[0m" 13 | } 14 | 15 | GRADLE_EXEC="bash gradlew " 16 | while getopts "c:" arg 17 | do 18 | case $arg in 19 | c) 20 | execArg=$(echo "$OPTARG" | tr '[:upper:]' '[:lower:]') 21 | if [ "$execArg" != "gradle" ] && [ "$execArg" != "gradlew" ]; then 22 | LOG_ERROR "-c execute mode: [gradlew|gradle]" 23 | elif [ "$execArg" == "gradle" ]; then 24 | GRADLE_EXEC=$execArg 25 | LOG_INFO "Begin to use gradle" 26 | else 27 | LOG_INFO "Begin to use gradle wrapper" 28 | fi 29 | ;; 30 | ?) 31 | LOG_ERROR "unkonw argument\nusage: -c [gradle|gradlew]" 32 | exit 1 33 | ;; 34 | esac 35 | done 36 | 37 | $GRADLE_EXEC clean bootJar -PsolcVersion=$solcVersion 38 | echo "gradle build finish..." 39 | 40 | cp dist/Data-Export*.jar ../tools 41 | cd ../tools 42 | 43 | echo "copy Data-Export.jar success..." 44 | 45 | echo "run Data-Export.jar" 46 | 47 | java -jar Data-Export*.jar --spring.config.location=./config/application.properties 48 | -------------------------------------------------------------------------------- /tools/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pgrep -f Data-Export | xargs kill -9 --------------------------------------------------------------------------------