Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
runtime_storage.save(self.db_session)
if len(module.constants or []) > 0:
for idx, constant in enumerate(module.constants):
# Decode value
try:
value_obj = ScaleDecoder.get_decoder_class(
constant.type,
ScaleBytes(constant.constant_value)
)
value_obj.decode()
value = value_obj.serialize()
except ValueError:
value = constant.constant_value
except RemainingScaleBytesNotEmptyException:
value = constant.constant_value
except NotImplementedError:
value = constant.constant_value
if type(value) is list or type(value) is dict:
value = json.dumps(value)
runtime_constant = RuntimeConstant(
spec_version=spec_version,
module_id=module_id,
index=idx,
name=constant.name,
type=constant.type,
value=value,
documentation='\n'.join(constant.docs)
)
def decode(self, check_remaining=True):
self.value = self.process()
if check_remaining and self.data.offset != self.data.length:
raise RemainingScaleBytesNotEmptyException('Current offset: {} / length: {}'.format(self.data.offset, self.data.length))
if self.data.offset > self.data.length:
raise RemainingScaleBytesNotEmptyException(
'No more bytes available (offset: {} / length: {})'.format(self.data.offset, self.data.length))
return self.value
module_id='staking',
name='CurrentEra',
spec_version=self.block.spec_version_id
).first()
if storage_call:
try:
current_era = substrate.get_storage(
block_hash=self.block.hash,
module="Staking",
function="CurrentEra",
return_scale_type=storage_call.get_return_type(),
hasher=storage_call.type_hasher,
metadata_version=SUBSTRATE_METADATA_VERSION
)
except RemainingScaleBytesNotEmptyException:
pass
# Retrieve validators for new session from storage
storage_call = RuntimeStorage.query(db_session).filter_by(
module_id='session',
name='Validators',
spec_version=self.block.spec_version_id
).first()
if storage_call:
try:
validators = substrate.get_storage(
block_hash=self.block.hash,
module="Session",
function="Validators",