diff --git a/script/README.md b/script/README.md deleted file mode 100644 index 12f6fd8..0000000 --- a/script/README.md +++ /dev/null @@ -1,95 +0,0 @@ -Consider using these scripts for a deterministic development setup using a localnet. - -## Not sure where to start? -Try this: - 1. Clone this repo - 2. Run 'init-localnet' located in 'dtp/script'. It will download and initialize everything. - 3. Verify the localnet is running and is as expected (see 'Initial State' below). - 4. Develop your app. Localnet will be at http://0.0.0.0:9000 - 5. Run 'init-localnet' anytime to reset the localnet to its initial state. - -## Features - - Keeps localnet/devnet/testnet keystores seperated. - - Does not touch the user level ~/.sui and its keystore (assumes might be used later for mainnet). - - Repeatable localnet that can be reset quickly with the same pre-funded address. - - Customizeable pre-funding amount ( See script/genesis/config.yaml ) - - Convenient Sui CLI frontends for each network ("dsui" for devnet, "tsui" for testnet...) - -## Verify the Sui localnet is running on your machine -Do the following -``` -$ pgrep sui -1773 -``` -This is the PID. If a number is shown, the sui process is running, meaning the localnet is running. - -## Initial State -Always same 5 client addresses. The 0xc7148~89a7 is the default active client and will be funded with 5 object coins. - -``` -$ lsui client addresses -Showing 5 results. -0x4e8b8c06d7aed3c11195794fa7b0469855c57b30 -0x5f11df8d90fef7a642d561aed0f2ee64de5c373c -0x8638a4d6438b399a77659463a25fdf2bdf0b229b -0x86f066b23d7e60ec4dbb280a4c265772c186693b -0xc7148f0c0086adf172eb4c2076c7d888337789a7 - -$ lsui client active-address -0xc7148f0c0086adf172eb4c2076c7d888337789a7 - -$ lsui client gas - Object ID | Gas Value ----------------------------------------------------------------------- - 0x0b162ef4f83118cc0ad811de35ed330ec3441d7b | 800000000000000 - 0x2d43245a6af1f65847f7c18d5f6aabbd8e11299b | 800000000000000 - 0x9811c29f1dadb67aadcd59c75693b4a91b347fbb | 800000000000000 - 0xc8381677d3c213f9b0e9ef3d2d14051458b6af8a | 800000000000000 - 0xd0b2b2227244707bce233d13bf537af7a6710c01 | 800000000000000 -``` -(Default 40 Sui per client, you can customize to as much as you need) - -## Development Setup - ``` - - │ - ├── dtp/ # The git cloned dtp - | ├── ... - │ └── script/ - │ ├── init-localnet # Create or update dtp-dev/sui-devnet-branch and dtp-dev/user-localnet - | ├── init-devnet # Create or update dtp-dev/sui-devnet-branch and dtp-dev/user-devnet - | ├── init-testnet # Create or update dtp-dev/sui-tesnet-branch and dtp-dev/user-testnet - │ ├── lsui # Sui CLI frontend for localnet - │ ├── dsui # Sui CLI frontend for live devnet - │ └── tsui # Sui CLI frontend for live testnet - │ - └── dtp-dev/ # Created by the scripts - ├── sui-devnet-branch # Complete local repo of Sui devnet branch. - ├── sui-testnet-branch # Complete local repo of Sui testnet branch. - ├── user-localnet # All localnet files, devnet branch runs at http://0.0.0.0:9000 - ├── user-devnet # Keystore for live devnet network - └── user-testnet # Keystore for live tesnet network -``` - -init-localnet fetch&build latest devnet from the Sui repo, create the localnet from scratch and (re)start the sui daemon. - -The first init-localnet execution will be long (many minutes to compile everything), but subsequent calls are fast (~10 seconds). - -It is intentional that localnet and devnet are using the same repo. Consider also to make your Cargo.toml of your app refer to the same local repo (instead of remote git), avoiding this way any out-of-sync binaries. - -# Example localnet call with sui-sdk (Rust) -``` -use std::str::FromStr; -use sui_sdk::types::base_types::SuiAddress; -use sui_sdk::SuiClient; - -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - // Test localnet with the pre-funded wallet. - let sui = SuiClient::new("http://0.0.0.0:9000", None, None).await?; - let address = SuiAddress::from_str("0xcfed50a652b8fce7a7917a8a736a7c2b1d646ba2")?; - let objects = sui.read_api().get_objects_owned_by_address(address).await?; - println!("{:?}", objects); - Ok(()) -} - diff --git a/script/dsui b/script/dsui deleted file mode 100755 index 7ecc12f..0000000 --- a/script/dsui +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Equivalent to sui, but for targeting remote devnet network only. - -NETNAME="devnet" -SUI_REPO_BRANCH="devnet" -SUI_SCRIPT="dsui" - -# Just find the absolute path of the "dtp-dev" where most -# dependencies will be downloaded and build/runtime files -# will be located. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -check_dev_setup - -# Use the proper config automatically. -SUI_SUBCOMMAND=$1 -if [[ "$1" = "client" || "$1" == "console" ]]; then - shift 1 - "$SUI_BIN_DIR"/sui $SUI_SUBCOMMAND --client.config "$CLIENT_CONFIG" "$@" - exit -fi - -if [[ "$1" == "network" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - "$SUI_BIN_DIR"/sui network --help - fi - echo - echo "network command not supported by dsui for remote devnet. Try with sui directly if you think it should work!?" - exit -fi - -if [[ "$1" == "genesis" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - "$SUI_BIN_DIR"/sui genesis --help - fi - echo - echo "genesis command not supported by dsui for remote devnet. Try with sui directly if you think it should work!?" -fi - -if [[ "$1" == "start" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - "$SUI_BIN_DIR"/sui start --help - fi - echo - echo - echo "start command not supported by dsui for remote devnet. Try with sui directly if you think it should work!?" -fi - -if [[ "$1" == "keytool" ]]; then - shift 1 - "$SUI_BIN_DIR"/sui $SUI_SUBCOMMAND --keystore-path "$KEYSTORE_FILE" "$@" - exit -fi - -# Default -"$SUI_BIN_DIR"/sui "$@" diff --git a/script/genesis_data/client.yaml b/script/genesis_data/client.yaml deleted file mode 100644 index 9310abb..0000000 --- a/script/genesis_data/client.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -keystore: - # ** Important ** - # - # If you are manuualy copying this file into your environment, then - # the path below must match your /sui.keystore location. - # - # If instead your are using the dtp/script/init-localnet, then do not - # modify this file. The script takes care to initialize the correct path. - File: /sui.keystore -envs: - - alias: localnet - rpc: "http://0.0.0.0:9000" - ws: ~ - - alias: devnet - rpc: "https://fullnode.devnet.sui.io:443" - ws: ~ -active_env: localnet -active_address: "0xc7148f0c0086adf172eb4c2076c7d888337789a7" diff --git a/script/genesis_data/config.yaml b/script/genesis_data/config.yaml deleted file mode 100644 index 9b42034..0000000 --- a/script/genesis_data/config.yaml +++ /dev/null @@ -1,76 +0,0 @@ ---- -validator_config_info: ~ -parameters: - timestamp_ms: 1675147035226 - chain_id: 127 -committee_size: 4 -grpc_load_shed: ~ -grpc_concurrency_limit: 20000000000 -accounts: - - address: 4e8b8c06d7aed3c11195794fa7b0469855c57b30 - gas_objects: - - object_id: "0xd79b45b89580f92986a9d92b57feb96e6766fbab" - gas_value: 800000000000000 - - object_id: "0x39ffad414102df11eea6bfe047894126ffedd754" - gas_value: 800000000000000 - - object_id: "0x0ba8f669967e5807433769a9632c5f2795947d6c" - gas_value: 800000000000000 - - object_id: "0x6d7f96220c30df2b74629fe07c8b3c8a162b9956" - gas_value: 800000000000000 - - object_id: "0x3a713341f43998b53c20de40d9e67116049b37a6" - gas_value: 800000000000000 - gas_object_ranges: [] - - address: 5f11df8d90fef7a642d561aed0f2ee64de5c373c - gas_objects: - - object_id: "0x9463a9d0f5caee14ec695af6552339ab76f62fc5" - gas_value: 800000000000000 - - object_id: "0x7b28a53e5e8e0d8e96e68d8a0838294832bc3713" - gas_value: 800000000000000 - - object_id: "0x8334225c1190281d701031a294d22ce07fe2f14a" - gas_value: 800000000000000 - - object_id: "0xf1954d90762928620573f53b44e82e26917837b0" - gas_value: 800000000000000 - - object_id: "0x7edba2f308678b0c606fcc6cd1546928ddb3dda1" - gas_value: 800000000000000 - gas_object_ranges: [] - - address: 8638a4d6438b399a77659463a25fdf2bdf0b229b - gas_objects: - - object_id: "0xc7c2cc2d8a52ab722d3fff5f023d92d3e6c83bf7" - gas_value: 800000000000000 - - object_id: "0x4bd3590f5a629a3520b210d4b140bbfe49513d25" - gas_value: 800000000000000 - - object_id: "0x240db2b7f923a6a36fec832a4142f321b8677244" - gas_value: 800000000000000 - - object_id: "0xdbe78a2d22d94db20fea77819ad1d3e854b7517e" - gas_value: 800000000000000 - - object_id: "0x5138c6830ea4aa8cb765e0c43fd6b21ebb815abf" - gas_value: 800000000000000 - gas_object_ranges: [] - - address: 86f066b23d7e60ec4dbb280a4c265772c186693b - gas_objects: - - object_id: "0xd0fb870ac78a2388ceab2b6ce09429c049058804" - gas_value: 800000000000000 - - object_id: "0x080a23489f65d893f602cc8d4165b2062525a49d" - gas_value: 800000000000000 - - object_id: "0x9d9d566b916e8cbceea88a869185234aa99ec240" - gas_value: 800000000000000 - - object_id: "0x46f2fff7b4523b57c1582f7a221fd419c425da49" - gas_value: 800000000000000 - - object_id: "0x750e819834b39ae10198ca4a6a586ebe0392e5a3" - gas_value: 800000000000000 - gas_object_ranges: [] - - address: c7148f0c0086adf172eb4c2076c7d888337789a7 - gas_objects: - - object_id: "0x2d43245a6af1f65847f7c18d5f6aabbd8e11299b" - gas_value: 800000000000000 - - object_id: "0xc8381677d3c213f9b0e9ef3d2d14051458b6af8a" - gas_value: 800000000000000 - - object_id: "0xd0b2b2227244707bce233d13bf537af7a6710c01" - gas_value: 800000000000000 - - object_id: "0x0b162ef4f83118cc0ad811de35ed330ec3441d7b" - gas_value: 800000000000000 - - object_id: "0x9811c29f1dadb67aadcd59c75693b4a91b347fbb" - gas_value: 800000000000000 - - object_id: "0x0000000000000000000000000000000000000fa7" - gas_value: 0xFFFFFFFFFFFFFFFF - gas_object_ranges: [] diff --git a/script/genesis_data/sui.keystore b/script/genesis_data/sui.keystore deleted file mode 100644 index b472df5..0000000 --- a/script/genesis_data/sui.keystore +++ /dev/null @@ -1,7 +0,0 @@ -[ - "AFN+bYPrQaSnOtC0Jbo6C+EZQ8INYpcOfGvYEBLOv4La", - "AHMEXsGDQDUrGA0Q9pyBbwZn7ZdwRQJ1N66AY8BuWcuA", - "AOaWqbhk0ot+0mvHlmPixkNH1NbX+qc9QNGKHe5QD8hL", - "AGc10rcDgxkE1USHaLoDrwvoObCRhMvl1agEb6a5ShVY", - "AE6Ug8sqXgD7osbbb3SwrE7ELWbA825f47Le7BdeTB07" -] \ No newline at end of file diff --git a/script/genesis_data/wallet_address.txt b/script/genesis_data/wallet_address.txt deleted file mode 100644 index 41f45f3..0000000 --- a/script/genesis_data/wallet_address.txt +++ /dev/null @@ -1 +0,0 @@ -0xc7148f0c0086adf172eb4c2076c7d888337789a7 diff --git a/script/init-devnet b/script/init-devnet deleted file mode 100755 index ecc5366..0000000 --- a/script/init-devnet +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# If not already done: -# - Get devnet binaries and build it under dtp-dev/sui-devnet -# - Initialize the user keystore under dtp-dev/devnet -# -NETNAME="devnet" -SUI_REPO_BRANCH="devnet" -SUI_SCRIPT="dsui" - -# Call the initialization code common to all script. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -common_init_dev_setup - -build_sui_repo_branch - -echo Remember: -echo " Use \"$SUI_SCRIPT\" to access $NETNAME" -echo -echo Try it by typing \"$SUI_SCRIPT client gas\" diff --git a/script/init-localnet b/script/init-localnet deleted file mode 100755 index a1bb202..0000000 --- a/script/init-localnet +++ /dev/null @@ -1,209 +0,0 @@ -#!/bin/bash - -# Initialize and start a Sui local network. -# -# Warning: -# If there is an existing sui local network, it will be deleted -# and replaced with a fresh installation. All modules, objects and -# transaction done since genesis will be purged. -# -# This script will also overwrite any changes under -# dtp-dev/sui. This sui local repo should not be used -# to modify sui itself (other than for may be throw away -# debug code). -# -# For future reference, this is how the config.yaml was generated: -# sui genesis --write-config "$GENESIS_DATA_DIR/config.yaml" - -NETNAME="localnet" -SUI_REPO_BRANCH="devnet" -SUI_SCRIPT="lsui" - -# Param -DEBUG_RUN=false -GENESIS=false -while [[ "$#" -gt 0 ]]; do - case $1 in - # -t|--target) target="$2"; shift ;; That's an example with a parameter - # -f|--flag) flag=1 ;; That's an example flag - -g|--genesis) GENESIS=true ;; - -d|--debug) DEBUG_RUN=true ;; - *) echo "Unknown parameter passed: $1"; exit 1 ;; - esac - shift -done - -if [ "$GENESIS" = true ]; then - echo "Genesis flag set. Will regenerate the default client addresses and coin objects for localnet." -fi - -if [ "$DEBUG_RUN" = true ]; then - echo "Debug flag set. Will run Localnet in foreground Ctrl-C to Exit" -fi - -# Call the initialization code common to all script. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -common_init_dev_setup - -# The script should not be called from a location that will get deleted. -# It would work (on Linux), but it is just to avoid user confusion later. -CWD=$(pwd -P) -if [[ "$CWD" = "$NETWORK_DATA_DIR"* ]]; then - echo "This script can't be called from a location to be deleted [$NETWORK_DATA_DIR]." - setup_error "Change current directory location and try again." -fi -CWD=$(pwd -P) -if [[ "$CWD" = "$PUBLISH_DATA_DIR"* ]]; then - echo "This script can't be called from a location to be deleted [$PUBLISH_DATA_DIR]." - setup_error "Change current directory location and try again." -fi - -# Stop already executing sui (if any) -# Get ps with "sui start", grep exclude itself from the list, head takes the first process (should not be more than one) -# the 1st sed remove leading space, the 2nd sed split words into line and finally the pid is the word on the first/head line. -OLD_SUI_PID=$(ps x | grep "sui start" | grep -v grep | head -n 1 | sed -e 's/^[[:space:]]*//' | sed 's/ /\n/g' | head -n 1) - -if [ ! -z "$OLD_SUI_PID" ] -then - echo "Stopping running $NETNAME (sui process pid $OLD_SUI_PID)" - skill -9 $OLD_SUI_PID - # Make sure it is dead. - end=$((SECONDS+15)) - DEAD=false - AT_LEAST_ONE_SECOND=false - while [ $SECONDS -lt $end ]; do - OLD_SUI_PID=$(ps x | grep "sui start" | grep -v grep | head -n 1 | sed -e 's/^[[:space:]]*//' | sed 's/ /\n/g' | head -n 1) - if [ -z "$OLD_SUI_PID" ]; then - break - else - echo -n "." - sleep 1 - AT_LEAST_ONE_SECOND=true - fi - done - - # Just UI aesthetic newline for when there was "." printed. - if [ "$AT_LEAST_ONE_SECOND" = true ]; then - echo - fi - - if [ ! -z "$OLD_SUI_PID" ]; then - setup_error "Sui process pid=$OLD_SUI_PID still running. You must stop (kill) the sui process before starting a new localnet" - fi -fi - -build_sui_repo_branch - -# Clean-up previous localnet (if exists) -RM_DIR="$NETWORK_DATA_DIR" -if [ -d "$RM_DIR" ] -then - echo "Removing existing $RM_DIR directory" - rm -rf "$RM_DIR" -fi - -# Delete localnet publish directory (if exists) to force re-publication. -RM_DIR="$PUBLISH_DATA_DIR" -if [ -d "$RM_DIR" ] -then - echo "Removing existing $RM_DIR directory" - rm -rf "$RM_DIR" -fi - -if [ "$GENESIS" = true ]; then - echo "Generating NEW genesis configuration file only" - $SUI_BIN_DIR/sui genesis --working-dir "$GENESIS_DATA_DIR" --write-config "$GENESIS_DATA_DIR/config.yaml.new" - diff "$GENESIS_DATA_DIR/config.yaml.new" "$GENESIS_DATA_DIR/config.yaml" - exit -fi - -echo "Creating new $NETNAME directory" -mkdir -p "$NETWORK_DATA_DIR" -if [ "$DEBUG_RUN" = true ]; then - $SUI_BIN_DIR/sui genesis --from-config "$GENESIS_DATA_DIR/config.yaml" --working-dir "$NETWORK_DATA_DIR" -else - $SUI_BIN_DIR/sui genesis --from-config "$GENESIS_DATA_DIR/config.yaml" --working-dir "$NETWORK_DATA_DIR" >& /dev/null -fi - -yes | cp -rf "$GENESIS_DATA_DIR/sui.keystore" "$NETWORK_DATA_DIR" -yes | cp -rf "$GENESIS_DATA_DIR/client.yaml" "$NETWORK_DATA_DIR" - -# Replace placeholder string in client.yaml with an absolute path to the keystore. -# Notice sed uses '+'' for seperator instead of '/' to avoid clash -# with directory path. Also uses a .bak temp file because Mac (BSD) does not -# allow in-place file change. -SEARCH_STRING="" -REPLACE_STRING="$NETWORK_DATA_DIR" -sed -i.bak -e "s+$SEARCH_STRING+$REPLACE_STRING+g" "$NETWORK_DATA_DIR/client.yaml" && rm "$NETWORK_DATA_DIR/client.yaml.bak" - - -# When need to start in foreground to debug. -if [ "$DEBUG_RUN" = true ]; then - echo "Starting new localnet process (foreground for debug)" - $SUI_BIN_DIR/sui start --network.config "$NETWORK_CONFIG" - exit -fi - -# Start the new localnet. -echo "Starting new localnet process (may take up to 30 secs)" -$SUI_BIN_DIR/sui start --network.config "$NETWORK_CONFIG" >& "$DEV_DIR/localnet.log" & -NEW_SUI_PID=$! - -# Loop until "sui client" confirms to be working, or exit if that takes -# more than 30 seconds. -end=$((SECONDS+30)) -ALIVE=false -AT_LEAST_ONE_SECOND=false -while [ $SECONDS -lt $end ]; do - CHECK_ALIVE=$($SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" objects | grep -i Digest) - if [ ! -z "$CHECK_ALIVE" ]; then - ALIVE=true - break - else - echo -n "." - sleep 1 - AT_LEAST_ONE_SECOND=true - fi -done - -# Just UI aesthetic newline for when there was "." printed. -if [ "$AT_LEAST_ONE_SECOND" = true ]; then - echo -fi - -# Act on success/failure of the sui process responding to "sui client". -if [ "$ALIVE" = false ]; then - echo "Sui process not responding. Try again? (may be the host is too slow?)." - exit; -fi - -echo "New localnet started ($SUI_VERSION, process pid $NEW_SUI_PID)" - -# Make sure localnet exists in sui envs (ignore errors because likely already exists) -echo ======== -$SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" new-env --alias localnet --rpc http://0.0.0.0:9000 >& /dev/null - -# Make localnet the active envs (should already be done, just in case, do it again here). -$SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" switch --env localnet > /dev/null - -# print sui envs to help debugging (if someone else is using this script). -$SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" envs -echo ======== -echo All addresses with coins: -$SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" addresses -echo ======== - -WALLET_ADDR=$($SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" active-address) -echo "All coins owned by $WALLET_ADDR (active):" -$SUI_BIN_DIR/sui client --client.config "$CLIENT_CONFIG" gas -echo ======== -echo -echo Remember: -echo " Use \"dsui\" to access devnet" -echo " Use \"lsui\" to access your localnet" -echo -echo Success. Try it by typing \"lsui client gas\" diff --git a/script/init-testnet b/script/init-testnet deleted file mode 100755 index c262a95..0000000 --- a/script/init-testnet +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# If not already done: -# - Get testnet binaries and build it under dtp-dev/sui-tesnet-branch -# - Initialize the user keystore under dtp-dev/user-testnet -# - -NETNAME="testnet" -SUI_REPO_BRANCH="testnet" -SUI_SCRIPT="tsui" - -# Call the initialization code common to all script. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -common_init_dev_setup - -build_sui_repo_branch - -echo Remember: -echo " Use \"$SUI_SCRIPT\" to access $NETNAME" -echo -echo Try it by typing \"$SUI_SCRIPT client gas\" \ No newline at end of file diff --git a/script/lsui b/script/lsui deleted file mode 100755 index 7ed06a3..0000000 --- a/script/lsui +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Equivalent to sui, but target the localnet and its proper config files (network.yaml and client.yaml) - -NETNAME="localnet" -SUI_REPO_BRANCH="devnet" -SUI_SCRIPT="lsui" - -# Just find the absolute path of the "dtp-dev" where most -# dependencies will be downloaded and build/runtime files -# will be located. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -check_dev_setup - -# Use the proper config automatically. -SUI_SUBCOMMAND=$1 -if [[ "$1" = "client" || "$1" == "console" ]]; then - shift 1 - $SUI_BIN_DIR/sui $SUI_SUBCOMMAND --client.config "$CLIENT_CONFIG" "$@" - exit -fi - -if [[ "$1" == "network" ]]; then - shift 1 - $SUI_BIN_DIR/sui $SUI_SUBCOMMAND --network.config "$NETWORK_CONFIG" "$@" - exit -fi - -if [[ "$1" == "genesis" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - $SUI_BIN_DIR/sui genesis --help - fi - echo - setup_error "Error: Use dtp/script/init-localnet instead for re-initializing localnet" -fi - -if [[ "$1" == "start" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - $SUI_BIN_DIR/sui start --help - fi - echo - # TODO Consider implementing a start-localnet script instead. - setup_error "Error: Use dtp/script/init-localnet instead for re-initializing localnet" -fi - -if [[ "$1" == "keytool" ]]; then - shift 1 - $SUI_BIN_DIR/sui $SUI_SUBCOMMAND --keystore-path "$KEYSTORE_FILE" "$@" - exit -fi - -# Default -$SUI_BIN_DIR/sui "$@" diff --git a/script/publish-localnet b/script/publish-localnet deleted file mode 100755 index ea694e1..0000000 --- a/script/publish-localnet +++ /dev/null @@ -1,142 +0,0 @@ -#!/bin/bash - -# Publish on the localnet the DTP Move package found under dtp/move -# -# Do nothing if no change to source code since last publication. -# -# On success, the file dtp/move/localnet/package_id.txt and client_addresses.txt -# will be created. The content are addresses in hexadecimal, starting with 0x. -# -# On failures, more info can be found in dtp/move/localnet/publish_output.txt - -NETNAME="localnet" -SUI_REPO_BRANCH="devnet" -SUI_SCRIPT="lsui" - -# Just find the absolute path of the "dtp-dev" where most -# dependencies will be downloaded and build/runtime files -# will be located. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -check_dev_setup - -# Remove some output from previous runs to minimize confusion. -rm -rf "$SCRIPT_OUTPUT" - -# Following files created only on confirmed success of publication. -rm -rf "$PUBLISH_DATA_DIR/package_id.txt" -rm -rf "$PUBLISH_DATA_DIR/client_addresses.txt" - -# Create dtp-dev/publish_data if does not exists. -mkdir -p "$PUBLISH_DATA_DIR" - -echo "Output location = $PUBLISH_DATA_DIR" - -# Sanity test that the sui binary works -if [ ! -f "$SUI_BIN_DIR/sui" ]; then - setup_error "$SUI_BIN_DIR/sui binary not found. Please run 'dtp/script/init-localnet'" -fi - -SUI_VERSION=$($SUI_BIN_DIR/sui --version) -if [ -z "$SUI_VERSION" ]; then - setup_error "$SUI_BIN_DIR/sui --version not running properly. Please run 'dtp/script/init-localnet'" -fi - -# Check that lsui is properly installed. -LSUI_VERSION=$(lsui --version) -if [ -z "$LSUI_VERSION" ]; then - setup_error "lsui not installed properly. Please run 'dtp/script/init-localnet'" -fi - -if [ "$SUI_VERSION" != "$LSUI_VERSION" ]; then - setup_error "lsui and sui somehow not same binary. Please run 'dtp/script/init-localnet'" -fi - -# Check if lsui is recent enough. -version_greater_equal "$LSUI_VERSION" "$MIN_SUI_VERSION" || setup_error "Sui binary version too old (not supported)" - -# Loop until "lsui client" confirms to be working, or exit if that takes -# more than 30 seconds. -end=$((SECONDS+30)) -ALIVE=false -AT_LEAST_ONE_SECOND=false -while [ $SECONDS -lt $end ]; do - CHECK_ALIVE=$(lsui client objects | grep -i Digest) - if [ ! -z "$CHECK_ALIVE" ]; then - ALIVE=true - break - else - echo -n "." - sleep 1 - AT_LEAST_ONE_SECOND=true - fi -done - -# Just UI aesthetic newline for when there was "." printed. -if [ "$AT_LEAST_ONE_SECOND" = true ]; then - echo -fi - -# Act on success/failure of the sui process responding to "sui client". -if [ "$ALIVE" = false ]; then - echo "Sui process not responding. Please run 'dtp/script/init-localnet'" - exit; -fi - -echo "$SUI_VERSION localnet running" - -# Make sure localnet exists in sui envs (ignore errors because likely already exists) -lsui client new-env --alias localnet --rpc http://0.0.0.0:9000 >& /dev/null - -# Make sure localnet is the active envs. -lsui client switch --env localnet > /dev/null || setup_error "Could not switch to localnet" - -# Run all unit tests. -script_cmd "lsui move test --install-dir \"$PUBLISH_DATA_DIR\" -p \"$MOVE_SRC_DIR\"" - -# Build the Move package for publication. -echo Publishing... -script_cmd "lsui client publish --gas-budget 30000 --install-dir \"$PUBLISH_DATA_DIR\" \"$MOVE_SRC_DIR\"" - -# Grab the first line with an immutable "ID" after the "Created Objects" string. -id_line=$(cat "$SCRIPT_OUTPUT" | sed '1,/Created Objects/d' | grep 'ID' | grep 'Immutable') - -if [ -z "$id_line" ]; then - setup_error "Could not find the package id from $SCRIPT_OUTPUT" -fi - -ID="" -for i in $id_line -do - if beginswith 0x $i; then - ID=$i - break; - fi -done - -if [ -z "$ID" ]; then - setup_error "Could not find Package id in $SCRIPT_OUTPUT" -fi - -# TODO Validate the package ID is all hexadecimal - -# Test the publication by retreiving object information from the network -# using that parsed package id. -script_cmd "lsui client object $ID" -validation=$(lsui client object $ID | grep "Move Package") -if [ -z "$validation" ]; then - setup_error "Unexpected object type (Not a Move Package)" -fi - -# Write in client_addresses.txt the addresses created by config.yaml on genesis. -# sed remove all the spaces and replace "address:" with "0x" -$(cat "$GENESIS_DATA_DIR/config.yaml" | grep address | sed 's/ //g' | sed 's/\(^.*address:\)/0x/g' > "$PUBLISH_DATA_DIR/client_addresses.txt") - -# Create the package_id.txt file to confirm to caller successful publication. -echo "$ID" > "$PUBLISH_DATA_DIR/package_id.txt" -echo -echo PackageID is [$ID] -echo Publication Successful diff --git a/script/publish-testnet b/script/publish-testnet deleted file mode 100755 index 6ca5c46..0000000 --- a/script/publish-testnet +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash - -# Publish on the remote testnet the DTP Move package found under ~/dtp/move -# -# Do nothing if no change to source code since last publication. -# -# On success, the file ~/dtp-dev/publish_data/testnet/package_id.txt and client_addresses.txt -# will be created. The content are addresses in hexadecimal, starting with 0x. -# -# On failures, more info can be found in ~/dtp-dev/publish_data/testnet/publish_output.txt - -NETNAME="testnet" -SUI_REPO_BRANCH="devnet" -SUI_SCRIPT="tsui" - -# Call the initialization code common to all script. -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -source "$SCRIPT_DIR/script_common" "$SCRIPT_DIR" "$SCRIPT_NAME" "$NETNAME" "$SUI_REPO_BRANCH" - -# Following files created only on confirmed success of publication. -# Remove output from potential previous runs to minimize confusion. -rm -rf "$SCRIPT_OUTPUT" -rm -rf "$PACKAGE_ID_OUTPUT" -rm -rf "$CLIENT_ADDRESSES_OUTPUT" - -# Create dtp-dev/publish_data if does not exists. -mkdir -p "$PUBLISH_DATA_DIR" - -echo "Output location = $PUBLISH_DATA_DIR" - -# Check that tsui is properly installed. -SUI_SCRIPT_VERSION=$("$SUI_SCRIPT" --version) -if [ -z "$SUI_SCRIPT_VERSION" ]; then - setup_error "$SUI_SCRIPT not installed properly. Please run 'dtp/script/init-$NETNAME'" -fi - -# Make sure testnet exists in sui envs (ignore errors because likely already exists) -$SUI_SCRIPT client new-env --alias testnet --rpc https://fullnode.testnet.sui.io:443 >& /dev/null - -# Make sure $NETNAME is the active envs. -$SUI_SCRIPT client switch --env $NETNAME > /dev/null || setup_error "Could not switch to $NETNAME" - -# Run all unit tests. -script_cmd "$SUI_SCRIPT move test --install-dir \"$PUBLISH_DATA_DIR\" -p \"$MOVE_SRC_DIR\"" - -# Build the Move package for publication. -echo Publishing... -script_cmd "$SUI_SCRIPT client publish --verify-dependencies --gas-budget 30000 --install-dir \"$PUBLISH_DATA_DIR\" \"$MOVE_SRC_DIR\"" - -# Grab the first line with an immutable "ID" after the "Created Objects" string. -id_line=$(cat "$SCRIPT_OUTPUT" | sed '1,/Created Objects/d' | grep 'ID' | grep 'Immutable') - -if [ -z "$id_line" ]; then - setup_error "Could not find the package id from $SCRIPT_OUTPUT" -fi - -ID="" -for i in $id_line -do - if beginswith 0x $i; then - ID=$i - break; - fi -done - -if [ -z "$ID" ]; then - setup_error "Could not find Package id in $SCRIPT_OUTPUT" -fi - -# TODO Validate the package ID is all hexadecimal - -# Test the publication by retreiving object information from the network -# using that parsed package id. -script_cmd "lsui client object $ID" -validation=$(lsui client object $ID | grep "Move Package") -if [ -z "$validation" ]; then - setup_error "Unexpected object type (Not a Move Package)" -fi - -# Write in client_addresses.txt the addresses created by config.yaml on genesis. -# sed remove all the spaces and replace "address:" with "0x" -$(cat "$GENESIS_DATA_DIR/config.yaml" | grep address | sed 's/ //g' | sed 's/\(^.*address:\)/0x/g' > "$PUBLISH_DATA_DIR/client_addresses.txt") - -# Create the package_id.txt file to confirm to caller successful publication. -echo "$ID" > "$PUBLISH_DATA_DIR/package_id.txt" -echo -echo PackageID is [$ID] -echo Publication Successful diff --git a/script/script_common b/script/script_common deleted file mode 100644 index b4acb34..0000000 --- a/script/script_common +++ /dev/null @@ -1,166 +0,0 @@ -#!/bin/bash - -# Do not call this script directly. It is a "common script" called by the other scripts. -# -# It initializes a bunch of environment variable, verify that some initialization took -# place, identify some common user errors etc... - -# DTP does not work with version below these. -MIN_SUI_VERSION="sui 0.22.0" -MIN_RUST_VERSION="rustc 1.65.0" - -# Mandatory command line input -SCRIPT_DIR=$1 -SCRIPT_NAME=$2 -NETNAME=$3 -SUI_REPO_BRANCH=$4 - -# Utility functions. -setup_error() { echo "$*" 1>&2 ; exit 1; } -export -f setup_error -version_greater_equal() { printf '%s\n%s\n' "$2" "$1" | sort --check=quiet --version-sort; } -export -f version_greater_equal -script_cmd() { script -efqa "$SCRIPT_OUTPUT" -c "$*"; } -export -f script_cmd -beginswith() { case $2 in "$1"*) true;; *) false;; esac; } -export -f beginswith - -# Directories -DEV_DIR_REL="$SCRIPT_DIR/../../dtp-dev" -DEV_DIR="$(cd "$(dirname "$DEV_DIR_REL")"; pwd)/$(basename "$DEV_DIR_REL")" -MOVE_SRC_DIR_REL="$SCRIPT_DIR/../move" -MOVE_SRC_DIR="$(cd "$(dirname "$MOVE_SRC_DIR_REL")"; pwd)/$(basename "$MOVE_SRC_DIR_REL")" -LOCAL_BIN="$HOME/.local/bin" - -# Some other commonly used locations. -SUI_REPO_DIR="$DEV_DIR/sui-$SUI_REPO_BRANCH-branch" -SUI_BIN_DIR="$SUI_REPO_DIR/target/debug" -GENESIS_DATA_DIR="$SCRIPT_DIR/genesis_data" - -NETWORK_DATA_DIR="$DEV_DIR/user-$NETNAME" -PUBLISH_DATA_DIR="$NETWORK_DATA_DIR/published_data" - -# Configuration files (often needed for sui CLI calls) -NETWORK_CONFIG="$NETWORK_DATA_DIR/network.yaml" -CLIENT_CONFIG="$NETWORK_DATA_DIR/client.yaml" - -SCRIPT_OUTPUT="$PUBLISH_DATA_DIR/publish_output.txt" -PACKAGE_ID_OUTPUT="$PUBLISH_DATA_DIR/package_id.txt" -CLIENT_ADDRESSES_OUTPUT="$PUBLISH_DATA_DIR/client_addresses.txt" - -update_bin_path() { - UBP_SRC_DIR="$HOME/.local/bin" - UBP_TARGET="$SCRIPT_DIR/$1" - if [ -d "$UBP_SRC_DIR" ]; then - if [ ! -L "$UBP_SRC_DIR/$1" ]; then - ln -s "$UBP_TARGET" "$UBP_SRC_DIR/$1" - echo "Symlink added: $UBP_SRC_DIR/$1 -> $UBP_TARGET" - else - # Verify link is as intended, if not replace it. - UBP_READLINK=$( readlink -f "$UBP_SRC_DIR/$1" ) - if [[ "$UBP_READLINK" != "$UBP_TARGET" ]]; then - ln -sf "$UBP_TARGET" "$UBP_SRC_DIR/$1" - echo "Symlink updated: $UBP_SRC_DIR/$1 -> $UBP_TARGET" - # If the target is the called script, then replace - # it and exit (will force user to re-execute from the - # new link, potentially being a different script version). - if [[ "$1" == "$SCRIPT_NAME" ]]; then - setup_error "Retry $1 again (in case the new synlink point to a new version)" - fi - fi - fi - fi -} -export -f update_bin_path - -build_sui_repo_branch() { - - # Verify Sui pre-requisites are installed. - which curl &> /dev/null || setup_error "Need to install curl. See https://docs.sui.io/build/install#prerequisites"; - which git &> /dev/null || setup_error "Need to install git. See https://docs.sui.io/build/install#prerequisites"; - which cmake &> /dev/null || setup_error "Need to install cmake. See https://docs.sui.io/build/install#prerequisites"; - which rustc &> /dev/null || setup_error "Need to install rust. See https://docs.sui.io/build/install#prerequisites"; - which cargo &> /dev/null || setup_error "Need to install cargo. See https://docs.sui.io/build/install#prerequisites"; - - # Verify Rust is recent enough. - version_greater_equal "$(rustc --version)" "$MIN_RUST_VERSION" || setup_error "Upgrade rust to a more recent version"; - - # If not already done, get the github sui $SUI_REPO_BRANCH. - if [ ! -d "$DEV_DIR/sui-$SUI_REPO_BRANCH-branch" ] - then - git clone -b devnet https://github.com/MystenLabs/sui.git "$DEV_DIR/sui-$SUI_REPO_BRANCH-branch" || setup_error "Failed getting Sui $SUI_REPO_BRANCH branch from github"; - fi - - # Update sui devnet local repo (if needed) - (cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch && git remote update >& /dev/null) - V1=$(cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch; git rev-parse HEAD) - V2=$(cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch; git rev-parse '@{u}') - if [ $V1 != $V2 ] - then - # Does a bit more than needed, but should allow to recover - # from most operator error... - echo Updating sui $NETNAME in dtp-dev... - (cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch && git switch $SUI_REPO_BRANCH > /dev/null) - (cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch && git fetch > /dev/null) - (cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch && git reset --hard origin/$SUI_REPO_BRANCH > /dev/null) - (cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch && git merge '@{u}') - fi - - # Verify sui built is latest. - echo Building $NETNAME using latest Sui $SUI_REPO_BRANCH branch... - (cd $DEV_DIR/sui-$SUI_REPO_BRANCH-branch; cargo build) - - # Sanity test that the sui binary works - if [ ! -f "$SUI_BIN_DIR/sui" ]; then - setup_error "$SUI_BIN_DIR/sui binary not found" - fi - - SUI_VERSION=$($SUI_BIN_DIR/sui --version) - if [ -z "$SUI_VERSION" ]; then - setup_error "$SUI_BIN_DIR/sui --version not running properly" - fi - - # Check if sui is recent enough. - version_greater_equal "$SUI_VERSION" "$MIN_SUI_VERSION" || setup_error "Sui binary version too old (not supported)" - -} - -export -f build_sui_repo_branch - -check_dev_setup() { - # Sanity check the development setup is OK. - if [ ! -d "$DEV_DIR" ]; then - setup_error "$DEV_DIR missing. Please run 'dtp/script/init-$NETNAME'" - fi - - if [ ! -d "$DEV_DIR/sui-$SUI_REPO_BRANCH-branch" ]; then - setup_error "$DEV_DIR/sui-$SUI_REPO_BRANCH-branch missing. Please run 'dtp/script/init-$NETNAME'" - fi - - if [ ! -d "$DEV_DIR/user-$NETNAME" ]; then - setup_error "$DEV_DIR/user-$NETNAME missing. Please run 'dtp/script/init-$NETNAME'" - fi -} - -export -f check_dev_setup - -common_init_dev_setup() { - # This is intended to be a fast initialization setup, and - # no-op if already all setup. Intent is just to fix symlinks if - # user did accidently deleted them and save the day. - mkdir -p "$DEV_DIR" - mkdir -p "$DEV_DIR/user-$NETNAME" - - update_bin_path "init-localnet" - update_bin_path "init-testnet" - update_bin_path "init-devnet" - update_bin_path "lsui" - update_bin_path "tsui" - update_bin_path "dsui" - update_bin_path "publish-localnet" - update_bin_path "publish-testnet" - update_bin_path "publish-devnet" - - echo "Output location = $DEV_DIR" -} -export -f common_init_dev_setup \ No newline at end of file diff --git a/script/tsui b/script/tsui deleted file mode 100755 index 746a50f..0000000 --- a/script/tsui +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -# Equivalent to sui, but for targeting remote testnet network only. - -# Utility functions. -setup_error() { echo "$*" 1>&2 ; exit 1; } - -# Just find the absolute path of the "dtp-dev" -SCRIPT_READLINK="$(readlink -f "$0")" -SCRIPT_NAME="$(basename $SCRIPT_READLINK)" -SCRIPT_DIR="$(dirname $SCRIPT_READLINK)" -DEV_DIR_REL="$SCRIPT_DIR/../../dtp-dev" -DEV_DIR="$(cd "$(dirname "$DEV_DIR_REL")"; pwd)/$(basename "$DEV_DIR_REL")" - -# Some other commonly used locations. -SUI_BIN_DIR="$DEV_DIR/sui-testnet/target/debug" - -# Files often needed for sui CLI calls -CLIENT_CONFIG="$DEV_DIR/testnet/client.yaml" -KEYSTORE_FILE="$DEV_DIR/testnet/sui.keystore" - -mkdir -p "$DEV_DIR/testnet" - -# TODO Validate if dtp-dev and sui binary are correct and give advises if not. - -# Use the proper config automatically. -SUI_SUBCOMMAND=$1 -if [[ "$1" = "client" || "$1" == "console" ]]; then - shift 1 - $SUI_BIN_DIR/sui $SUI_SUBCOMMAND --client.config "$CLIENT_CONFIG" "$@" - exit -fi - -if [[ "$1" == "network" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - $SUI_BIN_DIR/sui network --help - fi - echo - echo "network command not supported by tsui for remote testnet. Try with sui directly if you think it should work!?" - exit -fi - -if [[ "$1" == "genesis" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - $SUI_BIN_DIR/sui genesis --help - fi - echo - echo "genesis command not supported by tsui for remote testnet. Try with sui directly if you think it should work!?" -fi - -if [[ "$1" == "start" ]]; then - if [[ "$2" == "--help" || "$2" == "-h" ]]; then - $SUI_BIN_DIR/sui start --help - fi - echo - echo - echo "start command not supported by tsui for remote testnet. Try with sui directly if you think it should work!?" -fi - -if [[ "$1" == "keytool" ]]; then - shift 1 - $SUI_BIN_DIR/sui $SUI_SUBCOMMAND --keystore-path "$KEYSTORE_FILE" "$@" - exit -fi - -# Default -$SUI_BIN_DIR/sui "$@"