Generate stage1 genesis file from CSV with subscribed participants #13
@ -0,0 +1,94 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ "$#" -ne 3 ]; then
|
||||||
|
echo "Usage: $0 <subscribed-participants-csv> <participant-allocation> <validator-allocation>"
|
||||||
|
echo "Example: $0 /home/user/subscribed-participants.csv 1000000 1000000000000"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SUBSCRIBED_PARTICIPANTS_CSV="$1"
|
||||||
|
PARTICIPANT_ALLOCATION="$2"
|
||||||
|
VALIDATOR_ALLOCATION="$3"
|
||||||
|
STAGE1_GENESIS_DIR=stage1-genesis
|
||||||
|
|
||||||
|
# Create a temporary target directory
|
||||||
|
mkdir -p $STAGE1_GENESIS_DIR
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Parse the input CSV file to create stage1 onboarding module state
|
||||||
|
# Input CSV columns:
|
||||||
|
# 5: laconic_address, 6: nitro_address, 7: role, 8: hashed_subscriber_id, 11: funding_amount
|
||||||
|
|
||||||
|
stage1_participants_file="$STAGE1_GENESIS_DIR/stage1-participants.json"
|
||||||
|
jq -R -s --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" -f <(cat <<'EOF'
|
||||||
|
# Split the input into lines
|
||||||
|
split("\n") |
|
||||||
|
# Skip the first line (header) and filter out empty lines
|
||||||
|
.[1:] | map(select(length > 0)) |
|
||||||
|
# For each line, split it into fields by comma
|
||||||
|
map(split(",") | map(gsub("^\"|\"$"; ""))) |
|
||||||
|
# Create objects from the relevant fields
|
||||||
|
map({
|
||||||
|
cosmos_address: .[5],
|
||||||
|
nitro_address: .[6],
|
||||||
|
role: .[7],
|
||||||
|
kyc_id: .[8]
|
||||||
|
})
|
||||||
|
EOF
|
||||||
|
) < "$SUBSCRIBED_PARTICIPANTS_CSV" > "$stage1_participants_file"
|
||||||
|
|
||||||
|
echo "Exported participants for stage1 onboarding module state"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Parse the input CSV file to calculate allocations on stage1
|
||||||
|
# Use provided input amounts if funding amount not present in the CSV
|
||||||
|
|
||||||
|
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
||||||
|
jq -R -s --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" -f <(cat <<'EOF'
|
||||||
|
# Split the input into lines
|
||||||
|
split("\n") |
|
||||||
|
# Skip the first line (header) and filter out empty lines
|
||||||
|
.[1:] | map(select(length > 0)) |
|
||||||
|
# For each line, split it into fields by comma
|
||||||
|
map(split(",") | map(gsub("^\"|\"$"; ""))) |
|
||||||
|
# Create objects from the relevant fields
|
||||||
|
map({
|
||||||
|
cosmos_address: .[5],
|
||||||
|
balance: (
|
||||||
|
if .[11] == "" or .[11] == null then
|
||||||
|
if .[7] == "validator" then $validator_allocation else $participant_allocation end
|
||||||
|
else .[11] end
|
||||||
|
)
|
||||||
|
})
|
||||||
|
EOF
|
||||||
|
) < "$SUBSCRIBED_PARTICIPANTS_CSV" > "$stage1_allocations_file"
|
||||||
|
|
||||||
|
echo "Calculated allocations for stage 1 chain"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Run a script with cerc/laconicd:local to generate the genesis file
|
||||||
|
# with onboarding module state and given allocations
|
||||||
|
docker run -it \
|
||||||
|
-v ./$STAGE1_GENESIS_DIR:/root/.laconicd \
|
||||||
|
-v ./scripts:/scripts \
|
||||||
|
cerc/laconicd:local bash -c "/scripts/genesis.sh"
|
||||||
|
|
||||||
|
# Copy over the genesis file to output folder
|
||||||
|
OUTPUT_DIR=output
|
||||||
|
mkdir -p $OUTPUT_DIR
|
||||||
|
cp ./$STAGE1_GENESIS_DIR/config/genesis.json $OUTPUT_DIR/genesis.json
|
||||||
|
|
||||||
|
echo "Genesis file for stage1 written to $OUTPUT_DIR/genesis.json"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
echo "Please remove the temporary data directory: sudo rm -rf $STAGE1_GENESIS_DIR"
|
@ -21,23 +21,24 @@ mkdir -p $STAGE1_GENESIS_DIR
|
|||||||
|
|
||||||
# --------
|
# --------
|
||||||
|
|
||||||
# Export onboarding module state from stage0 laconicd chain
|
# Export participants from onboarding module state on stage0 laconicd chain
|
||||||
|
# Use cerc/laconicd-stage0:local image for stage0 laconicd build
|
||||||
|
|
||||||
onboarding_state_file="$STAGE1_GENESIS_DIR/stage0-onboarding-state.json"
|
stage1_participants_file="$STAGE1_GENESIS_DIR/stage1-participants.json"
|
||||||
docker run -it \
|
docker run -it \
|
||||||
-v ${STAGE0_DEPLOYMENT_DIR}/data/laconicd-data:/root/stage0-deployment/.laconicd \
|
-v ${STAGE0_DEPLOYMENT_DIR}/data/laconicd-data:/root/stage0-deployment/.laconicd \
|
||||||
cerc/laconicd:local bash -c "laconicd export --home /root/stage0-deployment/.laconicd" \
|
cerc/laconicd-stage0:local bash -c "laconicd export --home /root/stage0-deployment/.laconicd" \
|
||||||
| jq .app_state.onboarding > "$onboarding_state_file"
|
| jq .app_state.onboarding.participants > "$stage1_participants_file"
|
||||||
|
|
||||||
stage0_participants=$(cat "$onboarding_state_file" | jq .participants)
|
stage1_participants=$(cat "$stage1_participants_file")
|
||||||
|
|
||||||
echo "Exported onboarding module state from stage 0 chain"
|
echo "Exported participants for stage1 onboarding module state"
|
||||||
|
|
||||||
# --------
|
# --------
|
||||||
|
|
||||||
# For each participant, using ETH account holdings, figure out balance allocation for stage1
|
# For each participant, using ETH account holdings, figure out balance allocation for stage1
|
||||||
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
||||||
jq -n --argjson participants "$stage0_participants" --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" '
|
jq -n --argjson participants "$stage1_participants" --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" '
|
||||||
[
|
[
|
||||||
$participants[] |
|
$participants[] |
|
||||||
{
|
{
|
||||||
|
@ -10,14 +10,14 @@ CHAINID="laconic_9000-1"
|
|||||||
STAGE1_MONIKER=localtestnet-stage-1
|
STAGE1_MONIKER=localtestnet-stage-1
|
||||||
NODE_HOME="/root/.laconicd"
|
NODE_HOME="/root/.laconicd"
|
||||||
|
|
||||||
onboarding_state_file="$NODE_HOME/stage0-onboarding-state.json"
|
stage1_participants_file="$NODE_HOME/stage1-participants.json"
|
||||||
stage1_allocations_file="$NODE_HOME/stage1-allocations.json"
|
stage1_allocations_file="$NODE_HOME/stage1-allocations.json"
|
||||||
stage1_genesis_file="$NODE_HOME/config/genesis.json"
|
stage1_genesis_file="$NODE_HOME/config/genesis.json"
|
||||||
|
|
||||||
laconicd init $STAGE1_MONIKER --chain-id $CHAINID --default-denom alnt
|
laconicd init $STAGE1_MONIKER --chain-id $CHAINID --default-denom alnt
|
||||||
|
|
||||||
# Update onboarding module state with participants from stage0
|
# Update onboarding module state with participants
|
||||||
participants=$(jq -c '.participants' $onboarding_state_file)
|
participants=$(jq -c '.' $stage1_participants_file)
|
||||||
jq --argjson p "$participants" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file"
|
jq --argjson p "$participants" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file"
|
||||||
|
|
||||||
# Disable bank module transfers
|
# Disable bank module transfers
|
||||||
|
Loading…
Reference in New Issue
Block a user