Skip to content

Commit

Permalink
fix: update l1_sudt_dep in config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
RetricSu committed Jun 8, 2021
1 parent 4cfc048 commit 40b123f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 16 deletions.
16 changes: 13 additions & 3 deletions godwoken_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ yarn prepare-sudt

cd ${PROJECT_DIR}
# update l1_sudt_script_hash in config.toml file(if it exits) with lumos script.sudt.code_hash
codeHash=$(get_sudt_code_hash_from_lumos_file "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
codeHash=$(get_lumos_config_script_key_value SUDT CODE_HASH "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
set_key_value_in_toml "l1_sudt_script_type_hash" $codeHash "${PROJECT_DIR}/godwoken/config.toml"
# update l1_sudt_dep info in config.toml file(if it exits) with lumos script.sudt.dep
depType=$(get_lumos_config_script_key_value SUDT DEP_TYPE "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
txHash=$(get_lumos_config_script_key_value SUDT TX_HASH "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
outpointIndex=$(get_lumos_config_script_key_value SUDT INDEX "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
update_godwoken_config_toml_with_l1_sudt_dep "${PROJECT_DIR}/godwoken/config.toml" $depType $txHash $outpointIndex

# ready to start godwoken
cd ${PROJECT_DIR}/godwoken
Expand Down Expand Up @@ -98,7 +103,7 @@ echo 'this may takes a little bit of time, please wait...'
$GW_TOOLS_BIN deploy-scripts -r ${ckb_rpc} -i deploy/scripts-deploy.json -o deploy/scripts-deploy-result.json -k ${PRIVKEY}

# update l1_sudt_script_hash in rollup-config.json file(if it exits) with lumos script.sudt.code_hash
codeHash=$(get_sudt_code_hash_from_lumos_file "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
codeHash=$(get_lumos_config_script_key_value SUDT CODE_HASH "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
set_key_value_in_json "l1_sudt_script_type_hash" $codeHash "deploy/rollup-config.json"

# deploy genesis block
Expand All @@ -117,8 +122,13 @@ $GW_TOOLS_BIN generate-config -d ${DATABASE_URL} -r ${ckb_rpc} -g deploy/genesis
edit_godwoken_config_toml ${PROJECT_DIR}/godwoken/config.toml

# update l1_sudt_script_hash in config.toml file(if it exits) with lumos script.sudt.code_hash
codeHash=$(get_sudt_code_hash_from_lumos_file "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
codeHash=$(get_lumos_config_script_key_value SUDT CODE_HASH "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
set_key_value_in_toml "l1_sudt_script_type_hash" $codeHash "${PROJECT_DIR}/godwoken/config.toml"
# update l1_sudt_dep info in config.toml file(if it exits) with lumos script.sudt.dep
depType=$(get_lumos_config_script_key_value SUDT DEP_TYPE "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
txHash=$(get_lumos_config_script_key_value SUDT TX_HASH "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
outpointIndex=$(get_lumos_config_script_key_value SUDT INDEX "${PolyjuiceDir}/packages/runner/configs/lumos-config.json")
update_godwoken_config_toml_with_l1_sudt_dep "${PROJECT_DIR}/godwoken/config.toml" $depType $txHash $outpointIndex

# prepare runner config file for polyjuice
cp ${PROJECT_DIR}/godwoken/deploy/scripts-deploy-result.json ${PolyjuiceDir}/packages/runner/configs/scripts-deploy-result.json
Expand Down
70 changes: 64 additions & 6 deletions gw_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,29 @@ set_key_value_in_json() {
fi
}

get_sudt_code_hash_from_lumos_file() {
if [[ -n $1 ]];
# usage:
# get_lumos_config_script_key_value <scripts_name> <key_name> <lumos-config.json file path>
get_lumos_config_script_key_value(){
if [[ ! -n $1 ]];
then
echo 'provide your interested scripts(like SUDT/SECP256K1_BLAKE160)! abort.'
return 1
fi

if [[ ! -n $2 ]];
then
echo 'provide your interested key name(like CODE_HASH/TX_HASH)! abort.'
return 2
fi

if [[ -n $3 ]];
then
local lumosconfigfile="$1"
local lumosconfigfile="$3"
else
local lumosconfigfile="/code/godwoken-polyman/packages/runner/configs/lumos-config.json"
fi

echo "$(cat $lumosconfigfile)" | grep -Pzo 'SUDT[\s\S]*CODE_HASH": "\K[^"]*'
echo "$(cat $lumosconfigfile)" | grep -Pzo ''$1'[^}]*'$2'": "\K[^"]*'
}

generateSubmodulesEnvFile(){
Expand Down Expand Up @@ -349,7 +363,7 @@ copy_poa_scripts_from_docker_or_abort(){

edit_godwoken_config_toml(){
if [[ -f $1 ]];
then echo 'found json file.'
then echo 'found config.toml file.'
else
echo "${1} file not exits, skip this steps."
return 0
Expand All @@ -368,3 +382,47 @@ edit_godwoken_config_toml(){
sed -i "/\[block_producer.wallet_config.lock\]/a\hash_type = 'type'" $1
sed -i "/\[block_producer.wallet_config.lock\]/a\args = '0x43d509d97f26007a285f39241cffcd411157196c'" $1
}

# usage:
# update_godwoken_config_toml_with_l1_sudt_dep <config.toml file> <dep_type> <tx_hash> <index>
update_godwoken_config_toml_with_l1_sudt_dep(){
if [[ -f $1 ]];
then echo 'found config.toml file.'
else
echo "${1} file not exits, skip this steps."
return 0
fi

if [[ -n $2 ]];
then echo "dep_type: $2"
else
echo "dep_tpe not supported. abort."
return 1
fi

if [[ -n $3 ]];
then echo "tx_hash: $3"
else
echo "tx_hash not supported. abort."
return 2
fi

if [[ -n $4 ]];
then echo "tx_hash index: $4"
else
echo "tx_hash index not supported. abort."
return 3
fi

# delete the default l1_sudt_type_dep
sed -i '/\[block_producer.l1_sudt_type_dep\]/{n;d}' $1
# add an new one
sed -i "/\[block_producer.l1_sudt_type_dep\]/a\dep_type = '$2'" $1

# delete the default l1_sudt_type_dep.out_point
sed -i '/\[block_producer.l1_sudt_type_dep.out_point\]/{n;d}' $1
sed -i '/\[block_producer.l1_sudt_type_dep.out_point\]/{n;d}' $1
# add an new one
sed -i "/\[block_producer.l1_sudt_type_dep.out_point\]/a\index = '$4'" $1
sed -i "/\[block_producer.l1_sudt_type_dep.out_point\]/a\tx_hash = '$3'" $1
}
7 changes: 0 additions & 7 deletions scripts/test-get-sudt-script.sh

This file was deleted.

0 comments on commit 40b123f

Please sign in to comment.