Edit on GitHub

communex.module.std.whitelist_validator

 1import time
 2
 3from substrateinterface import Keypair  # type: ignore
 4
 5from communex._common import get_node_url
 6from communex.client import CommuneClient
 7from communex.compat.key import classic_load_key
 8from communex.types import Ss58Address
 9
10# The netuid of the general subnet.
11GENERAL_NETUID = 0
12
13
14def keys_to_uids(keys: dict[int, Ss58Address], target_keys: list[Ss58Address]) -> list[int]:
15    return [k for k, v in keys.items() if v in target_keys]
16
17
18def validaiton(client: CommuneClient, key: Keypair):
19    # Query the modules, nominated by DAO.
20    keys = client.query_map_key(netuid=GENERAL_NETUID)
21    legit_whitelist = client.query_map(
22        "LegitWhitelist", params=[], extract_value=False)["LegitWhitelist"]
23    # TODO: test on production query, to verify the format, now I am going to assume it is a dict.
24    target_keys = list(legit_whitelist.keys())
25    uids_map = keys_to_uids(keys, target_keys)
26    # WIP, rigt now assuming same weights
27    weights = [1 for _ in uids_map]
28
29    client.vote(key, uids=uids_map, weights=weights, netuid=GENERAL_NETUID)
30
31
32def main(client: CommuneClient, key: Keypair,):
33    while True:
34        validaiton(client, key)
35        time.sleep(1200)
36
37
38if __name__ == "__main__":
39    client = CommuneClient(get_node_url())
40    key = classic_load_key("foo")
41    main(client, key)
GENERAL_NETUID = 0
def keys_to_uids( keys: dict[int, communex.types.Ss58Address], target_keys: list[communex.types.Ss58Address]) -> list[int]:
15def keys_to_uids(keys: dict[int, Ss58Address], target_keys: list[Ss58Address]) -> list[int]:
16    return [k for k, v in keys.items() if v in target_keys]
def validaiton( client: communex.client.CommuneClient, key: substrateinterface.keypair.Keypair):
19def validaiton(client: CommuneClient, key: Keypair):
20    # Query the modules, nominated by DAO.
21    keys = client.query_map_key(netuid=GENERAL_NETUID)
22    legit_whitelist = client.query_map(
23        "LegitWhitelist", params=[], extract_value=False)["LegitWhitelist"]
24    # TODO: test on production query, to verify the format, now I am going to assume it is a dict.
25    target_keys = list(legit_whitelist.keys())
26    uids_map = keys_to_uids(keys, target_keys)
27    # WIP, rigt now assuming same weights
28    weights = [1 for _ in uids_map]
29
30    client.vote(key, uids=uids_map, weights=weights, netuid=GENERAL_NETUID)
def main( client: communex.client.CommuneClient, key: substrateinterface.keypair.Keypair):
33def main(client: CommuneClient, key: Keypair,):
34    while True:
35        validaiton(client, key)
36        time.sleep(1200)