drop table if exists eth_block;
CREATE TABLE `eth_block` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `block_no` int(11) DEFAULT 0,
 `block_hash` varchar(68) DEFAULT NULL,
 `txn_cnt` int(11) DEFAULT 0 COMMENT '트랜잭션 갯수',
 `uncle_cnt` int(11) DEFAULT 0 COMMENT '엉클블록 갯수',
 `miner` varchar(50) DEFAULT NULL COMMENT '채굴 Account Address',
 `gas_used` decimal(11,0) DEFAULT NULL COMMENT '개스 사용여부 0:아님, 1.:사용',
 `gas_limit` decimal(11,0) DEFAULT NULL,
 `trfee_sum` decimal(32,0) DEFAULT NULL COMMENT '트랜잭션 fee 합계',
 `reward` decimal(32,0) DEFAULT NULL COMMENT '블록 보상액',
 `uncle_reward` decimal(32,0) DEFAULT 0 COMMENT '엉클블록 보상액',
 `status` smallint(6) DEFAULT 0 COMMENT '비정상:0, 정상:1',
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_block_no` (`block_no`,`block_hash`),
 KEY `idx_block_hash` (`block_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_cntr_member;
CREATE TABLE `eth_cntr_member` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT NULL,
 `updated_on` bigint(20) DEFAULT NULL,
 `token_name` varchar(128) DEFAULT NULL,
 `cntr_addr` varchar(64) DEFAULT NULL,
 `member_id` int(11) NOT NULL,
 `status` char(16) NOT NULL DEFAULT '0' COMMENT '0:미정, 1:인증',
 `ip` varchar(16) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_circul_sum;
CREATE TABLE `eth_circul_sum` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) NOT NULL COMMENT '해당일-Unixtime',
 `sum_date` char(8) DEFAULT '' COMMENT '집계일자:sum_date+erc_type+cntr_addr->uniqueKey',
 `erc_type` varchar(10) NOT NULL DEFAULT 0 COMMENT 'main, erc20, erc721, erc1155',
 `cntr_addr` varchar(64) NOT NULL DEFAULT '' COMMENT 'main 또는 컨트렉트 주소',
 `daily_circul_sum` decimal(34,0) NOT NULL DEFAULT 0 COMMENT '일유통량',
 `add_block_cnt` bigint(20) DEFAULT 0 COMMENT '추가된 블록수',
 `reward_sum` decimal(23,7) DEFAULT 0.0000000 COMMENT '보상합계',
 `acc_reward_sum` decimal(23,7) DEFAULT 0.0000000 COMMENT '계정별 보상합계',
 `txn_cnt` int(11) DEFAULT 0 COMMENT '트랜잭션 갯수',
 `txn_fail_cnt` int(11) DEFAULT 0 COMMENT '실패한트랜잭션 갯수',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

drop table if exists eth_contract;
CREATE TABLE `eth_contract` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `txn_hash` varchar(66) DEFAULT NULL,
 `block_no` bigint(11) DEFAULT NULL,
 `cntr_addr` varchar(64) DEFAULT NULL COMMENT 'main or 컨트랙트 주소',
 `creator_addr` varchar(64) DEFAULT NULL,
 `balance` decimal(16,0) DEFAULT 0,
 `txn_cnt` int(11) DEFAULT 0,
 `order_by` tinyint(4) NOT NULL DEFAULT 0 COMMENT '리스트 순서',
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_tx_hash` (`txn_hash`),
 UNIQUE KEY `idx_contract_addr` (`cntr_addr`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_contract_abi;
CREATE TABLE `eth_contract_abi` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `cntr_addr` varchar(64) DEFAULT NULL COMMENT '컨트랙트 주소',
 `cntr_id` int(11) NOT NULL,
 `member_id` int(11) DEFAULT NULL,
 `cntr_name` varchar(64) NOT NULL,
 `compiler` varchar(64) DEFAULT NULL,
 `version` varchar(64) DEFAULT NULL,
 `veried` varchar(64) DEFAULT NULL,
 `license` varchar(64) DEFAULT NULL COMMENT '소유자 입력',
 `abi_code` mediumtext DEFAULT NULL COMMENT '사용abi 코드 입력',
 `create_code` mediumtext NOT NULL COMMENT '사용코드 입력',
 `ip` varchar(20) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_contract_sol;
CREATE TABLE `eth_contract_sol` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `cntr_addr` varchar(64) DEFAULT NULL,
 `cntr_id` int(11) NOT NULL,
 `member_id` int(11) DEFAULT NULL,
 `file_name` varchar(256) DEFAULT NULL,
 `sol_code` mediumtext DEFAULT NULL COMMENT '솔리디티 코드',
 `ip` varchar(20) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_last_sync;
CREATE TABLE `eth_last_sync` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `created_on` bigint(11) NOT NULL,
 `updated_on` bigint(11) NOT NULL,
 `sync_type` varchar(32) NOT NULL,
 `last_no` varchar(32) NOT NULL DEFAULT '1' COMMENT '마지막 싱크블록 번호를 넣음',
 `sync_range` varchar(64) NOT NULL,
 `sync_cnt` int(11) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_token;
CREATE TABLE `eth_token` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `update_on` bigint(20) NOT NULL DEFAULT 0,
 `cntr_addr` varchar(64) DEFAULT NULL,
 `token_name` varchar(20) DEFAULT NULL,
 `wei_decimals` smallint(10) DEFAULT NULL COMMENT 'wei단위 적용 소숫점',
 `curr_bal_qty` decimal(32,0) DEFAULT NULL COMMENT '현재 잔량',
 `symbol` varchar(21) DEFAULT '' COMMENT '토큰 심볼',
 `total_circul_qty` decimal(30,0) NOT NULL DEFAULT 0 COMMENT '총공급량',
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_cntr_addr` (`cntr_addr`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_token_add;
CREATE TABLE `eth_token_add` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `updated_on` bigint(20) DEFAULT 0,
 `cntr_addr` varchar(64) DEFAULT NULL,
 `icon_image` varchar(500) DEFAULT NULL,
 `unit_point` tinyint(4) NOT NULL DEFAULT 0,
 `decimal_point` tinyint(4) NOT NULL DEFAULT 0,
 `fee_point` tinyint(4) NOT NULL DEFAULT 0,
 `token_desc` tinytext DEFAULT NULL,
 `site_url` varchar(256) DEFAULT NULL,
 `sns_url` varchar(256) DEFAULT NULL,
 `token_tracker` varchar(128) DEFAULT NULL,
 `ip` varchar(20) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_token_holder;
CREATE TABLE `eth_token_holder` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `cntr_addr` varchar(66) DEFAULT NULL,
 `holder_addr` varchar(66) DEFAULT NULL,
 `total_sum` decimal(30,0) DEFAULT NULL,
 `last_sum` decimal(30,0) DEFAULT 0,
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_token_holder` (`cntr_addr`,`holder_addr`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_trans_inter;
CREATE TABLE `eth_trans_inter` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `block_no` int(11) DEFAULT NULL,
 `block_hash` varchar(68) DEFAULT NULL,
 `parent_txn_hash` varchar(66) DEFAULT NULL,
 `cntr_addr` varchar(66) DEFAULT NULL,
 `txn_hash` varchar(66) DEFAULT NULL,
 `from_addr` varchar(66) DEFAULT NULL,
 `to_addr` varchar(66) DEFAULT NULL,
 `txn_type` varchar(50) DEFAULT NULL,
 `value` decimal(32,0) DEFAULT 0,
 `gas_used` decimal(32,0) DEFAULT 0,
 `gas` decimal(32,0) DEFAULT 0,
 `input` blob DEFAULT NULL,
 `err` varchar(500) DEFAULT '',
 `status` int(11) DEFAULT 0,
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_block_no` (`block_no`,`block_hash`,`parent_txn_hash`),
 KEY `idx_hash` (`txn_hash`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_trans_inter;
CREATE TABLE `eth_tranxn` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `block_no` int(11) DEFAULT NULL,
 `block_hash` varchar(66) DEFAULT NULL,
 `txn_hash` varchar(66) DEFAULT NULL,
 `cntr_addr` varchar(66) DEFAULT NULL,
 `from_addr` varchar(66) DEFAULT NULL,
 `to_addr` varchar(66) DEFAULT NULL,
 `txn_type` varchar(50) DEFAULT NULL,
 `txn_symbol` varchar(120) NOT NULL DEFAULT '',
 `value` decimal(32,0) DEFAULT 0,
 `input_value` decimal(32,0) NOT NULL DEFAULT 0,
 `txn_fee` decimal(16,8) DEFAULT 0.00000000,
 `input` blob DEFAULT NULL,
 `gas_used` decimal(11,0) NOT NULL DEFAULT 0,
 `status` int(11) NOT NULL DEFAULT -1,
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_hash` (`txn_hash`),
 KEY `cntr_addr` (`cntr_addr`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

drop table if exists eth_txn_transfer;
CREATE TABLE `eth_txn_transfer` (
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `block_no` bigint(20) DEFAULT 0,
 `block_hash` varchar(66) DEFAULT NULL,
 `txn_hash` varchar(66) DEFAULT '',
 `tx_index` int(11) DEFAULT 0,
 `index` int(11) DEFAULT 0,
 `from_addr` varchar(66) DEFAULT '',
 `to_addr` varchar(66) DEFAULT '',
 `input_value` decimal(32,0) DEFAULT 0,
 `topic` blob DEFAULT NULL,
 `removed` smallint(6) DEFAULT 0,
 `cntr_addr` varchar(64) DEFAULT NULL,
 `log_cntr_addr` varchar(64) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `txn_idx` (`txn_hash`,`tx_index`,`index`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

drop table if exists eth_uncle_block;
CREATE TABLE `eth_uncle_block` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `created_on` bigint(20) DEFAULT 0,
 `block_no` int(11) DEFAULT 0,
 `block_hash` varchar(68) DEFAULT NULL,
 `uncle_no` int(11) DEFAULT 0,
 `uncle_hash` varchar(68) DEFAULT NULL,
 `uncle_position` int(11) DEFAULT 0,
 `miner` varchar(50) DEFAULT NULL,
 `gas_used` decimal(11,0) DEFAULT NULL,
 `gas_limit` decimal(11,0) DEFAULT NULL,
 `uncle_reward` decimal(32,0) DEFAULT 0,
 PRIMARY KEY (`id`),
 UNIQUE KEY `idx_uncle_no` (`uncle_no`,`uncle_hash`),
 KEY `idx_block_no` (`block_no`,`block_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
