#!/bin/sh

# Function to generate a random string
generate_random_string_with_timestamp() {
    # Generate the timestamp in the desired format
    timestamp=$(TZ='Asia/Kuala_Lumpur' date "+%Y-%m-%d_%H-%M-%S")
    # Concatenate the timestamp and the random string
    echo "${timestamp}_dew_vault"
}

random_account_id="$(generate_random_string_with_timestamp)"
full_account_id="$random_account_id.testnet"

near create-account $full_account_id --useFaucet

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TARGET_DIR="$SCRIPT_DIR/../neardev"
mkdir -p "$TARGET_DIR"

echo "$full_account_id" > "$TARGET_DIR/dev-vault-account"