|
#!/bin/bash |
|
|
|
|
|
# 💡 TAKE ACCOUNTS ONLINE |
|
# inspired by https://epocks.com/onlinenode.html |
|
# ================================================= |
|
declare -a offline_accounts |
|
get_offline_accounts() { |
|
echo "👤 Getting accounts in wallet..." |
|
tmp=$(mktemp) #create temp file |
|
trap 'rm -f -- "$tmp"' EXIT # make sure we delete temp files on crash |
|
(goal account list | tee /dev/tty) > $tmp # save account list in file |
|
sed -i '/^Please enter the password/d' $tmp # remove password prompt line |
|
offline_accounts=( $( grep "[offline]" $tmp | tr -s ' ' | cut -d ' ' -f3 ) ) |
|
rm $tmp # delete temp file |
|
echo '' |
|
} |
|
take_account_online() { |
|
echo "💡 Taking account $1 online..." |
|
raw=$(mktemp); signed=$(mktemp) #create temp file for raw + signed txns |
|
trap 'rm -f -- "$raw"' EXIT; trap 'rm -f -- "$signed"' EXIT # make sure we delete temp files on crash |
|
|
|
firstValid=$(goal node lastround) |
|
goal account changeonlinestatus \ |
|
--address=$1 \ |
|
--fee=2000 \ |
|
--firstvalid=$firstValid \ |
|
--lastvalid=$(expr $firstValid + 100) \ |
|
--online=true \ |
|
--txfile=$raw |
|
goal clerk sign --infile=$raw --outfile=$signed |
|
goal clerk rawsend --filename=$signed |
|
|
|
rm $raw; rm $signed # delete temp files |
|
echo '' |
|
} |
|
take_all_accounts_online() { |
|
# get account list |
|
get_offline_accounts |
|
echo '🔌 All offline accounts: ' |
|
printf -v var "%s\n" "${offline_accounts[@]}" |
|
# take each account offline |
|
for address in "${offline_accounts[@]}"; do |
|
take_account_online $address |
|
done |
|
echo '💡 All accounts are online!' |
|
} |
|
|
|
|
|
|
|
|
|
# 🔌 TAKE ACCOUNTS OFFLINE |
|
# inspired by https://epocks.com/onlinenode.html |
|
# ================================================= |
|
declare -a online_accounts |
|
get_online_accounts() { |
|
echo "👤 Getting accounts in wallet..." |
|
tmp=$(mktemp) #create temp file |
|
trap 'rm -f -- "$tmp"' EXIT # make sure we delete temp files on crash |
|
(goal account list | tee /dev/tty) > $tmp # save account list in file |
|
sed -i '/^Please enter the password/d' $tmp # remove password prompt line |
|
online_accounts=( $( grep "[online]" $tmp | tr -s ' ' | cut -d ' ' -f3 ) ) |
|
rm $tmp # delete temp file |
|
echo '' |
|
} |
|
|
|
take_account_offline() { |
|
echo "🔌 Taking account $1 offline..." |
|
raw=$(mktemp); signed=$(mktemp) #create temp file for raw + signed txns |
|
trap 'rm -f -- "$raw"' EXIT; trap 'rm -f -- "$signed"' EXIT # make sure we delete temp files on crash |
|
|
|
firstValid=$(goal node lastround) |
|
goal account changeonlinestatus \ |
|
--address=$1 \ |
|
--fee=2000 \ |
|
--firstvalid=$firstValid \ |
|
--lastvalid=$(expr $firstValid + 100) \ |
|
--online=false \ |
|
--txfile=$raw |
|
goal clerk sign --infile=$raw --outfile=$signed |
|
goal clerk rawsend --filename=$signed |
|
|
|
rm $raw; rm $signed # delete temp file |
|
echo '' |
|
} |
|
|
|
take_all_accounts_offline() { |
|
# get account list |
|
get_online_accounts |
|
echo '💡 Online Accounts: ' |
|
printf -v var "%s\n" "${online_accounts[@]}" |
|
# take each account offline |
|
for address in "${online_accounts[@]}"; do |
|
take_account_offline $address |
|
done |
|
echo '🔌 All accounts are offline. Node can be stopped safely...' |
|
} |
|
|
|
|
|
|
|
|
|
# COMMANDS |
|
# ================================================= |
|
case $1 in |
|
# HELP |
|
# ================================================= |
|
"help") |
|
echo " |
|
Quick functions |
|
---------------- |
|
algo install Install a node from scratch (uses \$ALGORAND_FOLDER variable) |
|
algo update Update your node to the latest version |
|
algo catchup Gets the latest catchpoint and start cathing up from it |
|
|
|
algo start Start your node |
|
algo stop Stop the node (also takes the accounts offline first) |
|
algo status Log the current state of you node, once |
|
algo watch Display the node status and updates it every 3.7s |
|
|
|
algo keys list List all the participation keys from your node |
|
algo keys new <addr> Generate new participation keys for a given account |
|
algo keys renew <addr> Regenerates the keys for an account, and push them online |
|
algo keys online Sets all participating accounts as online (can pass a single account too) |
|
algo keys offline Sets all participating accounts as offline (can pass a single account too) |
|
|
|
algo <anything> Alias for 'goal ...'. |
|
|
|
|
|
|
|
Steps to get running |
|
--------------------- |
|
1. algo install |
|
2. algo start |
|
3. algo catchup |
|
4. algo wallet new <my wallet name> |
|
5. algo account import -m \"my twenty five word mnemonic without commas\" |
|
6. algo keys new <the address you just imported> |
|
7. algo keys online |
|
" |
|
;; |
|
|
|
|
|
# START / STOP NODE |
|
# ================================================= |
|
# > algo start |
|
"start") |
|
goal node start |
|
;; |
|
|
|
# > algo stop |
|
"stop") |
|
# take all account offline before stopping node |
|
echo '🛑 Taking all accounts offline...' |
|
take_all_accounts_offline |
|
# stop the node |
|
echo '🛑 Stopping node...' |
|
goal node stop |
|
;; |
|
|
|
|
|
# NODE STATUS |
|
# ================================================= |
|
# > algo status |
|
"status") |
|
goal node status |
|
;; |
|
|
|
# > algo watch |
|
# updates every 3.7s :) |
|
"watch") |
|
goal node status -w 3700 |
|
;; |
|
|
|
|
|
# PARTICIPATION KEYS |
|
# https://epocks.com/onlinenode.html |
|
# ================================================= |
|
"keys") |
|
case $2 in |
|
# > algo keys list |
|
# List current keys in your node |
|
"list") |
|
goal account listpartkeys |
|
;; |
|
|
|
# > algo keys new <AAAAA...AAAAA> |
|
# Generate new participation keys for a given account |
|
"new") |
|
firstValid=$(goal node lastround) |
|
lastValid=$(expr $firstValid + 3000000) |
|
goal account addpartkey \ |
|
--address=$3 \ |
|
--roundFirstValid=$firstValid \ |
|
--roundLastValid=$lastValid |
|
;; |
|
|
|
# > algo keys renew <AAAAA...AAAAA> |
|
# Renew participation keys for a given account |
|
"renew") |
|
firstValid=$(goal node lastround) |
|
lastValid=$(expr $firstValid + 3000000) |
|
goal account renewpartkey \ |
|
--address=$3 \ |
|
--roundLastValid=$lastValid |
|
;; |
|
|
|
# > algo keys online <AAAAA...AAAAA> |
|
# Set online status for a given account |
|
"online") |
|
if [ -z "$3" ]; then |
|
take_all_accounts_online |
|
else |
|
take_account_online $3 |
|
fi |
|
;; |
|
|
|
# > algo keys offline <AAAAA...AAAAA> |
|
# take an account offline |
|
"offline") |
|
if [ -z "$3" ]; then |
|
take_all_accounts_offline |
|
else |
|
take_account_offline $3 |
|
fi |
|
;; |
|
|
|
esac |
|
;; |
|
|
|
|
|
# INSTALL IN $ALGORAND_FOLDER |
|
# https://developer.algorand.org/docs/run-a-node/setup/install/#installation-with-the-updater-script |
|
# ================================================= |
|
"install") |
|
if [ -d $ALGORAND_DATA ]; then |
|
echo "❌ Looks like a node is already installed." |
|
exit; |
|
fi |
|
current_folder=$PWD |
|
mkdir $ALGORAND_FOLDER |
|
cd $ALGORAND_FOLDER |
|
curl https://raw.githubusercontent.com/algorand/go-algorand/rel/stable/cmd/updater/update.sh -O |
|
chmod 744 update.sh |
|
./update.sh -i -c stable -p $ALGORAND_FOLDER -d $ALGORAND_DATA -n |
|
cd $current_folder |
|
;; |
|
|
|
# UPDATE NODE |
|
# https://developer.algorand.org/docs/run-a-node/setup/install/#updating-node |
|
# ================================================= |
|
"update") |
|
if [ ! -f $ALGORAND_FOLDER/update.sh ]; then |
|
echo "❌ Can't find updater script." |
|
exit; |
|
fi |
|
$ALGORAND_FOLDER/update.sh -d $ALGORAND_DATA |
|
;; |
|
|
|
|
|
# SYNC NODE USING CATCHUP |
|
# https://developer.algorand.org/docs/run-a-node/setup/install/#sync-node-network-using-fast-catchup |
|
# ================================================= |
|
"catchup") |
|
catchpoint=$(curl https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint) |
|
goal node catchup $catchpoint |
|
goal node status -w 1000 |
|
;; |
|
|
|
# EVERYTHING ELSE |
|
# ================================================= |
|
*) |
|
goal "$@" |
|
;; |
|
esac |
|
|