예제 #1
0
    def __str__(self):
        def format(name: str, value: str) -> str:
            output = f"{name}: "
            if value is None:
                output += "Unknown"
            else:
                output += f"{value}"
            output += "\n"
            return output

        output = format("Farming status", self.status)
        output += format("Total chia farmed", self.total_chia_farmed)
        output += format("User transaction fees", self.user_transaction_fees)
        output += format("Block rewards", self.block_rewards)
        output += format("Last height farmed", self.last_height_farmed)
        output += format("Plot count", self.plot_count)

        output += "Total size of plots: "
        if self.total_plot_size is None:
            output += "Unknown"
        else:
            plots_space_human_readable = self.total_plot_size / 1024**3
            unit = "GiB"
            if plots_space_human_readable >= 1024**2:
                plots_space_human_readable = plots_space_human_readable / (1024
                                                                           **2)
                unit = "PiB"
            elif plots_space_human_readable >= 1024:
                plots_space_human_readable = plots_space_human_readable / 1024
                unit = "TiB"
            output += f"{plots_space_human_readable:.3f} {unit}"
        output += "\n"

        output += "Estimated network space: "
        if self.estimated_network_space is None:
            output += "Unknown"
        else:
            unit = "TiB"
            network_space_human_readable = self.estimated_network_space / 1024**4
            if network_space_human_readable >= 1024:
                network_space_human_readable = network_space_human_readable / 1024
                unit = "PiB"
            output += f"{network_space_human_readable:.3f} {unit}"
        output += "\n"

        output += "Expected time to win: " + format_minutes(
            self.expected_time_to_win) + "\n"
        output += "Note: log into your key using 'chia wallet show' to see rewards for each key"
        return output
예제 #2
0
async def summary(rpc_port: int, wallet_rpc_port: int, harvester_rpc_port: int,
                  farmer_rpc_port: int) -> None:
    amounts = await get_wallets_stats(wallet_rpc_port)
    plots = await get_plots(harvester_rpc_port)
    blockchain_state = await get_blockchain_state(rpc_port)
    farmer_running = await is_farmer_running(farmer_rpc_port)

    print("Farming status: ", end="")
    if blockchain_state is None:
        print("Not available")
    elif blockchain_state["sync"]["sync_mode"]:
        print("Syncing")
    elif not blockchain_state["sync"]["synced"]:
        print("Not synced or not connected to peers")
    elif not farmer_running:
        print("Not running")
    else:
        print("Farming")

    if amounts is not None:
        print(f"Total chia farmed: {amounts['farmed_amount'] / units['chia']}")
        print(
            f"User transaction fees: {amounts['fee_amount'] / units['chia']}")
        print(
            f"Block rewards: {(amounts['farmer_reward_amount'] + amounts['pool_reward_amount']) / units['chia']}"
        )
        print(f"Last height farmed: {amounts['last_height_farmed']}")
    else:
        print("Total chia farmed: Unknown")
        print("User transaction fees: Unknown")
        print("Block rewards: Unknown")
        print("Last height farmed: Unknown")

    total_plot_size = 0
    if plots is not None:
        total_plot_size = sum(map(lambda x: x["file_size"], plots["plots"]))

        print(f"Plot count: {len(plots['plots'])}")

        print("Total size of plots: ", end="")
        plots_space_human_readable = total_plot_size / 1024**3
        if plots_space_human_readable >= 1024**2:
            plots_space_human_readable = plots_space_human_readable / (1024**2)
            print(f"{plots_space_human_readable:.3f} PiB")
        elif plots_space_human_readable >= 1024:
            plots_space_human_readable = plots_space_human_readable / 1024
            print(f"{plots_space_human_readable:.3f} TiB")
        else:
            print(f"{plots_space_human_readable:.3f} GiB")
    else:
        print("Plot count: Unknown")
        print("Total size of plots: Unknown")

    if blockchain_state is not None:
        print("Estimated network space: ", end="")
        network_space_human_readable = blockchain_state["space"] / 1024**4
        if network_space_human_readable >= 1024:
            network_space_human_readable = network_space_human_readable / 1024
            print(f"{network_space_human_readable:.3f} PiB")
        else:
            print(f"{network_space_human_readable:.3f} TiB")
    else:
        print("Estimated network space: Unknown")

    minutes = -1
    if blockchain_state is not None and plots is not None:
        proportion = total_plot_size / blockchain_state[
            "space"] if blockchain_state["space"] else -1
        minutes = int((await get_average_block_time(rpc_port) / 60) /
                      proportion) if proportion else -1
    print("Expected time to win: " + format_minutes(minutes))
    print(
        "Note: log into your key using 'chia wallet show' to see rewards for each key"
    )
예제 #3
0
 async def test_format_minutes(self):
     assert format_minutes(None) == "Invalid"
     assert format_minutes(dict()) == "Invalid"
     assert format_minutes("some minutes") == "Invalid"
     assert format_minutes(-1) == "Unknown"
     assert format_minutes(0) == "Now"
     assert format_minutes(1) == "1 minute"
     assert format_minutes(59) == "59 minutes"
     assert format_minutes(60) == "1 hour"
     assert format_minutes(61) == "1 hour and 1 minute"
     assert format_minutes(119) == "1 hour and 59 minutes"
     assert format_minutes(1380) == "23 hours"
     assert format_minutes(1440) == "1 day"
     assert format_minutes(2160) == "1 day and 12 hours"
     assert format_minutes(8640) == "6 days"
     assert format_minutes(10080) == "1 week"
     assert format_minutes(20160) == "2 weeks"
     assert format_minutes(40240) == "3 weeks and 6 days"
     assert format_minutes(40340) == "4 weeks"
     assert format_minutes(43800) == "1 month"
     assert format_minutes(102000) == "2 months and 1 week"
     assert format_minutes(481800) == "11 months"
     assert format_minutes(525600) == "1 year"
     assert format_minutes(1007400) == "1 year and 11 months"
     assert format_minutes(5256000) == "10 years"
예제 #4
0
async def summary(
    rpc_port: Optional[int],
    wallet_rpc_port: Optional[int],
    harvester_rpc_port: Optional[int],
    farmer_rpc_port: Optional[int],
) -> None:
    all_harvesters = await get_harvesters(farmer_rpc_port)
    blockchain_state = await get_blockchain_state(rpc_port)
    farmer_running = await is_farmer_running(farmer_rpc_port)

    wallet_not_ready: bool = False
    wallet_not_running: bool = False
    amounts = None
    try:
        amounts = await get_wallets_stats(wallet_rpc_port)
    except Exception as e:
        if isinstance(e, aiohttp.ClientConnectorError):
            wallet_not_running = True
        else:
            wallet_not_ready = True

    print("Farming status: ", end="")
    if blockchain_state is None:
        print("Not available")
    elif blockchain_state["sync"]["sync_mode"]:
        print("Syncing")
    elif not blockchain_state["sync"]["synced"]:
        print("Not synced or not connected to peers")
    elif not farmer_running:
        print("Not running")
    else:
        print("Farming")

    if amounts is not None:
        print(f"Total chia farmed: {amounts['farmed_amount'] / units['chia']}")
        print(
            f"User transaction fees: {amounts['fee_amount'] / units['chia']}")
        print(
            f"Block rewards: {(amounts['farmer_reward_amount'] + amounts['pool_reward_amount']) / units['chia']}"
        )
        print(f"Last height farmed: {amounts['last_height_farmed']}")

    class PlotStats:
        total_plot_size = 0
        total_plots = 0

    if all_harvesters is not None:
        harvesters_local: dict = {}
        harvesters_remote: dict = {}
        for harvester in all_harvesters["harvesters"]:
            ip = harvester["connection"]["host"]
            if is_localhost(ip):
                harvesters_local[harvester["connection"]
                                 ["node_id"]] = harvester
            else:
                if ip not in harvesters_remote:
                    harvesters_remote[ip] = {}
                harvesters_remote[ip][harvester["connection"]
                                      ["node_id"]] = harvester

        def process_harvesters(harvester_peers_in: dict):
            for harvester_peer_id, plots in harvester_peers_in.items():
                total_plot_size_harvester = sum(
                    map(lambda x: x["file_size"], plots["plots"]))
                PlotStats.total_plot_size += total_plot_size_harvester
                PlotStats.total_plots += len(plots["plots"])
                print(
                    f"   {len(plots['plots'])} plots of size: {format_bytes(total_plot_size_harvester)}"
                )

        if len(harvesters_local) > 0:
            print(f"Local Harvester{'s' if len(harvesters_local) > 1 else ''}")
            process_harvesters(harvesters_local)
        for harvester_ip, harvester_peers in harvesters_remote.items():
            print(
                f"Remote Harvester{'s' if len(harvester_peers) > 1 else ''} for IP: {harvester_ip}"
            )
            process_harvesters(harvester_peers)

        print(f"Plot count for all harvesters: {PlotStats.total_plots}")

        print("Total size of plots: ", end="")
        print(format_bytes(PlotStats.total_plot_size))
    else:
        print("Plot count: Unknown")
        print("Total size of plots: Unknown")

    if blockchain_state is not None:
        print("Estimated network space: ", end="")
        print(format_bytes(blockchain_state["space"]))
    else:
        print("Estimated network space: Unknown")

    minutes = -1
    if blockchain_state is not None and all_harvesters is not None:
        proportion = PlotStats.total_plot_size / blockchain_state[
            "space"] if blockchain_state["space"] else -1
        minutes = int((await get_average_block_time(rpc_port) / 60) /
                      proportion) if proportion else -1

    if all_harvesters is not None and PlotStats.total_plots == 0:
        print("Expected time to win: Never (no plots)")
    else:
        print("Expected time to win: " + format_minutes(minutes))

    if amounts is None:
        if wallet_not_running:
            print(
                "For details on farmed rewards and fees you should run 'chia start wallet' and 'chia wallet show'"
            )
        elif wallet_not_ready:
            print(
                "For details on farmed rewards and fees you should run 'chia wallet show'"
            )
    else:
        print(
            "Note: log into your key using 'chia wallet show' to see rewards for each key"
        )
예제 #5
0
async def summary(rpc_port: int, wallet_rpc_port: int, harvester_rpc_port: int, farmer_rpc_port: int) -> None:
    all_plots = await get_plots(farmer_rpc_port)
    blockchain_state = await get_blockchain_state(rpc_port)
    farmer_running = await is_farmer_running(farmer_rpc_port)

    wallet_not_ready: bool = False
    wallet_not_running: bool = False
    amounts = None
    try:
        amounts = await get_wallets_stats(wallet_rpc_port)
    except Exception as e:
        if isinstance(e, aiohttp.ClientConnectorError):
            wallet_not_running = True
        else:
            wallet_not_ready = True

    print("Farming status: ", end="")
    if blockchain_state is None:
        print("Not available")
    elif blockchain_state["sync"]["sync_mode"]:
        print("Syncing")
    elif not blockchain_state["sync"]["synced"]:
        print("Not synced or not connected to peers")
    elif not farmer_running:
        print("Not running")
    else:
        print("Farming")

    if amounts is not None:
        print(f"Total chia farmed: {amounts['farmed_amount'] / units['chia']}")
        print(f"User transaction fees: {amounts['fee_amount'] / units['chia']}")
        print(f"Block rewards: {(amounts['farmer_reward_amount'] + amounts['pool_reward_amount']) / units['chia']}")
        print(f"Last height farmed: {amounts['last_height_farmed']}")

    total_plot_size = 0
    total_plots = 0
    if all_plots is not None:
        for harvester_ip, plots in all_plots.items():
            if harvester_ip == "success":
                # This key is just "success": True
                continue
            total_plot_size_harvester = sum(map(lambda x: x["file_size"], plots["plots"]))
            total_plot_size += total_plot_size_harvester
            total_plots += len(plots["plots"])
            print(f"Harvester {harvester_ip}:")
            print(f"   {len(plots['plots'])} plots of size: {format_bytes(total_plot_size_harvester)}")

        print(f"Plot count for all harvesters: {total_plots}")

        print("Total size of plots: ", end="")
        print(format_bytes(total_plot_size))
    else:
        print("Plot count: Unknown")
        print("Total size of plots: Unknown")

    if blockchain_state is not None:
        print("Estimated network space: ", end="")
        print(format_bytes(blockchain_state["space"]))
    else:
        print("Estimated network space: Unknown")

    minutes = -1
    if blockchain_state is not None and all_plots is not None:
        proportion = total_plot_size / blockchain_state["space"] if blockchain_state["space"] else -1
        minutes = int((await get_average_block_time(rpc_port) / 60) / proportion) if proportion else -1

    if all_plots is not None and total_plots == 0:
        print("Expected time to win: Never (no plots)")
    else:
        print("Expected time to win: " + format_minutes(minutes))

    if amounts is None:
        if wallet_not_running:
            print("For details on farmed rewards and fees you should run 'chia start wallet' and 'chia wallet show'")
        elif wallet_not_ready:
            print("For details on farmed rewards and fees you should run 'chia wallet show'")
    else:
        print("Note: log into your key using 'chia wallet show' to see rewards for each key")