Skip to content
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: Genesis Accounts From CSV #232

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "scripts/seda-scripts"]
path = scripts/seda-scripts
url = [email protected]:sedaprotocol/seda-scripts.git
16 changes: 15 additions & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ For setting up your environment to develop `seda-chain`. Shows how to build, run
format, and clean the code base. To learn how to contribute please read
[here](CONTRIBUTING.md).

**NOTE**: Windows is not supported at this time.
> [!NOTE]
> Windows is not supported at this time.

## Sub Modules

We have a `git` submodule located at `scripts/seda-scripts`.

> [!NOTE]
> This submodule is a private repository but the scripts that
> refernce this module are for spinning up a network and
> non-seda devs don't need to interact with those portions.

To keep this submodule up to date you cd into the submodule and `git pull` like normal.

You can also make changes in that submodule and push them like normal.

## Dev-Container

Expand Down
68 changes: 68 additions & 0 deletions scripts/genesis_accounts_from_csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

# Grab the directory where this script is located
SCRIPTS_DIR="$(dirname "$0")"
# Source common functions
source "${SCRIPTS_DIR}/seda-scripts/common.sh"

# Does add-genesis-account for each entry in a CSV file.
# Usage: genesis_accounts_from_csv <CSV_FILE> <ERROR_LOG>
# Requires: sedad

usage "$0" 2 "$#" "CSV_FILE" "ERROR_LOG"

CSV_FILE=$1
ERROR_LOG=$2

# Clear the error log file at the beginning of the script run
> "$ERROR_LOG"

echo "Processing genesis accounts from $CSV_FILE"
# Skip the header line; read the rest of the lines
tail -n +2 "$CSV_FILE" | while IFS=, read -r address amount vesting_amount vesting_start_time vesting_end_time funder_addr || [ -n "$address" ]; do
echo "Processing address: $address"

# check address and amount are not empty
if [ -z "$address" ] || [ -z "$amount" ]; then
echo "Failed to process address: $address"
echo "$address,$amount,$vesting_amount,$vesting_start_time,$vesting_end_time,$funder_addr" >> "$ERROR_LOG"
echo "Address and amount are required fields" >> "$ERROR_LOG"
echo "--------------------------------" >> "$ERROR_LOG"
continue
fi

# Initialize command with mandatory parameters
cmd="${SEDA_BINARY} add-genesis-account \"$address\" \"${amount}\""

# Add conditional parameters
# If the vesting amount is not empty:
# neither should the vesting start time, end time, and funder address
if [ -z "$vesting_amount" ] && ([ -n "$vesting_start_time" ] || [ -n "$vesting_end_time" ] || [ -n "$funder_addr" ]); then
echo "Failed to process address: $address"
echo "$address,$amount,$vesting_amount,$vesting_start_time,$vesting_end_time,$funder_addr" >> "$ERROR_LOG"
echo "Vesting amount requires both vesting start time, vesting end time and funder_addr" >> "$ERROR_LOG"
echo "--------------------------------" >> "$ERROR_LOG"
continue
fi
[ -n "$vesting_amount" ] && cmd+=" --vesting-amount \"${vesting_amount}\""
[ -n "$vesting_start_time" ] && cmd+=" --vesting-start-time \"$vesting_start_time\""
[ -n "$vesting_end_time" ] && cmd+=" --vesting-end-time \"$vesting_end_time\""
[ -n "$funder_addr" ] && cmd+=" --funder \"$funder_addr\""

# Execute the command and capture all output
error_output=$(eval $cmd 2>&1)

# Check for any error, if eval command fails
if [ $? -ne 0 ]; then
echo "Failed to process address: $address"
echo "Command Executed: $cmd" >> "$ERROR_LOG"
# Write the failing entry and error message to the error log
echo "$address,$amount,$vesting_amount,$vesting_start_time,$vesting_end_time,$funder_addr" >> "$ERROR_LOG"
# Filter for lines with "Error:" or "ERR" and remove ANSI color codes, then write to the log
echo "$error_output" | grep -E "Error:|ERR" | sed 's/\x1b\[[0-9;]*m//g' >> "$ERROR_LOG"
echo "--------------------------------" >> "$ERROR_LOG"
fi

done

echo "All addresses processed."
4 changes: 4 additions & 0 deletions scripts/genesis_accounts_from_csv_example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
address,amount,vesting_amount,vesting_start_time,vesting_end_time,funder_addr
seda1fsw93wnvav0uvnzv3alk9zvkpp3jnn3pcj8l05,10000aseda,,,,
seda1e32g7uv8pw7jrxdhtz7adxfws0vw6u9gzcxccq,10000000000seda,,,,
seda1jd2q0mz0vzs75tp7lyuzf9064zccddgs8utjr5,10000seda,10000seda,1711612865,1774684865,seda1e32g7uv8pw7jrxdhtz7adxfws0vw6u9gzcxccq
1 change: 1 addition & 0 deletions scripts/seda-scripts
Submodule seda-scripts added at 59c7d2
Loading