diff --git a/database/bcevent.sql b/database/bcevent.sql new file mode 100644 index 0000000..18806de --- /dev/null +++ b/database/bcevent.sql @@ -0,0 +1,67 @@ +-- MySQL dump 10.14 Distrib 5.5.41-MariaDB, for Linux (x86_64) +-- +-- Host: localhost Database: bcevent +-- ------------------------------------------------------ +-- Server version 5.5.41-MariaDB + +-- +-- Table structure for table `version` +-- + +DROP TABLE IF EXISTS `version`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `version` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `version` int(11) NOT NULL DEFAULT '0' COMMENT '版本号', + PRIMARY KEY (`idx`), + UNIQUE KEY `version` (`version`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `t_blockchain_event` +-- + +DROP TABLE IF EXISTS `t_blockchain_event`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_blockchain_event` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `txhash` varchar(255) NOT NULL DEFAULT '' COMMENT 'txhash', + `log_index` bigint NOT NULL DEFAULT '0' COMMENT 'log_index', + `hash_code` varchar(60) NOT NULL DEFAULT '' COMMENT 'hash_code', + `net_id` bigint NOT NULL DEFAULT '0' COMMENT 'net_id', + `event_name` varchar(60) NOT NULL DEFAULT '' COMMENT 'event_name', + `contract_address` varchar(60) NOT NULL DEFAULT '' COMMENT 'contract_address', + `contract_name` varchar(60) NOT NULL DEFAULT '' COMMENT 'contract_name', + `block_number` bigint NOT NULL DEFAULT '0' COMMENT 'block_number', + `raw_data` mediumblob COMMENT 'raw_data', + `return_values` mediumblob COMMENT 'return_values', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `unikey` (`txhash`, `hash_code`, `log_index`, `net_id`, `event_name`, `contract_address`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `t_last_block` +-- + +DROP TABLE IF EXISTS `t_last_block`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_last_block` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `net_id` bigint NOT NULL DEFAULT '0' COMMENT 'net_id', + `contract_address` varchar(60) NOT NULL DEFAULT '' COMMENT 'contract_address', + `contract_name` varchar(60) NOT NULL DEFAULT '' COMMENT 'contract_name', + `event_name` varchar(60) NOT NULL DEFAULT '' COMMENT 'event_name', + `block_number` bigint NOT NULL DEFAULT '0' COMMENT 'block_number', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `unikey` (`net_id`, `contract_address`, `event_name`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; diff --git a/server/web3bcspider/services/pull_bcevent.js b/server/web3bcspider/services/pull_bcevent.js index c03c8ac..910e049 100644 --- a/server/web3bcspider/services/pull_bcevent.js +++ b/server/web3bcspider/services/pull_bcevent.js @@ -161,10 +161,12 @@ class PullBcEvent extends BaseService { while (true) { const nowTime = utils.getUtcTime(); const returnValues = event['returnValues']; + const hashCode = ''; const {err} = await this.conn.upsert( 't_blockchain_event', [ ['txhash', event['transactionHash']], + ['hash_code', hashCode], ['log_index', event['logIndex']], ['net_id', this.bc.getNetId()], ['event_name', this.getEventName()], @@ -174,6 +176,7 @@ class PullBcEvent extends BaseService { ], [ ['txhash', event['transactionHash']], + ['hash_code', hashCode], ['log_index', event['logIndex']], ['net_id', this.bc.getNetId()], ['event_name', this.getEventName()],