Skip to content

Commit

Permalink
Include well-known PalletVersion storage function (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanz authored Feb 21, 2023
1 parent 56af822 commit 89ccff5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions scalecodec/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import warnings
from datetime import datetime
from hashlib import blake2b
from typing import Union
from typing import Union, Optional

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

@property
def storage(self):
def storage(self) -> Optional[list]:

storage_functions = self.value_object['storage'].value_object

if storage_functions:
return storage_functions.value_object['entries'].value_object
pallet_version_sf = self.runtime_config.create_scale_object("StorageEntryMetadataV13")
pallet_version_sf.encode({
'name': ':__STORAGE_VERSION__:',
'modifier': 'Default',
'type': {'Plain': "u16"},
'default': '0x0000',
'documentation': ['Returns the current pallet version from storage']
})

return [pallet_version_sf] + storage_functions['entries'].elements

@property
def calls(self):
return self.value_object['calls'].value_object

@property
def events(self):
def events(self) -> Optional[list]:
events = self.value_object['events'].value_object

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

def get_storage_function(self, name: str):
storage_functions = self.value_object['storage'].value_object
if self.storage:

# Convert name for well-known PalletVersion storage entry
if name == 'PalletVersion':
name = ':__STORAGE_VERSION__:'

if storage_functions.value_object:
for storage_function in storage_functions['entries']:
for storage_function in self.storage:
if storage_function.value['name'] == name:
return storage_function

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',

# Indicate who your project is intended for
'Intended Audience :: Developers',
Expand Down

0 comments on commit 89ccff5

Please sign in to comment.