Skip to content

Commit 6ad013f

Browse files
author
latentvector
committed
new staking refactor
1 parent 872cd3c commit 6ad013f

File tree

27 files changed

+143
-140
lines changed

27 files changed

+143
-140
lines changed

commune/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
from .module import Module
33
c = Block = Lego = M = Module # alias c.Module as c.Block, c.Lego, c.M
44
from .cli import cli
5+
from .vali.vali import Vali
6+
from .tree.tree import Tree
7+
from .client.client import Client
8+
from .server.server import Server
9+
from .namespace import Namespace
510
# import sys
611
# sys.path += [c.pwd()]
712

commune/client/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def test(self, module='module::test_client'):
389389

390390
info = c.call(module+'/info')
391391
key = c.get_key(module)
392-
assert info['ss58_address'] == key.ss58_address
392+
assert info['key'] == key.ss58_address
393393
return {'info': info, 'key': str(key)}
394394

395395
def __del__(self):

commune/key/key.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ key already exists at alice
1717
'943fb89150a67192919a43004f87685faba470e754fe4ff0af6a93e7fc54dc0a6cceb6fbc29d610d5486ba78969f609ea83753fb9e32d58df0c67f13
1818
dfcbbd68',
1919
'mnemonic': 'quantum belt rival casual benefit obscure sight wool pupil jaguar guide mango',
20-
'ss58_address': '5EtMr6n6APFay8FFdhhP9sMPwvv1Nfcm5yxiRTxviHH4WVZg'
20+
'key': '5EtMr6n6APFay8FFdhhP9sMPwvv1Nfcm5yxiRTxviHH4WVZg'
2121
}
2222
Now this generates a random key and if you want to save it to a file you can do so like this.
2323

@@ -43,7 +43,7 @@ c add_key alice
4343
c29d610d5486ba78969f609ea83753fb9e32d58df0c67f13dfcbbd68',
4444
'mnemonic': 'quantum belt rival casual benefit obscure sight wool
4545
pupil jaguar guide mango',
46-
'ss58_address': '5EtMr6n6APFay8FFdhhP9sMPwvv1Nfcm5yxiRTxviHH4WVZg'
46+
'key': '5EtMr6n6APFay8FFdhhP9sMPwvv1Nfcm5yxiRTxviHH4WVZg'
4747
}
4848

4949

commune/key/key.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self,
106106
private_key = key.__dict__.get('private_key', private_key)
107107
crypto_type = key.__dict__.get('crypto_type', crypto_type)
108108
derive_path = key.__dict__.get('derive_path', derive_path)
109-
ss58_address = key.__dict__.get('ss58_address', ss58_address)
109+
ss58_address = key.__dict__.get('key', ss58_address)
110110
path = key.__dict__.get('path', path)
111111
public_key = key.__dict__.get('public_key', public_key)
112112
ss58_format = key.__dict__.get('ss58_format', ss58_format)
@@ -316,7 +316,7 @@ def get_key(cls,
316316
if not cls.key_exists(path):
317317
if create_if_not_exists:
318318
key = cls.add_key(path, **kwargs)
319-
c.print(f'key does not exist, generating new key -> {key["ss58_address"]}')
319+
c.print(f'key does not exist, generating new key -> {key["key"]}')
320320
else:
321321
raise ValueError(f'key does not exist at --> {path}')
322322

@@ -547,7 +547,7 @@ def to_json(self, password: str = None ) -> dict:
547547
if password != None:
548548
state_dict[k] = self.encrypt(data=state_dict[k], password=password)
549549
if '_ss58_address' in state_dict:
550-
state_dict['ss58_address'] = state_dict.pop('_ss58_address')
550+
state_dict['key'] = state_dict.pop('_ss58_address')
551551
state_dict = json.dumps(state_dict)
552552

553553
return state_dict
@@ -562,8 +562,8 @@ def from_json(cls, obj: Union[str, dict], password: str = None) -> dict:
562562
for k,v in obj.items():
563563
if cls.is_encrypted(obj[k]) and password != None:
564564
obj[k] = cls.decrypt(data=obj[k], password=password)
565-
if 'ss58_address' in obj:
566-
obj['_ss58_address'] = obj.pop('ss58_address')
565+
if 'key' in obj:
566+
obj['_ss58_address'] = obj.pop('key')
567567
return cls(**obj)
568568

569569
@classmethod

commune/module/module.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,12 @@ def key(self):
122122
def key(self, key: 'Key'):
123123
self._key = c.get_key(key, create_if_not_exists=True)
124124
return self._key
125-
126125
@classmethod
127126
def call(cls, *args, **kwargs) -> None:
128127
return c.module('client').call( *args, **kwargs)
129-
130128
@classmethod
131129
async def async_call(cls, *args,**kwargs):
132130
return c.call(*args, **kwargs)
133-
134-
135131
@classmethod
136132
def call_search(cls,*args, **kwargs) -> None:
137133
return c.m('client').call_search(*args, **kwargs)
@@ -1407,10 +1403,15 @@ def search_dict(self, d:dict = 'k,d', search:str = {'k.d': 1}) -> dict:
14071403

14081404

14091405

1406+
@classmethod
1407+
def tree(cls, *args, **kwargs) -> List[str]:
1408+
return c.module('tree').tree(*args, **kwargs)
1409+
14101410
@classmethod
14111411
def tree(cls, *args, **kwargs) -> List[str]:
14121412
return c.module('tree').tree(*args, **kwargs)
14131413

1414+
14141415
@classmethod
14151416
def tree2path(cls, *args, **kwargs) -> List[str]:
14161417
return c.module('tree').tree2path( *args, **kwargs)
@@ -1466,10 +1467,13 @@ def simple2path(cls, path:str, **kwargs) -> str:
14661467

14671468
@classmethod
14681469
def simple2objectpath(cls, path:str,path2objectpath = {'tree': 'commune.tree.tree.Tree'}, **kwargs) -> str:
1470+
1471+
14691472
if path in path2objectpath:
14701473
object_path = path2objectpath[path]
14711474
else:
14721475
object_path = c.module('tree').simple2objectpath(path, **kwargs)
1476+
14731477
return object_path
14741478
@classmethod
14751479
def simple2object(cls, path:str, **kwargs) -> str:
@@ -1541,10 +1545,6 @@ def has_config(cls) -> bool:
15411545
@classmethod
15421546
def has_module(cls, module):
15431547
return module in c.modules()
1544-
1545-
@classmethod
1546-
def Vali(cls, *args, **kwargs):
1547-
return c.module('vali')
15481548

15491549
@classmethod
15501550
def tasks(cls, task = None, mode='pm2',**kwargs) -> List[str]:
@@ -2492,7 +2492,9 @@ def serve(cls,
24922492
'name': name,
24932493
'address':address,
24942494
'kwargs':kwargs
2495-
}
2495+
}
2496+
2497+
c.print(module, name)
24962498
module_class = c.module(module)
24972499

24982500
kwargs.update(extra_kwargs)
@@ -2584,7 +2586,7 @@ def dummy_gen(cls):
25842586
def info(self ,
25852587
module = None,
25862588
features = ['schema', 'namespace', 'commit_hash', 'hardware','attributes','functions'],
2587-
lite_features = ['name', 'address', 'schema', 'ss58_address', 'description'],
2589+
lite_features = ['name', 'address', 'schema', 'key', 'description'],
25882590
lite = True,
25892591
cost = False,
25902592
**kwargs
@@ -2619,8 +2621,8 @@ def info(self ,
26192621
info['path'] = self.module_path() # get the path of the module
26202622
if 'address' in features:
26212623
info['address'] = self.address.replace(c.default_ip, c.ip(update=False))
2622-
if 'ss58_address' in features:
2623-
info['ss58_address'] = self.key.ss58_address
2624+
if 'key' in features:
2625+
info['key'] = self.key.ss58_address
26242626
if 'code_hash' in features:
26252627
info['code_hash'] = self.chash() # get the hash of the module (code)
26262628
if 'commit_hash' in features:
@@ -3122,8 +3124,8 @@ def transfer_multiple(cls, *args, **kwargs):
31223124

31233125

31243126
@classmethod
3125-
def transfer_stake(cls, *args, **kwargs):
3126-
return c.module('subspace')().transfer_stake(*args, **kwargs)
3127+
def stake_transfer(cls, *args, **kwargs):
3128+
return c.module('subspace')().stake_transfer(*args, **kwargs)
31273129

31283130

31293131
@classmethod
@@ -7012,7 +7014,7 @@ def load_ticket(self, key=None, **kwargs):
70127014
@classmethod
70137015
def verify_ticket(cls, *args, **kwargs):
70147016

7015-
return c.get_key().verify_ticket(*args, **kwargs)
7017+
return c.module('ticket').verify_ticket(*args, **kwargs)
70167018

70177019
@classmethod
70187020
def load_style(cls):

commune/namespace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def add_servers(cls, *servers, network:str='local', **kwargs):
258258
return responses
259259

260260
@classmethod
261-
def infos(cls, search=None, network=network, servers=None, features=['ss58_address', 'address', 'name'], update:str=True, batch_size = 10, timeout=20, hardware=True, namespace=True, schema=True) -> List[str]:
261+
def infos(cls, search=None, network=network, servers=None, features=['key', 'address', 'name'], update:str=True, batch_size = 10, timeout=20, hardware=True, namespace=True, schema=True) -> List[str]:
262262
path = f'infos/{network}'
263263
if not update:
264264
infos = cls.get(path, [])

commune/remote/peer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ def n_servers(self):
191191
@classmethod
192192
def peer2key(cls, search=None, network:str='remote', update=False):
193193
infos = c.infos(search=search, network=network, update=update)
194-
return {v['name']:v['ss58_address'] for v in infos if 'name' in v and 'address' in v}
194+
return {v['name']:v['key'] for v in infos if 'name' in v and 'address' in v}
195195

196196
@classmethod
197197
def peer_addresses(cls, network:str='remote'):
198198
infos = c.infos(network=network)
199-
return {info['ss58_address'] for info in infos if 'ss58_address' in info}
199+
return {info['key'] for info in infos if 'key' in info}
200200

201201
def check_peers(self, timeout=10):
202202
futures = []
@@ -266,7 +266,7 @@ def addresses(self, search=None, network='remote'):
266266
return c.addresses(search=search, network=network)
267267

268268
def keys(self):
269-
return [info.get('ss58_address', None)for info in self.infos()]
269+
return [info.get('key', None)for info in self.infos()]
270270

271271
@classmethod
272272
def infos(self, search='module', network='remote', update=False):

commune/server/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_serving_with_different_key(cls, module_name = 'storage::test', key_name
4343
module = c.connect(module_name)
4444
info = module.info()
4545

46-
assert info['ss58_address'] == key.ss58_address, f"key failed {key.ss58_address} != {info['ss58_address']}"
46+
assert info['key'] == key.ss58_address, f"key failed {key.ss58_address} != {info['key']}"
4747
c.kill(module_name)
4848

4949
c.rm_key(key_name)

commune/subspace/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def get_state():
382382
# st.write(self.state['stake_to'][self.netuid])
383383
stake_to = self.state['stake_to'][self.netuid].get(self.key.ss58_address)
384384
self.key_info = {
385-
'ss58_address': self.key.ss58_address,
385+
'key': self.key.ss58_address,
386386
'balance': self.state['balances'].get(self.key.ss58_address,0),
387387
'stake_to': self.state['stake_to'][self.netuid].get(self.key.ss58_address,{}),
388388
'stake': sum([v[1] for v in stake_to]) if stake_to != None else {},

0 commit comments

Comments
 (0)