Skip to content

Instantly share code, notes, and snippets.

@gotjoshua
Last active February 11, 2021 14:06
Show Gist options
  • Save gotjoshua/9ceefa07ef32aef3fbb373c320e854f1 to your computer and use it in GitHub Desktop.
Save gotjoshua/9ceefa07ef32aef3fbb373c320e854f1 to your computer and use it in GitHub Desktop.
regen txs batched
#!/bin/bash
# usage tasks.sh BATCHES PretixOfExistingKeys SigningKeyName ToWhatAddress
read -e -s -p "Keyring pass?" PP
BATCHES=${1:-12}
MAX_WALLET=${2:-400}
BATCH_SIZE=$((MAX_WALLET / BATCHES))
PREFIX=${3:-begreenXtra}
SIGNER=${4:-begreen}
# using send to self stfategy instead
#TO=${5:-regen:1ky56h2ndwrgcxxr3s3g4uzseaj2mhthznheqhw} #PoSFreak
rm -f multi.tx
rm -f signed.tx
rm -f broadcast-async.tx
rm -f merged.tx
touch merged.tx
## from: ###############
# https://stackoverflow.com/questions/1455695/forking-multi-threaded-processes-bash
declare -a pids
waitPids() {
while [ ${#pids[@]} -ne 0 ]; do
# echo "Waiting for pids: ${pids[@]}"
local range=$(eval echo {0..$((${#pids[@]}-1))})
local i
for i in $range; do
if ! kill -0 ${pids[$i]} 2> /dev/null; then
echo -n "Done -- ${pids[$i]}"
unset pids[$i]
fi
done
pids=("${pids[@]}") # Expunge nulls created by unset.
sleep 1
done
echo "DoneDone!"
}
addPid() {
local desc=$1
local pid=$2
echo -n "$desc-$pid ... "
pids=(${pids[@]} $pid)
}
NODE=""
for j in $(eval echo {0..$((BATCHES - 1))}); do
# outer loop
START=$((j * BATCH_SIZE))
END=$((START + BATCH_SIZE))
RANGE=$(eval echo {$START..$END})
echo "================ Starting Loop $START..$END ==============="
for i in $RANGE; do
whichWallet="begreenXtra${i}"
# echo $whichWallet
eachAddress=$(echo $PP | regen keys show $whichWallet -a)
sendCmd="regen tx bank send $eachAddress $eachAddress 10utree --chain-id aplikigo-1 --memo $whichWallet --gas-prices 0.025utree -y --generate-only"
# echo $sendCmd
$sendCmd > obo$i.tx
cat obo$i.tx >> multi.tx
echo $PP | regen tx sign obo$i.tx --chain-id aplikigo-1 --from $whichWallet > obosigned$i.tx &
addPid "$whichWallet" $!
# add each to signed file
cat obosigned$i.tx >> signed.tx
done
waitPids #signing
for i in $RANGE; do
#alternate nodes
# NODE=$([ $((i % 2)) == 0 ] && echo "--node http://161.35.51.84:26657" || echo "") # "--node http://localhost:26657"
# Fork the broadcasts
BRCMD="regen tx broadcast obosigned$i.tx $NODE -b async"
# echo $BRCMD
echo $PP | $BRCMD >> broadcast-async.tx &
addPid "bc$i" $! # broadcast for obosigned$i.tx
done
waitPids & #broadcasting
echo
echo
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment