From b210c6e5eadca91563e0b07bfaf38512791bbdec Mon Sep 17 00:00:00 2001 From: Oink70 Date: Fri, 15 Jul 2022 08:03:13 +0000 Subject: [PATCH] Add PoS-addresses.sh and PoS-rewards.sh --- KnownStakingAddresses.sed | 1 + PoS-addresses.sh | 152 +++++++++++++++++++++++++++++++++++++ PoS-rewards.sh | 154 ++++++++++++++++++++++++++++++++++++++ README.md | 47 +++++++++++- 4 files changed, 352 insertions(+), 2 deletions(-) create mode 100644 KnownStakingAddresses.sed create mode 100755 PoS-addresses.sh create mode 100755 PoS-rewards.sh diff --git a/KnownStakingAddresses.sed b/KnownStakingAddresses.sed new file mode 100644 index 0000000..022b32c --- /dev/null +++ b/KnownStakingAddresses.sed @@ -0,0 +1 @@ +s/iBSUZSgXHEGGz65GTT6BGgchtkTHoFBs57/\x1B[32m& <-- Oink@\x1B[0m/g diff --git a/PoS-addresses.sh b/PoS-addresses.sh new file mode 100755 index 0000000..68a87e9 --- /dev/null +++ b/PoS-addresses.sh @@ -0,0 +1,152 @@ +#!/bin/bash +## © Oink 2022 +## This script retrieves and displays the addresses responsible for Proof-of-Stake rewards +## during the specified period. It counts the reward per address and displays them +## starting with the largest number of rewards to the least number. +## It also identifies known addresses and colorizes the ones it knows about. + +# Set locations of the Verus binary. This location will be used if verus was not found in the PATH environment. +VERUS=/home/verus/bin/verus + +## check if the Verus binary is found and verusd is running. +## If Verus exists in the PATH environment, use it. +## If not, fall back to predefined location in this script. +if ! command -v verus &>/dev/null +then + echo "verus not found in your PATH environment. Using location from line 9 in this script." + if ! command -v $VERUS &>/dev/null + then + echo "Verus could not be found. Make sure it's in your path and/or in line 9 of this script." + echo "exiting..." + exit 1 + fi +else + VERUS=$(which verus) +fi + +count=$(${VERUS} getconnectioncount 2>/dev/null) +case $count in + ''|*[!0-9]*) DAEMON_ACTIVE=0 ;; + *) DAEMON_ACTIVE=1 ;; +esac +if [[ "$DAEMON_ACTIVE" != "1" ]] +then + echo "verus daemon is not running and connected. Start your verus daemon and wait for it to be connected" + exit 1 +fi + +## Dependencies: jq, bc +if ! command -v jq &>/dev/null ; then + echo "jq not found. please install using your package manager." + exit 1 +else + JQ=$(which jq) +fi +if ! command -v bc &>/dev/null ; then + echo "bc not found. please install using your package manager." + exit 1 +else + BC=$(which bc) +fi + + +## set defaults +TIME_NOW=$(date +"%s") +TIME_END=$TIME_NOW +TIME_WINDOW=24hour +TIME_START=$(date -d "$(date -ud @${TIME_END}) - ${TIME_WINDOW}" +"%s") +FILTER_FILE=KnownStakingAddresses.sed + +## process command line parameters +POSITIONAL=() +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -t|--time-window) + TIME_WINDOW_SET=1 + TIME_WINDOW=$2 + shift # past argument + shift # past value + ;; + -e|--end-date) + TIME_END_SET=1 + TIME_END=$(date -d "$2" +"%s") + shift # past argument + shift # past value + ;; + -s|--start-date) + TIME_START_SET=1 + TIME_START=$(date -d "$2" +"%s") + shift # past argument + shift # past value + ;; + -f|--filter-file) + FILTER_FILE=$2 + shift # past argument + shift # past value + ;; + -h|--help) + printf "\nUsage:\n\PoS-addresses.sh [options]\n\n" + printf "Options:\n\n" + printf "\t-t #\t--time-window # :\tSet an arbitrary time window (default 24hours). This amount will be deducted from the end date to determine the start date.\n" + printf "\t\t\t\t\tRequires #minute/#hour/#day/#week/#month/#year.\n" + printf "\t-s #\t--start # :\t\tSet a start date (00:00 UTC). Overrides the time window. Requires time in YYYY-MM-DD format.\n" + printf "\t-e #\t--end # :\t\tSet an end date (00:00 UTC). if not set, it uses the current time. Requires time in YYYY-MM-DD format.\n" + printf "\t-t #\t--filter-file # :\tSpecify a custom filterfile for the sed function to identify known addresses.\n" + printf "\t-h\t--help :\t\tShows this message on the console.\n" + printf "\nExamples:\n\n" + printf "PoS-addresses.sh -t 1week\t\t\tCheck the past week.\n" + printf "PoS-addresses.sh -s 2022-07-13\t\tCheck succesful PoS addresses from 2022-07-13, 00:00 to now.\n" + printf "PoS-addresses.sh -e 2022-07-14\t\tCheck succesful PoS addresses from 2022-07-13, 00:00 to 2022-07-14, 00:00.\n" + printf "PoS-addresses.sh -e 2022-07-14 -t 2day\tCheck PoS addresses from two days prior of 2022-07-14, 00:00 up to 2022-07-14, 00:00.\n" + printf "PoS-addresses.sh -t private-list\t\tUse the file private-list to identify addresses.\n" + printf "\n" + exit 0 + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift # past argument + ;; + esac +done + +## process the values from the command line parameters +if [ "$TIME_START_SET" == "1" ] +then + TIME_WINDOW="" +# echo "Start time is set manually, ignoring time-window (if any)" # enable to verify if the check (if-then condition) works as intended. +else + # echo "start time not specified, calculating using and time and time-window." # enable to verify if the check (if-then condition) works as intended. + TIME_START=$(date -d "$(date -ud @${TIME_END}) - ${TIME_WINDOW}" +"%s") +fi + +## Determine the blocknumbers that need to be scanned. +## D etermine the first block that happens after $TIME_START +## To do this, we take an hour time window, retrieve the list of blockhashes +## between $TIME_START and $TIME_START+1hour, to account for an occasional long blocktime +declare -i b=$($VERUS getblock $($VERUS getblockhashes $((TIME_START+3600)) $TIME_START | jq -r '.[0]') | jq -r '.height') + +## Determine the last block that happens before $TIME_END +## To do this, we take an hour time window, retrieve the list of blockhashes +## between $TIME_END+1hour and $TIME_END, to account for an occasional long blocktime +declare -i e=$($VERUS getblock $($VERUS getblockhashes $TIME_END $((TIME_END-3600)) | jq -r '.[-1]') | jq -r '.height') + +## declaring variables +declare -i c=$b + +## Start with the payload +echo -e "Showing staking addresses responsible for staked blocks from block $c to block $e" + +## Retrieving every block in the time window, determine for each block if it was a staked block, +## then pipe the result through sorting, counting the amount of blocks per address and +## sorting the result from high to low. +## Finally identify known addresses from the separate KnownStakingAddresses.sed file and add that info to the output +while [ $c -le $e ]; do + $VERUS getblock "$c" 2 | $JQ -r '. | select(.validationtype=="stake") | .tx | .[-1].vout | .[0].scriptPubKey | .addresses| .[0]' + c+=1 +done | \ +sort | \ +uniq -c | \ +sort -bgr | \ +sed -f $FILTER_FILE diff --git a/PoS-rewards.sh b/PoS-rewards.sh new file mode 100755 index 0000000..ea9264d --- /dev/null +++ b/PoS-rewards.sh @@ -0,0 +1,154 @@ +#!/bin/bash +## © Oink 2022 +## This script retrieves and displays the addresses that received a Proof-of-Stake reward +## during the specified period. It counts the awards per address and displays them +## starting with the largest number of rewards to the least number. +## It also identifies known addresses and colorizes the ones it knows about. + +# Set locations of the Verus binary. This location will be used if verus was not found in the PATH environment. +VERUS=/home/verus/bin/verus + +## check if the Verus binary is found and verusd is running. +## If Verus exists in the PATH environment, use it. +## If not, fall back to predefined location in this script. +if ! command -v verus &>/dev/null +then + echo "verus not found in your PATH environment. Using location from line 9 in this script." + if ! command -v $VERUS &>/dev/null + then + echo "Verus could not be found. Make sure it's in your path and/or in line 9 of this script." + echo "exiting..." + exit 1 + fi +else + VERUS=$(which verus) +fi + +count=$(${VERUS} getconnectioncount 2>/dev/null) +case $count in + ''|*[!0-9]*) DAEMON_ACTIVE=0 ;; + *) DAEMON_ACTIVE=1 ;; +esac +if [[ "$DAEMON_ACTIVE" != "1" ]] +then + echo "verus daemon is not running and connected. Start your verus daemon and wait for it to be connected" + exit 1 +fi + +## Dependencies: jq, bc +if ! command -v jq &>/dev/null ; then + echo "jq not found. please install using your package manager." + exit 1 +else + JQ=$(which jq) +fi +if ! command -v bc &>/dev/null ; then + echo "bc not found. please install using your package manager." + exit 1 +else + BC=$(which bc) +fi + + +## set defaults +TIME_NOW=$(date +"%s") +TIME_END=$TIME_NOW +TIME_WINDOW=24hour +TIME_START=$(date -d "$(date -ud @${TIME_END}) - ${TIME_WINDOW}" +"%s") +FILTER_FILE=KnownStakingAddresses.sed + +## process command line parameters +POSITIONAL=() +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -t|--time-window) + TIME_WINDOW_SET=1 + TIME_WINDOW=$2 + shift # past argument + shift # past value + ;; + -e|--end-date) + TIME_END_SET=1 + TIME_END=$(date -d "$2" +"%s") + shift # past argument + shift # past value + ;; + -s|--start-date) + TIME_START_SET=1 + TIME_START=$(date -d "$2" +"%s") + shift # past argument + shift # past value + ;; + -f|--filter-file) + FILTER_FILE=$2 + shift # past argument + shift # past value + ;; + -h|--help) + printf "\nUsage:\n\PoS-rewards [options]\n\n" + printf "Options:\n\n" + printf "\t-t #\t--time-window # :\tSet an arbitrary time window (default 24hours). This amount will be deducted from the end date to determine the start date.\n" + printf "\t\t\t\t\tRequires #minute/#hour/#day/#week/#month/#year.\n" + printf "\t-s #\t--start # :\t\tSet a start date (00:00 UTC). Overrides the time window. Requires time in YYYY-MM-DD format.\n" + printf "\t-e #\t--end # :\t\tSet an end date (00:00 UTC). if not set, it uses the current time. Requires time in YYYY-MM-DD format.\n" + printf "\t-t #\t--filter-file # :\tSpecify a custom filterfile for the sed function to identify known addresses.\n" + printf "\t-h\t--help :\t\tShows this message on the console.\n" + printf "\nExamples:\n\n" + printf "PoS-rewards -t 1week\t\t\tCheck the past week.\n" + printf "PoS-rewards -s 2022-07-13\t\tCheck PoS rewards from 2022-07-13, 00:00 to now.\n" + printf "PoS-rewards -e 2022-07-14\t\tCheck PoS rewards from 2022-07-13, 00:00 to 2022-07-14, 00:00.\n" + printf "PoS-rewards -e 2022-07-14 -t 2day\tCheck PoS from two days prior of 2022-07-14, 00:00 up to 2022-07-14, 00:00.\n" + printf "PoS-rewards -t private-list\t\tUse the file private-list to identify addresses.\n" + printf "\n" + exit 0 + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift # past argument + ;; + esac +done + +## process the values from the command line parameters +if [ "$TIME_START_SET" == "1" ] +then + TIME_WINDOW="" +# echo "Start time is set manually, ignoring time-window (if any)" # enable to verify if the check (if-then condition) works as intended. +else + # echo "start time not specified, calculating using and time and time-window." # enable to verify if the check (if-then condition) works as intended. + TIME_START=$(date -d "$(date -ud @${TIME_END}) - ${TIME_WINDOW}" +"%s") +fi + +## Determine the blocknumbers that need to be scanned. +## D etermine the first block that happens after $TIME_START +## To do this, we take an hour time window, retrieve the list of blockhashes +## between $TIME_START and $TIME_START+1hour, to account for an occasional long blocktime +declare -i b=$($VERUS getblock $($VERUS getblockhashes $((TIME_START+3600)) $TIME_START | jq -r '.[0]') | jq -r '.height') + +## Determine the last block that happens before $TIME_END +## To do this, we take an hour time window, retrieve the list of blockhashes +## between $TIME_END+1hour and $TIME_END, to account for an occasional long blocktime +declare -i e=$($VERUS getblock $($VERUS getblockhashes $TIME_END $((TIME_END-3600)) | jq -r '.[-1]') | jq -r '.height') + +## declaring variables +declare -i c=$b + +## Start with the payload +echo -e "Showing PoS reward addresses from block $c to block $e" + +## Retrieving every block in the time window, determine for each block if it was a staked block, +## then pipe the result through sorting, counting the amount of blocks per address and +## sorting the result from high to low. +## filter out `RCG8KwJNDVwpUBcdoa6AoHqHVJsA1uMYMR`, which is a trustless address used by the staking consensus. +## Finally identify known addresses from the separate KnownStakingAddresses.sed file and add that info to the output +while [ $c -le $e ]; do + $VERUS getblock "$c" 2 | $JQ -r '. | select(.validationtype=="stake") | .tx | .[0].vout | .[0].scriptPubKey | .addresses| .[]' + c+=1 +done | \ +sort | \ +uniq -c | \ +sort -bgr | \ +sed '/RCG8KwJNDVwpUBcdoa6AoHqHVJsA1uMYMR/d' | \ +sed -f $FILTER_FILE diff --git a/README.md b/README.md index 332eb3a..08c6828 100644 --- a/README.md +++ b/README.md @@ -101,11 +101,12 @@ Loosely based on scripts from https://github.com/alexenglish/VerusExtras ## PoW-rewards.sh ### Description -Shows how many mining block rewards addresses got over a specified time frame. +Shows how many mining block rewards addresses got over a specified time frame. It uses the `sed` filter file `KnownPoolAddresses.sed` by default to identify known addresses. ### Prerequisites - Linux OS - `bc` and `jq` installed + - `KnownPoolAddresses.sed` file in the script folder - The `verus` binary in the PATH environment. If not found it falls back to the location of the `verus` binary is set on line 9 of the script. - a running `Verusd` daemon @@ -113,7 +114,49 @@ Shows how many mining block rewards addresses got over a specified time frame. `./PoW-rewards.sh [options]` ##### Options: - `-t # || --time-window #` : Set an arbitrary time window (default 24hours). This amount will be deducted from the end date to determine the start date. - Requires #minute/#hour/#day/#week/#month/#year. + Requires #minute/#hour/#day/#week/#month/#year. + - `-s # || --start #` : Set a start date (00:00 UTC). Overrides the time window. Requires time in YYYY-MM-DD format. + - `-e # || --end #` : Set an end date (00:00 UTC). if not set, it uses the current time. Requires time in YYYY-MM-DD format. + - `-t # || --filter-file #` : Specify a custum filterfile for the sed function to identify known addresses. + - `-h || --help` : Displays help text on the console. + +## PoS-rewards.sh +### Description +Shows how many staking block rewards addresses got over a specified time frame. It uses the `sed` filter file `KnownStakingAddresses.sed` by default to identify known addresses. + +### Prerequisites + - Linux OS + - `bc` and `jq` installed + - `KnownStakingAddresses.sed` file in the script folder + - The `verus` binary in the PATH environment. If not found it falls back to the location of the `verus` binary is set on line 9 of the script. + - a running `Verusd` daemon + +### Usage +`./PoW-rewards.sh [options]` +##### Options: + - `-t # || --time-window #` : Set an arbitrary time window (default 24hours). This amount will be deducted from the end date to determine the start date. + Requires #minute/#hour/#day/#week/#month/#year. + - `-s # || --start #` : Set a start date (00:00 UTC). Overrides the time window. Requires time in YYYY-MM-DD format. + - `-e # || --end #` : Set an end date (00:00 UTC). if not set, it uses the current time. Requires time in YYYY-MM-DD format. + - `-t # || --filter-file #` : Specify a custum filterfile for the sed function to identify known addresses. + - `-h || --help` : Displays help text on the console. + +## PoS-addresses.sh +### Description +Shows addresses that are responsible for staked blocks over a specific period of time. It uses the `sed` filter file `KnownStakingAddresses.sed` by default to identify known addresses. + +### Prerequisites + - Linux OS + - `bc` and `jq` installed + - `KnownStakingAddresses.sed` file in the script folder + - The `verus` binary in the PATH environment. If not found it falls back to the location of the `verus` binary is set on line 9 of the script. + - a running `Verusd` daemon + +### Usage +`./PoW-rewards.sh [options]` +##### Options: + - `-t # || --time-window #` : Set an arbitrary time window (default 24hours). This amount will be deducted from the end date to determine the start date. + Requires #minute/#hour/#day/#week/#month/#year. - `-s # || --start #` : Set a start date (00:00 UTC). Overrides the time window. Requires time in YYYY-MM-DD format. - `-e # || --end #` : Set an end date (00:00 UTC). if not set, it uses the current time. Requires time in YYYY-MM-DD format. - `-t # || --filter-file #` : Specify a custum filterfile for the sed function to identify known addresses.