Skip to content

Commit

Permalink
feat: download contracts from repo
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega authored and mariocao committed Oct 19, 2023
1 parent 853622b commit 19e73ba
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 25 deletions.
77 changes: 59 additions & 18 deletions scripts/testnet/add_wasm_state_to_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,46 @@ set -euxo pipefail
# Then, it adds these states to a given original genesis file.
# The final genesis file is placed in the current directory as genesis.json.
#
source config.sh

#
# PRELIMINARY CHECKS
#
ORIGINAL_GENESIS=$NODE_DIR/genesis.json
if [ ! -f "$ORIGINAL_GENESIS" ]; then
echo "Original genesis file not found inside node directory."
exit 1
fi

TMP_HOME=./tmp
rm -rf $TMP_HOME

# download_contract_release() downloads a file from seda-chain-contracts repo.
# Argument:
# $1: Wasm contract file name
function download_contract_release() {
local repo="sedaprotocol/seda-chain-contracts"
local url="https://api.github.com"

mkdir -p $WASM_DIR

function gh_curl() {
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
$@
}

if [ "$CONTRACTS_VERSION" = "latest" ]; then
# Github should return the latest release first.
parser=".[0].assets | map(select(.name == \"${1}\"))[0].id"
else
parser=". | map(select(.tag_name == \"$CONTRACTS_VERSION\"))[0].assets | map(select(.name == \"${1}\"))[0].id"
fi;

asset_id=`gh_curl -s $url/repos/$repo/releases | jq "$parser"`
if [ "$asset_id" = "null" ]; then
>&2 echo "ERROR: asset not found: version $CONTRACTS_VERSION, file $1"
exit 1
fi;

curl -sL --header "Authorization: token $GITHUB_TOKEN" \
--header 'Accept: application/octet-stream' \
https://$GITHUB_TOKEN:@api.github.com/repos/$repo/releases/assets/$asset_id \
--output-dir $WASM_DIR --output ${1}
}

# store_and_instantiate() stores and instantiates a contract and returns its address
# Accept arguments:
# Arguments:
# $1: Contract file name
# $2: Initial state
store_and_instantiate() {
function store_and_instantiate() {
local TX_OUTPUT=$($BIN tx wasm store $WASM_DIR/$1 --from $ADDR --keyring-backend test --gas auto --gas-adjustment 1.2 --home $TMP_HOME -y --output json)
[[ -z "$TX_OUTPUT" ]] && { echo "failed to get tx output" ; exit 1; }
local TX_HASH=$(echo $TX_OUTPUT | jq -r .txhash)
Expand All @@ -46,15 +66,36 @@ store_and_instantiate() {
echo $CONTRACT_ADDRESS
}


source config.sh

#
# PRELIMINARY CHECKS AND DOWNLOADS
#
ORIGINAL_GENESIS=$NODE_DIR/genesis.json
if [ ! -f "$ORIGINAL_GENESIS" ]; then
echo "Original genesis file not found inside node directory."
exit 1
fi

TMP_HOME=./tmp
rm -rf $TMP_HOME

rm -rf $WASM_DIR
download_contract_release proxy_contract.wasm
download_contract_release staking.wasm
download_contract_release data_requests.wasm


#
# SCRIPT BEGINS - START CHAIN
#
$BIN init new node0 --home $TMP_HOME

$BIN keys add satoshi --home $TMP_HOME --keyring-backend test
ADDR=$($BIN keys show satoshi --home $TMP_HOME --keyring-backend test -a)
$BIN keys add deployer --home $TMP_HOME --keyring-backend test
ADDR=$($BIN keys show deployer --home $TMP_HOME --keyring-backend test -a)
$BIN add-genesis-account $ADDR 100000000000000000seda --home $TMP_HOME --keyring-backend test
$BIN gentx satoshi 10000000000000000seda --home $TMP_HOME --keyring-backend test
$BIN gentx deployer 10000000000000000seda --home $TMP_HOME --keyring-backend test
$BIN collect-gentxs --home $TMP_HOME


Expand Down
Binary file removed scripts/testnet/artifacts/data_requests.wasm
Binary file not shown.
Binary file removed scripts/testnet/artifacts/proxy_contract.wasm
Binary file not shown.
Binary file removed scripts/testnet/artifacts/staking.wasm
Binary file not shown.
21 changes: 18 additions & 3 deletions scripts/testnet/config_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ HOME_CONFIG_DIR=$HOME_DIR/config # chain config directory
BIN=$(git rev-parse --show-toplevel)/build/seda-chaind # chain binary executable on your machine
LINUX_BIN=$(git rev-parse --show-toplevel)/build/seda-chaind-linux # linux version of chain binary

# CHAIN_ID=seda-testnet
CHAIN_ID=seda-testnet
# GENESIS_TIME=


# Validators
#######################################
########### VALIDATOR NODES ###########
#######################################
# NOTE: Assumes 26656 port for p2p communication
# NOTE: Assumes user is ec2-user
# NOTE: The setup node script assumes ami-0a1ab4a3fcf997a9d
Expand All @@ -32,10 +34,23 @@ SELF_DELEGATION_AMOUNTS=(
SSH_KEY=~/.ssh/id_rsa # key used for ssh


# Genesis acoounts addresses
#######################################
########## GENESIS ACCOUNTS ###########
#######################################
# Standard genesis accounts
# NOTE: The script will create operators of the nodes defined above and
# add them as genesis accounts in addition to the ones defined below.
GENESIS_ADDRESSES=(
"seda..."
"seda..."
)

SATOSHI=seda... # if set, creates a genesis account with 100x seda tokens compared to standard genesis account
FAUCET=seda... # if set, creates a genesis account with 10x seda tokens compared to standard genesis account


#######################################
############### GITHUB ################
#######################################
GITHUB_TOKEN=ghp_... # github token for accessing seda-chain-contracts repo
CONTRACTS_VERSION=v0.0.1-rc # latest or seda-chain-contracts release version
16 changes: 12 additions & 4 deletions scripts/testnet/create_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rm -rf $NODE_DIR
#
# CREATE GENESIS AND ADJUST GOV PARAMETERS
#
$BIN init new node0
$BIN init new node0 --chain-id $CHAIN_ID

cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json
Expand All @@ -34,9 +34,17 @@ cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["max
# ADD GENESIS ACCOUNTS
#
for i in ${!GENESIS_ADDRESSES[@]}; do
$BIN add-genesis-account ${GENESIS_ADDRESSES[$i]} 100000000000000000seda --keyring-backend test
$BIN add-genesis-account ${GENESIS_ADDRESSES[$i]} 100000000000000000seda
done

set +u
if [ ! -z "$SATOSHI" ]; then
$BIN add-genesis-account $SATOSHI 10000000000000000000seda
fi
if [ ! -z "$FAUCET" ]; then
$BIN add-genesis-account $FAUCET 1000000000000000000seda
fi
set -u

#
# CREATE NODE KEY, VALIDATOR KEY, AND GENTX FOR EACH NODE
Expand All @@ -54,9 +62,9 @@ for i in ${!MONIKERS[@]}; do
VALIDATOR_ADDRESS=$($BIN keys show ${MONIKERS[$i]} --keyring-backend test --home $INDIVIDUAL_VAL_HOME_DIR -a)

# to create their gentx
$BIN add-genesis-account $VALIDATOR_ADDRESS 100000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR
$BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR
# to output geneis file
$BIN add-genesis-account $VALIDATOR_ADDRESS 100000000000000000seda
$BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda

$BIN gentx ${MONIKERS[$i]} ${SELF_DELEGATION_AMOUNTS[$i]} --moniker=${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR --ip=${IPS[$i]}

Expand Down

0 comments on commit 19e73ba

Please sign in to comment.