Skip to content

Commit

Permalink
Merge pull request #5 from RetricSu/hot-bump-version
Browse files Browse the repository at this point in the history
bump godwoken version and improve start command
  • Loading branch information
RetricSu authored Apr 28, 2021
2 parents 0cbe20f + 5d5f701 commit cbae542
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ start-godwoken:
cd docker && docker-compose start godwoken

test-con:
./testParseConfig.sh
./testParseConfig.sh
2 changes: 1 addition & 1 deletion godwoken
27 changes: 16 additions & 11 deletions godwoken_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
86 changes: 86 additions & 0 deletions gw_util.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit cbae542

Please sign in to comment.