#!/bin/bash # Requirements: jq, parallel, xmr2csv, expect, all monero binaries # Before running this script first compile and run # "./monerod --stagenet" https://github.com/monero-project/monero#compiling-monero-from-source # Before running this script first compile xmr2csv # also add it to your path https://github.com/moneroexamples/transactions-export # Usage: ./collect.sh # Usage: This script expects to be placed into a folder that contains wallets. Each wallet should # have a Test-Wallet1, Test-Wallet1.keys, and Test-Wallet1.address.txt file. # If you use a remote node for the export portion of the script, just note that # you will need a local copy of the blockchain for the xmr2csv portion of the script. # Global variables NODE_ADDRESS="127.0.0.1" # testnet.community.rino.io | stagenet.community.rino.io | node.community.rino.io NETWORK="stagenet" # Case-sensitive (make all lowercase) (Options: "testnet", "stagenet", or "mainnet") num_processors=$(nproc --all) # TODO Pass in a directory ############################################################################# # You shouldn't need to edit anything below this line # ############################################################################# if [[ "$NETWORK" == "stagenet" ]];then NODE_RPC_PORT="38081"; LOCAL_RPC_PORT="38088"; fi if [[ "$NETWORK" == "testnet" ]];then NODE_RPC_PORT="28081"; LOCAL_RPC_PORT="28088"; fi if [[ "$NETWORK" == "mainnet" ]];then NODE_RPC_PORT="18081"; LOCAL_RPC_PORT="18088"; fi parent_dir=$(pwd) # Check to see if the xmr2csv_commands file exists and if it does does ask the user to delete it before preceding if [ -f "${parent_dir}/xmr2csv_commands.txt" ];then while true; do read -p "xmr2csv_commands.txt exists from a previous run. Would you like to proceed with the deletion? " answer case $answer in [Yy]* ) rm -f "${parent_dir}"/xmr2csv_commands.txt; break;; [Nn]* ) exit 1;; * ) echo "Please answer yes or no.";; esac done fi while read dir; do # Read in all directories that contain a .keys file in the current directory cd "$dir" || exit echo "$dir" working_dir=$(pwd) while read walletAddrFile; do # Loop each .address.txt wallet addr file # Gets the name of the current wallet file walletName=$(echo $walletAddrFile | cut -f 2 -d "." | cut -f 2 -d "/") # Gets the address of the current wallet walletAddr=$(cat "$walletAddrFile") if [ "$NETWORK" == "mainnet" ];then # Create script to export the current wallet transactions using the monero-wallet-cli cat >./Export_Wallet.exp <./Export_Wallet.exp < xmr2csv_start_time_"$walletAddr".csv if [ "$NETWORK" == "mainnet" ];then # Make xmr2csv command using all the collected values and save the command to a text file to be run in parallel later on echo xmr2csv --address "$walletAddr" --viewkey "$view_key" --spendkey "$spend_key" --start-height "$min_block_height" --ring-members --out-csv-file "$working_dir"/xmr_report_"$walletAddr".csv --out-csv-file2 "$working_dir"/xmr_report_ring_members_"$walletAddr".csv --out-csv-file3 "$working_dir"/xmr_report_ring_members_freq_"$walletAddr".csv --out-csv-file4 "$working_dir"/xmr_report_key_images_outputs_"$walletAddr".csv --out-csv-file5 "$working_dir"/xmr_report_outgoing_txs_"$walletAddr".csv >> "$parent_dir"/xmr2csv_commands.txt else # Make xmr2csv command using all the collected values and save the command to a text file to be run in parallel later on echo xmr2csv --address "$walletAddr" --viewkey "$view_key" --spendkey "$spend_key" --"$NETWORK" --start-height "$min_block_height" --ring-members --out-csv-file "$working_dir"/xmr_report_"$walletAddr".csv --out-csv-file2 "$working_dir"/xmr_report_ring_members_"$walletAddr".csv --out-csv-file3 "$working_dir"/xmr_report_ring_members_freq_"$walletAddr".csv --out-csv-file4 "$working_dir"/xmr_report_key_images_outputs_"$walletAddr".csv --out-csv-file5 "$working_dir"/xmr_report_outgoing_txs_"$walletAddr".csv >> "$parent_dir"/xmr2csv_commands.txt fi # Echo the commands to stdout echo -en "\033[34mXMR2CSV command constructed and saved to ${parent_dir}/xmr2csv_commands.txt\033[0m";echo; if [ "$NETWORK" == "mainnet" ];then echo -en "\033[34mxmr2csv --address $walletAddr --viewkey $view_key --spendkey $spend_key --start-height $min_block_height --ring-members --out-csv-file $working_dir/xmr_report_$walletAddr.csv --out-csv-file2 $working_dir/xmr_report_ring_members_$walletAddr.csv --out-csv-file3 $working_dir/xmr_report_ring_members_freq_$walletAddr.csv --out-csv-file4 $working_dir/xmr_report_key_images_outputs_$walletAddr.csv --out-csv-file5 $working_dir/xmr_report_outgoing_txs_$walletAddr.csv\033[0m";echo; else echo -en "\033[34mxmr2csv --address $walletAddr --viewkey $view_key --spendkey $spend_key --$NETWORK --start-height $min_block_height --ring-members --out-csv-file $working_dir/xmr_report_$walletAddr.csv --out-csv-file2 $working_dir/xmr_report_ring_members_$walletAddr.csv --out-csv-file3 $working_dir/xmr_report_ring_members_freq_$walletAddr.csv --out-csv-file4 $working_dir/xmr_report_key_images_outputs_$walletAddr.csv --out-csv-file5 $working_dir/xmr_report_outgoing_txs_$walletAddr.csv\033[0m";echo; fi fi # End error check done < <(find ./ -type f -name "*.address.txt" | sort -u) # Find text files in each wallet directory cd - || exit # Find wallet directories that contain a .keys file and only get the parent dirs done < <(find . -mindepth 2 -type f -name '*.keys' | sed -r 's|/[^/]+$||' | sort -u ) echo;echo;echo; echo -en '\033[34mStarting multiprocessing of xmr2csv exports... \033[0m';echo; # https://adamtheautomator.com/how-to-speed-up-bash-scripts-with-multithreading-and-gnu-parallel/ # Opne the file with all the commands and start the multiprocessing cat "$parent_dir"/xmr2csv_commands.txt | parallel --bar --jobs "$num_processors" {}