Skip to content

Commit 89ccff5

Browse files
authored
Include well-known PalletVersion storage function (#105)
1 parent 56af822 commit 89ccff5

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

scalecodec/types.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import warnings
1919
from datetime import datetime
2020
from hashlib import blake2b
21-
from typing import Union
21+
from typing import Union, Optional
2222

2323
from scalecodec.constants import TYPE_DECOMP_MAX_RECURSIVE
2424
from scalecodec.utils.ss58 import ss58_decode_account_index, ss58_decode, ss58_encode, is_valid_ss58_address
@@ -2451,18 +2451,28 @@ def get_identifier(self):
24512451
return self.value['name']
24522452

24532453
@property
2454-
def storage(self):
2454+
def storage(self) -> Optional[list]:
2455+
24552456
storage_functions = self.value_object['storage'].value_object
24562457

24572458
if storage_functions:
2458-
return storage_functions.value_object['entries'].value_object
2459+
pallet_version_sf = self.runtime_config.create_scale_object("StorageEntryMetadataV13")
2460+
pallet_version_sf.encode({
2461+
'name': ':__STORAGE_VERSION__:',
2462+
'modifier': 'Default',
2463+
'type': {'Plain': "u16"},
2464+
'default': '0x0000',
2465+
'documentation': ['Returns the current pallet version from storage']
2466+
})
2467+
2468+
return [pallet_version_sf] + storage_functions['entries'].elements
24592469

24602470
@property
24612471
def calls(self):
24622472
return self.value_object['calls'].value_object
24632473

24642474
@property
2465-
def events(self):
2475+
def events(self) -> Optional[list]:
24662476
events = self.value_object['events'].value_object
24672477

24682478
if events:
@@ -2477,10 +2487,13 @@ def errors(self):
24772487
return self.value_object['errors'].value_object
24782488

24792489
def get_storage_function(self, name: str):
2480-
storage_functions = self.value_object['storage'].value_object
2490+
if self.storage:
2491+
2492+
# Convert name for well-known PalletVersion storage entry
2493+
if name == 'PalletVersion':
2494+
name = ':__STORAGE_VERSION__:'
24812495

2482-
if storage_functions.value_object:
2483-
for storage_function in storage_functions['entries']:
2496+
for storage_function in self.storage:
24842497
if storage_function.value['name'] == name:
24852498
return storage_function
24862499

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
# 3 - Alpha
126126
# 4 - Beta
127127
# 5 - Production/Stable
128-
'Development Status :: 4 - Beta',
128+
'Development Status :: 5 - Production/Stable',
129129

130130
# Indicate who your project is intended for
131131
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)