-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scripts for random uploads and wallet generation
- Loading branch information
Showing
3 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
|
||
# Function to print a message in a box | ||
print_in_box() { | ||
local message="$1" | ||
local border_length=$((${#message} + 4)) | ||
local border=$(printf '%*s' "$border_length" | tr ' ' '#') | ||
|
||
echo "$border" | ||
echo "# $message #" | ||
echo "$border" | ||
} | ||
|
||
# Check for correct number of arguments | ||
if [ "$#" -ne 2 ]; then | ||
echo "Usage: $0 <number_of_wallets> <amount_per_wallet>" | ||
exit 1 | ||
fi | ||
|
||
# Get the input arguments | ||
NUM_WALLETS=$1 | ||
AMOUNT_PER_WALLET=$2 | ||
|
||
# Define directories relative to the current working directory | ||
APP_DIR=$(pwd) | ||
CLIENT_DIR="${APP_DIR}/client" | ||
NEW_CLIENT_DIR_TEMPLATE="${APP_DIR}/client_" | ||
|
||
# Initialize an array to store the wallet details | ||
declare -a WALLETS | ||
|
||
# Loop to create and fund wallets | ||
for ((i=1; i<=NUM_WALLETS; i++)); do | ||
# Step 1: Create a new wallet address and capture the new address | ||
safe wallet address | ||
start_address=$(safe wallet address | awk 'NR==3') | ||
|
||
# Step 2: Extract the first 5 characters of the wallet address | ||
start_prefix=$(echo "$start_address" | cut -c1-5) | ||
|
||
# Step 3: Define the new client directory names | ||
SOURCE_CLIENT_DIR="${NEW_CLIENT_DIR_TEMPLATE}${start_prefix}" | ||
|
||
# Step 4: Rename the original client directory to client_<5PK> | ||
mv "$CLIENT_DIR" "$SOURCE_CLIENT_DIR" | ||
print_in_box "Moving source client to $SOURCE_CLIENT_DIR" | ||
|
||
# Step 5: Create a new wallet address and capture the new address | ||
safe wallet address | ||
new_address=$(safe wallet address | awk 'NR==3') | ||
new_prefix=$(echo "$new_address" | cut -c1-5) | ||
NEW_CLIENT_DIR="${NEW_CLIENT_DIR_TEMPLATE}${new_prefix}" | ||
|
||
print_in_box "Moving new client to $NEW_CLIENT_DIR" | ||
|
||
# Step 6: Move the new client | ||
mv "$CLIENT_DIR" "$NEW_CLIENT_DIR" | ||
|
||
# Step 7: Restore the original client directory | ||
mv "$SOURCE_CLIENT_DIR" "$CLIENT_DIR" | ||
|
||
# Step 8: Send tokens to the new address | ||
echo "New address is: $new_address" | ||
transfer_output=$(safe wallet send "$AMOUNT_PER_WALLET" "$new_address") | ||
echo "Transfer output is: $transfer_output" | ||
|
||
# Extract the transfer note | ||
transfer_note=$(echo "$transfer_output" | awk '/Please share this to the recipient:/{getline; getline; print}') | ||
|
||
echo "Transfer note is: $transfer_note" | ||
|
||
# Store the wallet details in the array | ||
WALLETS+=("Wallet: client_${new_prefix}, Address: $new_address") | ||
|
||
# Step 9: Rename current client directory to client_<5PK> | ||
mv "$CLIENT_DIR" "$SOURCE_CLIENT_DIR" | ||
|
||
# Step 10: Restore the client_<5PK> to client | ||
mv "$NEW_CLIENT_DIR" "$CLIENT_DIR" | ||
|
||
# Step 11: Receive the funds using the transfer note | ||
safe wallet receive "$transfer_note" | ||
|
||
# Step 12: Rename the client directories back to their original names | ||
mv "$CLIENT_DIR" "$NEW_CLIENT_DIR" | ||
mv "$SOURCE_CLIENT_DIR" "$CLIENT_DIR" | ||
done | ||
|
||
# Print the summary of wallets created | ||
print_in_box "Summary of Wallets Created" | ||
for wallet in "${WALLETS[@]}"; do | ||
echo "$wallet" | ||
done | ||
print_in_box "End of Summary" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Function to check if the `safe` command exists, and install it if not | ||
check_and_install_safe() { | ||
if ! command -v safe &> /dev/null; then | ||
echo "'safe' command not found. Installing..." | ||
curl -sSL https://raw.githubusercontent.com/maidsafe/safeup/main/install.sh | sudo bash | ||
safeup client | ||
else | ||
echo "'safe' command is already installed." | ||
fi | ||
} | ||
|
||
# Function to generate a 10MB file of random data | ||
generate_random_data_file() { | ||
tmpfile=$(mktemp) | ||
dd if=/dev/urandom of="$tmpfile" bs=10M count=1 iflag=fullblock &> /dev/null | ||
|
||
echo "Generated random data file at $tmpfile" | ||
|
||
# Upload the random data file using SAFE CLI | ||
safe files upload "$tmpfile" | ||
# cat $tmpfile | ||
if [ $? -eq 0 ]; then | ||
echo "Successfully uploaded $tmpfile using SAFE CLI" | ||
else | ||
echo "Failed to upload $tmpfile using SAFE CLI" | ||
fi | ||
|
||
# Remove the temporary file | ||
rm "$tmpfile" | ||
|
||
# Log and sleep for 60 seconds | ||
echo "Sleeping for 60 seconds..." | ||
sleep 60 | ||
} | ||
|
||
# Check and install 'safe' if necessary | ||
check_and_install_safe | ||
|
||
# Example usage | ||
total_files=100 # Total number of files to generate and upload | ||
|
||
# Loop to generate and upload random data files | ||
for i in $(seq 1 $total_files); do | ||
echo "Generating and uploading file $i of $total_files..." | ||
generate_random_data_file | ||
done |