Skip to content

Commit

Permalink
Merge pull request #96 from patrickmogul/dev-claim
Browse files Browse the repository at this point in the history
v1.5.2 - Claim Fixed
  • Loading branch information
patrickmogul authored Nov 6, 2023
2 parents 7a5ecae + bdb1216 commit 71010f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
# Load environment variables from .env file
load_dotenv()

self.toolbox_version = "1.5.2"
self.toolbox_version = "1.5.3"
self.server_host_name = socket.gethostname()
self.user_home_dir = os.path.expanduser("~")
self.dotenv_file = f"{self.user_home_dir}/.findora.env"
Expand Down
50 changes: 28 additions & 22 deletions src/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def set_main_or_test() -> None:

def menu_findora() -> None:
print(Fore.MAGENTA)
update = menu_topper()
update, public_address = menu_topper()
print("* Findora Validator Toolbox - Menu Options:")
print("*")
print("* 1 - Show 'curl' stats info - Run this to show your local curl stats!")
Expand Down Expand Up @@ -537,7 +537,7 @@ def menu_findora() -> None:
)
print("* 0 - Exit Application - Goodbye!")
print_stars()
return
return public_address


def get_curl_stats() -> None:
Expand Down Expand Up @@ -577,20 +577,24 @@ def refresh_fn_stats() -> None:
)


def claim_findora_rewards() -> None:
import subprocess

def claim_findora_rewards(public_address) -> None:
print_stars()
try:
subprocess.call(
["fn", "claim"],
print("* Claiming all pending FRA rewards now.")
result = subprocess.call(
["fn", "claim", "--validator-td-addr", public_address],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
print("* Claim all pending completed, refresh your stats after the next block.")
except subprocess.CalledProcessError as err:
print(
"* Error, no response from local API, try your command again or "
+ f"check your fn stats to see if there's an issue.\n* Error: {err}"
)
if result == 0:
print("* Claim all pending completed, refresh your stats after the next block.")
else:
print("* Error: An issue occurred while claiming rewards. Please check your command and try again.")
except Exception as err:
print("* Error: An unexpected error occurred. Please check your setup and try again.")
print(f"* Error: {err}")


def get_total_send(our_fn_stats) -> None:
Expand Down Expand Up @@ -1101,14 +1105,14 @@ def fetch_fn_show_output():


def get_fn_stats(output):
address = extract_value(output, "Validator Node Addr")
public_address = extract_value(output, "Validator Node Addr")
# Convert the validator_address to lowercase and ensure it starts with '0x'
validator_address = address.lower()
if not validator_address.startswith("0x"):
validator_address = "0x" + validator_address
validator_address_evm = public_address.lower()
if not validator_address_evm.startswith("0x"):
validator_address_evm = "0x" + validator_address_evm

# Get validator data
graphql_stats = fetch_single_validator(validator_address)
graphql_stats = fetch_single_validator(validator_address_evm)

blocks_data = graphql_stats.get("data", {}).get("blocks", [])
if not blocks_data:
Expand Down Expand Up @@ -1169,7 +1173,7 @@ def get_fn_stats(output):
your_delegation_rewards = delegation_info.get("reward", 0)
fn_info["Pending Rewards"] = f"{findora_gwei_convert(your_delegation_rewards):,.2f}"

return fn_info, validator_address
return fn_info, validator_address_evm, public_address


def menu_topper() -> None:
Expand All @@ -1180,7 +1184,7 @@ def menu_topper() -> None:
fra = findora_gwei_convert(curl_stats["result"]["validator_info"]["voting_power"])
our_version = get_container_version()
output = fetch_fn_show_output()
our_fn_stats, validator_address = get_fn_stats(output)
our_fn_stats, validator_address, public_address = get_fn_stats(output)
external_ip = config.our_external_ip
online_version = get_container_version(
f'https://{config.fra_env}-{environ.get("FRA_NETWORK")}.{config.fra_env}.findora.org:8668/version'
Expand Down Expand Up @@ -1249,7 +1253,7 @@ def menu_topper() -> None:
f"* CPU Load Averages: {round(Load1, 2)} over 1 min, {round(Load5, 2)} over 5 min, {round(Load15, 2)} over 15 min"
)
print_stars()
return update
return update, public_address


def rescue_menu() -> None:
Expand Down Expand Up @@ -1585,7 +1589,7 @@ def run_findora_menu() -> None:
0: finish_node,
1: get_curl_stats,
2: refresh_fn_stats,
3: claim_findora_rewards,
3: lambda: claim_findora_rewards(public_address),
4: pre_send_findora,
5: set_send_options,
6: change_validator_info,
Expand All @@ -1605,7 +1609,7 @@ def run_findora_menu() -> None:
# Keep this loop going so when an item ends the menu reloads
while True:
load_var_file(config.dotenv_file)
menu_findora()
public_address = menu_findora()
# Pick an option, any option
value = input("* Enter your option: ")
# Try/Catch - If it's not a number, goodbye, try again
Expand Down Expand Up @@ -1679,7 +1683,9 @@ def parse_flags(parser, region, network):
args = parser.parse_args()

if args.claim:
claim_findora_rewards()
output = fetch_fn_show_output()
our_fn_stats, validator_address, public_address = get_fn_stats(output)
claim_findora_rewards(public_address)
finish_node()

if args.installer:
Expand Down

0 comments on commit 71010f8

Please sign in to comment.