Spaces:
Configuration error
Configuration error
| import bittensor as bt | |
| import json | |
| subtensor = bt.subtensor(network = "ws://80.209.241.45:9944") | |
| bt.logging.info("Connected to subtensor") | |
| # stake = subtensor.get_stake(hotkey_ss58="") | |
| def get_miner_uids(metagraph: bt.metagraph) -> list: | |
| miner_uids = [] | |
| for i, axon in enumerate(metagraph.axons): | |
| v_trust = metagraph.validator_trust[i].item() | |
| if v_trust > 0.0: | |
| continue | |
| miner_uids.append((i, metagraph.incentive[i].item())) | |
| # sort miner_uids by incentive | |
| miner_uids = sorted(miner_uids, key=lambda x: x[1], reverse=True) | |
| return miner_uids | |
| def validator_info(): | |
| metagraph = subtensor.metagraph(netuid = 6) | |
| all_weights = subtensor.weights(netuid=6) | |
| axons = metagraph.axons | |
| weight_list = [] | |
| for validator_uid, weights in all_weights: | |
| total_weight = sum([weight for validator_uid, weight in weights]) | |
| validator_stake = metagraph.stake[validator_uid].item() | |
| vtrust = metagraph.validator_trust[validator_uid].item() | |
| temp_list = {} | |
| for miner_uid, weight in weights: | |
| # temp_list.append((miner_uid, weight/total_weight * validator_stake)) | |
| temp_list[miner_uid] = weight/total_weight | |
| weight_list.append({'uid': validator_uid, 'miners_weight': temp_list, 'validator_stake': int(validator_stake), 'vtrust': vtrust}) | |
| # weight_list[validator_uid] = {'miners_weight': temp_list, 'validator_stake': validator_stake, 'vtrust': vtrust} | |
| # Sort weight_list by validator_stake | |
| weight_list = sorted(weight_list, key=lambda x: x['validator_stake'], reverse=True) | |
| bt.logging.info(f"weights:{weight_list}") | |
| miners = get_miner_uids(metagraph) | |
| return weight_list, miners | |
| # print(miners_sorted_by_incentive) | |