#!/bin/bash
#
# SnollyGoster
# Have you ever think if you were special?
# https://snollygoster.xyz
# @snollyygoster // snollygoster@duck.com // SnollyGoster#2340
#
# Script ini berfungsi untuk cek unclaimed rewards ORE dalam dir yang diatur, lalu membuat dir temp untuk fungsi auto_send sehingga tidak repot memindahkan file .json ke folder baru
# Copy - Paste wallet memprioritaskan file .json yang berisi ORE, lalu wallet yang 0 ORE unclaimed, tidak terpaste kedalam temp dir

rpc=ISI RPC NYA
directory="/data/labs/ore50/keyring/"
temp_folder="$directory/temp/"

# Membuat folder temp jika belum ada
sudo mkdir -p "$temp_folder"

json_files=$(find "$directory" -type f -name '*.json')

total_ore=0

for file in $json_files
do
    echo "Checking rewards for $file"
    ore_output=$(ore --rpc $rpc --keypair "$file" rewards)
    ore_amount=$(echo "$ore_output" | cut -d ' ' -f 1)
    
    # Check if ore_amount is greater than 0
    if (( $(echo "$ore_amount > 0" | bc -l) )); then
        total_ore=$(echo "$total_ore + $ore_amount" | bc)
        echo "$ore_output"
        
        # Copy file JSON ke folder temp jika memiliki ORE
       sudo cp "$file" "$temp_folder"
    fi
done

echo "Total ORE: $total_ore"
