Testers wanted for an Autonomi app demo

whats the address my good sir iv not got much but its yours :slight_smile:

1 Like

also please add @riddim to this group he has a collection going for you as well :slight_smile:

2 Likes

He’s been in touch. This is very generous of you both, and very helpful while nanos are scarce.

I have 140 of my own and will post an address when I have the app ready and have figured it how to gather my nanos.

For you and @riddim use a script?

Thanks again!

I made a buggy script @riddim made a better one I think after skim reading another thread sure he will post it here shortly :slight_smile:

Not better - just the same as you in python - and if one hits ctrl +c it might break everything… Better to use your script @aatonnomicc

I lost nanos :wink: because it destroyed a wallet containing coin

1 Like

ok think I was hoping you made a better one lol

@happybeing change the ReceiveingAddress to the wallet address you want to deposit into and it should spit you out a copy past for depositing the coins

it also throws an error if there are no nanos at the last send to the central wallet

its ruff as but sure you can get the idea.

also if your central wallet is on the same pc as nodes it will send the nanos to itself at the end and must be deposited back into itself.

#!/bin/bash

#run with bash <(curl -s http://safe-logs.ddns.net/scrip/scrape.sh)bash

ReceiveingAddress="b2cb192127e60b6e2add0f9998ed64d2863dd89f8ee28f61415770245919681627dd9361f0a711c65e6ca9e255740459"

# Environment setup
export PATH=$PATH:$HOME/.local/bin
base_dir="/var/safenode-manager/services"

safe wallet address

wallet_address=$(safe wallet address | awk 'NR==3{print $1}')

echo "$wallet_address"

# Process nodes
for dir in "$base_dir"/*; do
    if [[ -f "$dir/safenode.pid" ]]; then
        dir_name=$(basename "$dir")
        node_number=${dir_name#safenode}
        rewards_balance=$(safe wallet balance --peer-id /var/safenode-manager/services/safenode$node_number | awk 'NR==3{print $7}')

                echo ""
                echo "$dir_name"
                echo "$rewards_balance"
                echo ""
                                echo ""

        if (( $(echo "$rewards_balance > 0.000000000" |bc -l) )); then
                echo "has nanos"

                                #move wallets to initiate a transfer
                                #sudo env "PATH=$PATH" safenode-manager stop --service-name "$dir_name"
                                sudo systemctl stop "$dir_name"
                                mv $HOME/.local/share/safe/client/wallet $HOME/.local/share/safe/client/wallet-backup
                                sudo mv /var/safenode-manager/services/safenode$node_number/wallet/ $HOME/.local/share/safe/client/
                                sudo chown -R "$USER":"$USER" $HOME/.local/share/safe/client/wallet

                                node_balance=$(safe wallet balance | awk 'NR==3{print $1}')
                                echo ""
                                echo " node wallet transfered balance:$node_balance"
                                echo ""

                                #send rewards from node wallet to main wallet address
                                deposit=$(safe wallet send $node_balance $wallet_address | awk 'NR==10{print $1}')
                                echo ""
                                echo "$deposit"
                                echo ""

                                #move wallets back to original location
                                sudo mv $HOME/.local/share/safe/client/wallet /var/safenode-manager/services/safenode$node_number/
                                mv $HOME/.local/share/safe/client/wallet-backup $HOME/.local/share/safe/client/wallet
                                sudo chown -R safe:safe /var/safenode-manager/services/safenode$node_number/wallet
                                #sudo env "PATH=$PATH" safenode-manager start --service-name "$dir_name"
                                sudo systemctl start "$dir_name"

                                safe wallet receive "$deposit"
                                safe wallet balance

                fi
    fi
done

client_balance=$(safe wallet balance | awk 'NR==3{print $1}')

echo ""
echo "######################################################################"
echo "#                                                                    #"
echo "#            New wallet balance $client_balance                          #"
echo "#                                                                    #"
echo "######################################################################"
echo ""
echo ""
echo ""
echo ""
deposit=$(safe wallet send $client_balance $ReceiveingAddress | awk 'NR==10{print $1}')
echo
echo
echo
echo "safe wallet receive $deposit"
echo
echo
echo

3 Likes

Well If I don’t mess this up it will be a miracle, but miracles is what we do here isn’t it :wink:, so…

no problem!

Thanks. :slightly_smiling_face:

3 Likes

There are deals being done to get you funds :wink:

2 Likes

Awesome!

All this and I haven’t even asked. It’s wonderful.

:+1:

3 Likes

Yep count me in.

2 Likes

here the alternative python implementation … might be a bit more verbose (with logging into files) and no errors thrown (except on error probably) … i removed the part that could mess up everything … so if it fails … it just fails and can be repaired …

same systematics - input the main wallet address into ReceivingAddress and fire (obviously as sudo/root since services get stopped and stuff)

import os
import re
import shutil
import subprocess
import sys
from datetime import datetime
from typing import List, Optional

# Define paths for log and error files
log_dir: str = "/var/log/nano_collector"
failed_deposits_file: str = os.path.join(log_dir, "failed_deposits.txt")
final_deposits_log: str = os.path.join(log_dir, "final_deposits.log")

# Ensure the log directory exists
os.makedirs(log_dir, exist_ok=True)

def run_command(command: str) -> str:
    """Executes a shell command and returns the output as a string."""
    result = subprocess.run(command, shell=True, capture_output=True, text=True)
    return result.stdout.strip()

def extract_address(output: str) -> Optional[str]:
    """Extracts a wallet address from the command output."""
    match = re.search(r'^(?P<address>[a-fA-F0-9]{64})$', output, re.MULTILINE)
    return match.group('address') if match else None

def extract_balance_main_wallet(output: str) -> Optional[str]:
    """Extracts a wallet balance from the command output."""
    match = re.search(r'^(?P<balance>[0-9.]+)$', output, re.MULTILINE)
    return match.group('balance') if match else None

def extract_balance(output: str) -> Optional[str]:
    """Extracts a wallet balance from the command output."""
    match = re.search(r'Node\'s rewards wallet balance.*: (?P<balance>[0-9.]+)', output)
    return match.group('balance') if match else None

def extract_deposit(output: str) -> Optional[str]:
    """Extracts the receive string from the 'safe wallet send' command output."""
    match = re.search(r'Please share this to the recipient:\n\n(?P<deposit>[a-fA-F0-9]+)', output)
    return match.group('deposit') if match else None

def log_final_deposit(deposit: str, status: str) -> None:
    """Logs the final deposit with a timestamp and status."""
    with open(final_deposits_log, "a") as log:
        log.write(f"{datetime.now()} - Deposit: {deposit} - Status: {status}\n")

def save_failed_deposit(deposit: str) -> None:
    """Saves failed deposits for later transmission."""
    with open(failed_deposits_file, "a") as f:
        f.write(f"{deposit}\n")

def collect_earnings(receiving_address: str) -> None:
    """Collects earnings from nodes and transfers them to a main address."""

    # Path to the Safenode manager service directory
    base_dir: str = "/var/safenode-manager/services"

    print(f"Wallet Address: {receiving_address}")

    for dir_name in sorted(os.listdir(base_dir)):
        dir_full_path: str = os.path.join(base_dir, dir_name)
        if os.path.isfile(os.path.join(dir_full_path, "safenode.pid")):
            node_number: str = dir_name.replace("safenode", "")

            # Query node balance
            rewards_balance_output: str = run_command(f"safe wallet balance --peer-id {dir_full_path}")
            rewards_balance: Optional[str] = extract_balance(rewards_balance_output)

            print(f"\n{dir_name}\nBalance: {rewards_balance}\n")

            if rewards_balance and float(rewards_balance) > 0:
                print("Has nanos")

                # Stop the node service
                subprocess.run(f"sudo systemctl stop {dir_name}", shell=True)

                wallet_backup_path: str = os.path.expanduser(
                    "~/.local/share/safe/client/wallet-backup")

                shutil.move(os.path.expanduser("~/.local/share/safe/client/wallet"),
                            wallet_backup_path)
                shutil.move(f"{dir_full_path}/wallet/", os.path.expanduser("~/.local/share/safe/client/wallet"))

                shutil.chown(os.path.expanduser("~/.local/share/safe/client/wallet"), user=os.getlogin(), group=os.getlogin())

                # Query node wallet balance
                node_balance_output: str = run_command("safe wallet balance")
                node_balance: Optional[str] = extract_balance_main_wallet(node_balance_output)

                print(f"\nNode wallet transferred balance: {node_balance}\n")

                # Send node earnings to the main wallet
                deposit_output: str = run_command(f"safe wallet send {node_balance} {receiving_address}")
                deposit: Optional[str] = extract_deposit(deposit_output)

                print(f"\nDeposit: {deposit}\n")

                # Move wallets back
                shutil.move(os.path.expanduser("~/.local/share/safe/client/wallet"), f"{dir_full_path}/wallet/")
                shutil.move(wallet_backup_path,
                            os.path.expanduser("~/.local/share/safe/client/wallet"))

                shutil.chown(f"{dir_full_path}/wallet", user=os.getlogin(), group=os.getlogin())
                shutil.chown(os.path.expanduser("~/.local/share/safe/client/wallet"), user="safe", group="safe")

                subprocess.run(f"sudo systemctl restart {dir_name}", shell=True)

                # Execute "safe wallet receive"
                result = subprocess.run(f"safe wallet receive {deposit}", shell=True, capture_output=True,
                                        text=True)

                if result.returncode != 0:
                    save_failed_deposit(deposit)
                    log_final_deposit(deposit, "Failed to receive")
                else:
                    print(f'Successfully received {node_balance} from {dir_name}')


# Define the main wallet address here
ReceivingAddress: str = "a51117c1388c3b76b89ab64a66d95204a5edad87b74fd87cd1f34ab167326215087e580e807132d20db34b4f4e58ff44"

# Collect earnings
collect_earnings(ReceivingAddress)

2 Likes

@aatonnomicc is the hero who came up with the idea and is managing it :smiley:

2 Likes

its for a good cause :slight_smile:

2 Likes