-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add scripts for random uploads and wallet generation #1884
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the whole flow can be optimized to: Not a big issue, as anyway script do the job |
||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it requires arguments to be passed in,
better give an example of usage in the comment (head of this file, or in the readme correspondently?)