# 棰勮█鏈烘湇鍔℃妧鏈柟妗� ## 姒傝堪 `闀垮畨閾韭烽瑷€鏈篳v1.0.0_alpha鐗堟湰鏄竴绉嶄腑蹇冨寲鐨勫彲鍒嗗竷寮忛儴缃茬殑棰勮█鏈猴紝涓洪暱瀹夐摼閾句笂銆侀摼涓嬫暟鎹殑浜や簰鎻愪緵浜嗕竴涓ˉ姊併€傜敤鎴峰彲浠ラ€氳繃鏅鸿兘鍚堢害璋冪敤鏉ヨ幏鍙栭摼涓嬬殑鎺ュ彛鏁版嵁銆佹寚瀹氱殑鏁版嵁搴撴暟鎹€乂RF锛堝彲楠岃瘉闅忔満鏁版暟鎹級浠ュ強鍊熷姪鏅鸿兘鍚堢害鍋氳法閾炬暟鎹殑鏌ヨ锛屽悓鏃朵篃鎻愪緵浜嗘敞鍐屾煡璇opic/鎸夌収topic鏌ヨ鐨勫姛鑳戒互绠€鍖栫敤鎴蜂娇鐢ㄣ€� ## 璁捐 ### 鏁翠綋娴佺▼ - 鐢ㄦ埛鍦ㄦ櫤鑳藉悎绾︿腑璋冪敤`棰勮█鏈烘櫤鑳藉悎绾涓殑鍙栨暟鎹柟娉曪紝`棰勮█鏈烘櫤鑳藉悎绾鏍¢獙鐩稿簲鍙傛暟锛屽彂閫佺浉搴旂殑閾句簨浠� - `棰勮█鏈烘湇鍔鐩戝惉鍒伴摼涓婂彇鏁版嵁浜嬩欢锛屾牴鎹悎绾︿腑鎸囧畾鐨勫彇鏁版嵁閰嶇疆锛岃繘琛屾暟鎹殑鑾峰彇 - `棰勮█鏈烘湇鍔灏嗗彇鍒版暟鎹€氳繃璋冪敤`棰勮█鏈烘櫤鑳藉悎绾鏂规硶鏉ュ皢鏁版嵁鍥炰紶锛宍棰勮█鏈烘櫤鑳藉悎绾閫氳繃鍥炶皟鐢ㄦ埛鏅鸿兘鍚堢害鍛婄煡鐢ㄦ埛鏁版嵁鍙栧埌锛岀敤鎴峰悎绾﹀仛鐩稿簲涓氬姟澶勭悊鍗冲彲  <center> 棰勮█鏈烘櫤鑳藉悎绾︾殑閴存潈鏂规</center> ### 棰勮█鏈烘湇鍔¤璁� `棰勮█鏈烘湇鍔鏁翠綋鍙互鍒嗕负鍥涗釜妯″潡銆傜敱鐩戝惉鍒扮殑閾句笂`棰勮█鏈烘櫤鑳藉悎绾浜嬩欢杩涜椹卞姩,鍚勪釜妯″潡閰嶅悎杩愯瀹屾垚鍙栨暟鎹姛鑳姐€傛湇鍔″皢杩愯涓墍闇€鏁版嵁淇濆瓨鍒版湰鍦扮殑`mysql`鏁版嵁搴撲腑銆� - 棰勮█鏈虹姸鎬佹祦杞ā鍧� - 鍙栨暟鎹ā鍧� - 棰勮█鏈烘帴鍙fā鍧� - 棰勮█鏈哄憡璀︽ā鍧�  <center> 棰勮█鏈篠erver缁撴瀯</center> #### 棰勮█鏈鸿〃璁捐 `棰勮█鏈烘湇鍔灏嗘湇鍔¤繍琛屾墍闇€鏁版嵁瀛樺偍鍒颁簡`mysql`鏁版嵁搴撲腑銆� - `鍚堢害琛�(oracle_contracts)`涓昏璁板綍閫氳繃鎺ュ彛瀹夎鐨勯瑷€鏈哄悎绾︿俊鎭€傚悎绾︾殑瀹夎銆佸崌绾ч兘浼氬啓鍏ュ埌琛ㄤ腑銆俙棰勮█鏈烘湇鍔鐩戝惉閾句笂鐨勪簨浠堕渶瑕佹彁渚涘簭鍙凤紝鍥犳鍦╜棰勮█鏈烘湇鍔澶勭悊瀹岀浉鍏充簨浠跺悗锛屼篃浼氬皢浜嬩欢搴忓彿鐨勫彉鍖栨洿鏂板埌琛ㄤ腑 ```sql CREATE TABLE if NOT exists `oracle_contracts`( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '鑷id', `chain_alias` varchar(128) NOT NULL COMMENT '閾惧埆鍚�', `chain_id` varchar(128) NOT NULL COMMENT '閾緄d', `contract_name` varchar(128) NOT NULL COMMENT '鍚堢害鍚嶇О', `contract_version` int NOT NULL DEFAULT '1' COMMENT '鍚堢害鐗堟湰', `deployed` tinyint NOT NULL DEFAULT '0' COMMENT '鏄惁閮ㄧ讲杩囷紝榛樿涓�0鏈儴缃诧紝1涓哄凡缁忛儴缃�', `runtime_type` tinyint NOT NULL DEFAULT '6' COMMENT '1 涓虹郴缁熷悎绾︼紱2 涓簉ust; 3 涓篶++; 4涓簍inygo; 5涓簊olidity; 6涓篻o', `topic_query_start` bigint unsigned NOT NULL COMMENT '璁㈤槄鈥滄煡璇簨浠垛€濈殑璧峰浣嶇疆', `topic_finish_start` bigint unsigned NOT NULL COMMENT '璁㈤槄鈥滅粨鏉熶簨浠垛€濈殑璧峰浣嶇疆', `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '鍒涘缓鏃堕棿', `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `idx_c_c` (`chain_alias`,`contract_name`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='鍚堢害鎯呭喌琛ㄦ牸'; ``` - `浜嬩欢鐘舵€佽〃(event_state)`璁板綍浜嗕粠閾句笂鐩戝惉浜嬩欢鍒版暣涓簨浠舵祦杞畬鏁寸殑鍚勪釜闃舵 ```sql CREATE TABLE if NOT exists `event_state`( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '鑷id', `chain_alias` varchar(128) NOT NULL, `request_id` varchar(256) NOT NULL COMMENT '璇锋眰id', `tx_id` varchar(128) NOT NULL COMMENT '浜ゆ槗id', `contract_name` varchar(128) NOT NULL COMMENT '鍚堢害鍚嶇О', `state` tinyint NOT NULL DEFAULT '0' COMMENT '0锛歋tateInit 锛�1锛歋tateFetchDataFailed 锛� 2锛� StateFetchDataSucess 锛� 3锛� StateCallbackFailed 锛� 4锛歋tateCallbackSuccess 锛� 5锛歋tateResultOnChainSuccess锛堢粓姝㈡€侊級 锛�6锛歋tateCallbackFailedFibnoacci锛堝娆¤皟閾惧け璐ョ粓姝㈡€侊級', `query_type` tinyint NOT NULL DEFAULT '1' COMMENT '鏌ヨ绫诲瀷鏋氫妇 1锛歶se_http锛�2锛歶se_db ', `query_body` mediumblob NOT NULL COMMENT '鍏蜂綋鐨勬煡璇㈡柟妗堬紝鏆傚畾涓哄簭鍒楀寲鍚庣殑json瀛楃涓�', `next_fibonacci` bigint unsigned NOT NULL DEFAULT '0' COMMENT '涓婇摼澶辫触鏃跺€檉eibonacci閲嶈瘯璁板綍', `block_height` bigint unsigned NOT NULL DEFAULT '1' COMMENT '褰撳墠浜嬩欢鐨勫尯鍧楅珮搴�', `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '鍒涘缓鏃堕棿', `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '鏇存柊鏃堕棿', PRIMARY KEY (`id`), UNIQUE KEY `uniq_s_c_r` (`request_id`) COMMENT '''璇锋眰id鍞竴绱㈠紩''', KEY `updated_state` (`updated_at`,`state`), KEY `created_state` (`created_at`,`state`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='浜嬩欢鐘舵€佽〃鏍�' ; ``` - `棰勮█鏈哄彇鏁版嵁杩斿洖鍊煎瓨鍌ㄨ〃(event_result)`瀛樺偍浜嗛瑷€鏈哄彇鍒扮殑鏁版嵁缁撴灉 ```sql CREATE TABLE if NOT exists `event_result` ( `request_id` varchar(256) NOT NULL COMMENT '璇锋眰id锛屽敮涓€绱㈠紩', `event_result` mediumblob NOT NULL COMMENT '鍙栧埌鐨勬暟鎹�', `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '閾緄d', PRIMARY KEY (`request_id`), KEY `created_at` (`created_at`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='棰勮█鏈哄彇鏁版嵁杩斿洖鍊煎瓨鍌ㄨ〃' ; ``` - `浜嬩欢閿佽〃(event_lock)`鐢ㄤ簬鍗忚皟澶氫釜`棰勮█鏈烘湇鍔″疄渚媊杩涜宸ヤ綔 ```sql CREATE TABLE if NOT exists `event_lock` ( `request_id` varchar(256) NOT NULL COMMENT '璇锋眰id', `locked_version` int NOT NULL DEFAULT '0' COMMENT '閿�', `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '鏇存柊鏃惰褰�', PRIMARY KEY (`request_id`) COMMENT '璇锋眰id鍞竴绱㈠紩', KEY `updated_at` (`updated_at`), KEY `request_updated` (`request_id`,`updated_at`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='浜嬩欢閿�' ; ``` - `vrf琛ㄦ牸(vrfs)`璁板綍浜唙rf鐨勫叕閽ュ拰绉侀挜淇℃伅锛屽叾涓璼rv_name涓哄敮涓€绱㈠紩锛堢郴缁熷啓鐨勶級銆傚涓疄渚嬪鏋滆繛鎺ュ埌鍚屼竴涓猰ysql瀹炰緥锛岄偅涔堜粬浠叡浜悓涓€涓獀rf鍏閽ワ紝鍚勪釜瀹炰緥鐢熸垚vrf鏄竴鑷寸殑 ```sql CREATE TABLE if NOT exists `vrfs`( `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '涓婚敭', `privatek` blob NOT NULL COMMENT '绉侀挜', `publick` blob NOT NULL COMMENT '鍏挜', `srv_name` varchar(128) NOT NULL COMMENT '鏈嶅姟鍚嶇О锛屽敮涓€绱㈠紩', PRIMARY KEY (`id`), UNIQUE KEY `uniq-s` (`srv_name`) COMMENT '鍒╃敤鏈嶅姟鍚嶇О浣滃敮涓€绱㈠紩' ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='vrf琛ㄦ牸'; ``` #### 棰勮█鏈虹姸鎬佹祦杞ā鍧� `棰勮█鏈烘湇鍔鐩戝惉浜嬩欢锛屽彇鏁版嵁锛屽洖浼犳暟鎹埌閾句笂鏁翠釜娴佺▼鎶借薄鎴愪负涓€涓湁闄愮姸鎬佹満鏉ヨ繘琛屽疄鐜帮紝鐘舵€佽縼绉诲涓嬪浘  <center>api鎺ュ彛妯″潡</center> #### 棰勮█鏈哄憡璀︽ā鍧� `棰勮█鏈烘湇鍔鍦ㄥ皢鏁版嵁閫氳繃璋冪敤`棰勮█鏈哄悎绾鍥炶皟閾剧殑鏃跺€欏彲鑳戒細鍙戠敓閿欒锛屾垜浠緷鎹甪ibonacci閲嶈瘯鐨勭瓥鐣ヨ繘琛岄噸璇�,褰撻噸璇曟鏁拌秴杩囩敤鎴烽厤缃殑鏈€澶у€�(閰嶇疆椤逛负fibonacci_limits)鏃跺€欙紝浼氭牴鎹敤鎴烽厤缃紙閰嶇疆椤逛负alarmer锛夌殑鎶ヨ鏂瑰紡杩涜鎶ヨ  <center>鍛婅妯″潡</center> ## 浠g爜鏁翠綋鐩綍缁撴瀯 ```bash . 鈹溾攢鈹€ alarms # 鍛婅妯″潡鐨勪唬鐮佸寘 鈹溾攢鈹€ config # 璇诲彇閰嶇疆妯″潡鐨勪唬鐮佸寘 鈹溾攢鈹€ config_files # 閰嶇疆鏂囦欢 鈹� 鈹溾攢鈹€ crypto-config # 浣跨敤chainmaker-cryptogen 宸ュ叿鐢熸垚鐨勮瘉涔︽枃浠� 鈹� 鈹溾攢鈹€ sdk-config # 閾緎dk閰嶇疆 鈹� 鈹� 鈹溾攢鈹€ sdk_config_chain1.yml # 閾�1鐨剆dk 鈹� 鈹� 鈹斺攢鈹€ sdk_config_chain2.yml # 閾�2鐨剆dk 鈹� 鈹斺攢鈹€ smart_oracle.yml # 棰勮█鏈烘湇鍔$殑閰嶇疆鏂囦欢 鈹溾攢鈹€ contract_process # 棰勮█鏈烘湇鍔℃牳蹇冧笟鍔¢€昏緫鐨勪唬鐮佸寘 鈹溾攢鈹€ custom.cnf # 鍙互鍙傝€冭繖涓厤缃潵閰嶇疆docker涓殑mysql鏁版嵁搴擄紙5.7 鍙婁互鍚庯級 鈹溾攢鈹€ databases # 杩炴帴鏁版嵁搴撴ā鍧楃殑浠g爜鍖� 鈹溾攢鈹€ docker-compose.yml # docker-compose 妯℃澘鏂囦欢 鈹溾攢鈹€ Dockerfile # docker 闀滃儚鏂囦欢 鈹溾攢鈹€ fetch_data # 鍙栨暟鎹ā鍧椾唬鐮佸寘 鈹溾攢鈹€ http_server_process # 棰勮█鏈篽ttp鏈嶅姟鎺ュ彛浠g爜鍖� 鈹溾攢鈹€ install-upgrade-oracle-contract.sh #棰勮█鏈哄悎绾﹀畨瑁呫€佸崌绾ц剼鏈� 鈹溾攢鈹€ logger # 鏃ュ織妯″潡浠g爜鍖� 鈹溾攢鈹€ main.go # 鏈嶅姟鍏ュ彛 鈹溾攢鈹€ Makefile 鈹溾攢鈹€ models # 棰勮█鏈烘暟鎹ā鍨嬪寘 鈹溾攢鈹€ mysql-data-volumes # 榛樿鐨刣ocker-compose鍚姩mysql鏁版嵁搴撶殑鏁版嵁鎸傝浇鐐� 鈹� 鈹斺攢鈹€ data 鈹溾攢鈹€ readme.md 鈹溾攢鈹€ scripts # mysql寤哄簱鑴氭湰 鈹� 鈹斺攢鈹€ init.sql 鈹溾攢鈹€ standard_oracle_contract # 绯荤粺鑷甫鐨勫悎绾︽枃浠跺強浠g爜 鈹� 鈹溾攢鈹€ oracle_contract_file 鈹� 鈹� 鈹斺攢鈹€ oracle_contract_v1 # 缂栬瘧杩囩殑棰勮█鏈哄悎绾﹀彲鎵ц鏂囦欢 鈹� 鈹溾攢鈹€ oracle_contract_src.zip # 棰勮█鏈哄悎绾︽簮浠g爜 鈹� 鈹斺攢鈹€ use_demo_src.zip # 鐢ㄦ埛浣跨敤棰勮█鏈哄悎绾︾殑绀轰緥婧愪唬鐮� 鈹� 鈹斺攢鈹€ use_demo.7z # 缂栬瘧鍘嬬缉鍚庣殑绀轰緥鏅鸿兘鍚堢害鏂囦欢 鈹斺攢鈹€ ut_cover.sh # 鍗曞厓娴嬭瘯鑴氭湰 ```