From df783691a684268b4d0fdf8081bd7d6842fd5b4a Mon Sep 17 00:00:00 2001 From: RetricSu Date: Tue, 27 Apr 2021 15:40:19 +0200 Subject: [PATCH 1/2] bump godwoken version --- godwoken | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godwoken b/godwoken index b811a1b3..26d15dbe 160000 --- a/godwoken +++ b/godwoken @@ -1 +1 @@ -Subproject commit b811a1b39f92e0f6cd0471bf15604626c57d1867 +Subproject commit 26d15dbe42d15ad902593fcc89cf82b1ccc18d66 From 5d5f701675a9dfcab3db85e101f2b5c601c556d4 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Wed, 28 Apr 2021 04:38:59 +0200 Subject: [PATCH 2/2] bump godwoken version and add rollup-cell detect when start --- Makefile | 2 +- godwoken_entrypoint.sh | 27 +++++++------ gw_util.sh | 86 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 12 deletions(-) create mode 100755 gw_util.sh diff --git a/Makefile b/Makefile index b021a2a5..7e97632a 100644 --- a/Makefile +++ b/Makefile @@ -136,4 +136,4 @@ start-godwoken: cd docker && docker-compose start godwoken test-con: - ./testParseConfig.sh \ No newline at end of file + ./testParseConfig.sh diff --git a/godwoken_entrypoint.sh b/godwoken_entrypoint.sh index 7ce0be72..1238830b 100644 --- a/godwoken_entrypoint.sh +++ b/godwoken_entrypoint.sh @@ -11,6 +11,13 @@ export PRIVKEY=deploy/private_key export ckb_rpc=http://ckb:8114 export RUST_BACKTRACE=1 +# import some helper function +source ${PROJECT_DIR}/gw_util.sh + +# start ckb-indexer +# todo: should remove to another service. but the port mapping some how not working. +${PROJECT_DIR}/indexer-data/ckb-indexer -s ${PROJECT_DIR}/indexer-data/ckb-indexer-data -c ${ckb_rpc} > ${PROJECT_DIR}/indexer-data/indexer-log & + # detect which mode to start godwoken GODWOKEN_CONFIG_FILE=${PROJECT_DIR}/godwoken/config.toml @@ -20,9 +27,15 @@ if test -f "$GODWOKEN_CONFIG_FILE"; then # fat start, re-deploy godwoken chain export START_MODE="fat_start" else - echo "godwoken config.toml exists. use slim mode." - # slim start, just start godwoken, no re-depoly scripts - export START_MODE="slim_start" + echo "godwoken config.toml exists. try search rollup cell.." + if isRollupCellExits "${GODWOKEN_CONFIG_FILE}"; + then + # slim start, just start godwoken, no re-depoly scripts + export START_MODE="slim_start" + else + # fat start, re-deploy godwoken chain + export START_MODE="fat_start" + fi fi else export START_MODE="fat_start" @@ -31,9 +44,6 @@ fi if [ $START_MODE = "slim_start" ]; then cd ${PROJECT_DIR}/godwoken - # start ckb-indexer - # todo: should remove to another service. but the port mapping some how not working. - ${PROJECT_DIR}/indexer-data/ckb-indexer -s ${PROJECT_DIR}/indexer-data/ckb-indexer-data -c ${ckb_rpc} > ${PROJECT_DIR}/indexer-data/indexer-log & #cargo run --bin godwoken RUST_LOG=debug ./target/debug/godwoken else @@ -96,11 +106,6 @@ cp ${PROJECT_DIR}/godwoken/config.toml ${PROJECT_DIR}/godwoken-examples/packages # generate godwoken config file for polyjuice cd ${PROJECT_DIR}/godwoken-examples && yarn gen-config && cd ${PROJECT_DIR}/godwoken - -# start ckb-indexer -# todo: should remove to another service. but the port mapping some how not working. -${PROJECT_DIR}/indexer-data/ckb-indexer -s ${PROJECT_DIR}/indexer-data/ckb-indexer-data -c ${ckb_rpc} > ${PROJECT_DIR}/indexer-data/indexer-log & - # start godwoken RUST_LOG=debug ./target/debug/godwoken #cargo run --bin godwoken \ No newline at end of file diff --git a/gw_util.sh b/gw_util.sh new file mode 100755 index 00000000..17d1c047 --- /dev/null +++ b/gw_util.sh @@ -0,0 +1,86 @@ +#!/bin/bash + + +# how to use: +# parese_toml_with_section file_path section_name key_name +parse_toml_with_section(){ + [[ -f $1 ]] || { echo "$1 is not a file." >&2;return 1;} + local -n config_array=config + [[ -n $2 ]] || { echo "pleas pass your interested section name as second variable!";} + if [[ -n $3 ]]; then + key_name="$3" + else + echo "pleas pass your interested key name as third variable!"; + fi + declare -Ag ${!config_array} || return 1 + local line key value section_regex entry_regex interested_section_array + section_regex="^[[:blank:]]*\[([[:alpha:]_][[:alnum:]/._-]*)\][[:blank:]]*(#.*)?$" + entry_regex="^[[:blank:]]*([[:alpha:]_][[:alnum:]_]*)[[:blank:]]*=[[:blank:]]*('[^']+'|\"[^\"]+\"|[^#[:blank:]]+)[[:blank:]]*(#.*)*$" + while read -r line + do + [[ -n $line ]] || continue + [[ $line =~ $section_regex ]] && { + local -n config_array=${BASH_REMATCH[1]//\./\_} # if section name contains ".", replace it with "_" for naming. + if [[ ${BASH_REMATCH[1]} =~ $2 ]]; then + interested_section_array="$BASH_REMATCH" + else + continue + fi + declare -Ag ${!config_array} || return 1 + continue + } + [[ $line =~ $entry_regex ]] || continue + key=${BASH_REMATCH[1]} + value=${BASH_REMATCH[2]#[\'\"]} # strip quotes + value=${value%[\'\"]} + config_array["${key}"]="${value}" + done < "$1" + declare -n array="${interested_section_array//\./\_}" + echo ${array[$key_name]} +} + +isRollupCellExits(){ + echo $1 + if [[ -n $1 ]]; + then + local tomlconfigfile="$1" + else + local tomlconfigfile="/code/godwoken/config.toml" + fi + + rollup_code_hash=$( parse_toml_with_section "$tomlconfigfile" "chain.rollup_type_script" "code_hash" ) + rollup_hash_type=$( parse_toml_with_section "$tomlconfigfile" "chain.rollup_type_script" "hash_type" ) + rollup_args=$( parse_toml_with_section "$tomlconfigfile" "chain.rollup_type_script" "args" ) + + result=$( echo '{ + "id": 2, + "jsonrpc": "2.0", + "method": "get_cells", + "params": [ + { + "script": { + "code_hash": "'${rollup_code_hash}'", + "hash_type": "'${rollup_hash_type}'", + "args": "'${rollup_args}'" + }, + "script_type": "type" + }, + "asc", + "0x64" + ] + }' \ + | tr -d '\n' \ + | curl -H 'content-type: application/json' -d @- \ + http://localhost:8116 ) + + if [[ $result =~ "block_number" ]]; then + echo "Rollup cell exits!" + # 0 equals true + return 0 + else + echo "can not found Rollup cell!" + # 1 equals false + return 1 + fi +} +