Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_u16(self):
obj = ScaleDecoder.get_decoder_class('u16')
obj.encode(64302)
self.assertEqual(str(obj.data), "0x2efb")
return self.metadata.value
else:
# Fall back to version unaware legacy MetadataV0
self.data.reset()
self.metadata = self.process_type('MetadataV0Decoder')
# TODO remove duplicate reference?
self.call_index = self.metadata.call_index
self.event_index = self.metadata.event_index
return self.metadata.value
class MetadataV4Decoder(ScaleDecoder):
def __init__(self, data, sub_type=None):
self.version = None
self.modules = []
self.call_index = {}
self.event_index = {}
super().__init__(data, sub_type)
def process(self):
result_data = {
"magicNumber": 1635018093, # struct.unpack('
storage_key=xxh128(module.prefix.encode()) + xxh128(storage.name.encode()),
type_key1=type_key1,
type_key2=type_key2,
type_value=type_value,
type_is_linked=type_is_linked,
type_key2hasher=type_key2hasher,
documentation='\n'.join(storage.docs)
)
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(
self.call_index[call.lookup] = (module, call)
call_module_index += 1
if module.events is not None:
for event_index, event in enumerate(module.events):
event.lookup = "{:02x}{:02x}".format(event_module_index, event_index)
self.event_index[event.lookup] = (module, event)
event_module_index += 1
result_data["metadata"]["MetadataV11"]["modules"] = [m.value for m in self.modules]
result_data["metadata"]["MetadataV11"]["extrinsic"] = self.process_type("ExtrinsicMetadata").value
return result_data
class MetadataV3Decoder(ScaleDecoder):
def __init__(self, data, sub_type=None):
self.version = None
self.modules = []
self.call_index = {}
self.event_index = {}
super().__init__(data, sub_type)
def process(self):
result_data = {
"magicNumber": 1635018093, # struct.unpack('
def clear_type_registry(self):
self.type_registry = {'types': {cls.type_string.lower(): cls for cls in self.all_subclasses(ScaleDecoder) if
cls.type_string}}
self.type_registry['types'].update({cls.__name__.lower(): cls for cls in self.all_subclasses(ScaleDecoder)})
if name == '::Type':
return 'Compact'
if name == '::Type':
return 'Compact'
if name == '::Type':
return 'Compact'
if name == '::Inherent':
return 'InherentOfflineReport'
if name == 'RawAddress':
return 'Address'
return name
# TODO move type_string and sub_type behaviour to this sub class
class ScaleType(ScaleDecoder, ABC):
def __init__(self, data=None, sub_type=None, metadata=None):
self.metadata = metadata
if not data:
data = ScaleBytes(bytearray())
super().__init__(data, sub_type)
call.lookup = "{:02x}{:02x}".format(call_module_index, call_index)
self.call_index[call.lookup] = (module, call)
call_module_index += 1
if module.events is not None:
for event_index, event in enumerate(module.events):
event.lookup = "{:02x}{:02x}".format(event_module_index, event_index)
self.event_index[event.lookup] = (module, event)
event_module_index += 1
result_data["metadata"]["MetadataV2"]["modules"] = [m.value for m in self.modules]
return result_data
class MetadataV1Decoder(ScaleDecoder):
def __init__(self, data, sub_type=None):
self.version = None
self.modules = []
self.call_index = {}
self.event_index = {}
super().__init__(data, sub_type)
def process(self):
result_data = {
"magicNumber": 1635018093, # struct.unpack('
self.name = None
self.docs = []
super().__init__(data, sub_type, **kwargs)
def process(self):
self.name = self.process_type('Bytes').value
self.docs = self.process_type('Vec').value
return {
"name": self.name,
"docs": self.docs
}
class MetadataV9Decoder(ScaleDecoder):
def __init__(self, data, sub_type=None):
self.version = None
self.modules = []
self.call_index = {}
self.event_index = {}
super().__init__(data, sub_type)
def process(self):
result_data = {
"magicNumber": 1635018093, # struct.unpack('
}
self.fallback = self.process_type('HexBytes').value
self.docs = self.process_type('Vec').value
return {
"name": self.name,
"modifier": self.modifier,
"type": self.type,
"fallback": self.fallback,
"docs": self.docs
}
class MetadataV6Decoder(ScaleDecoder):
def __init__(self, data, sub_type=None):
self.version = None
self.modules = []
self.call_index = {}
self.event_index = {}
super().__init__(data, sub_type)
def process(self):
result_data = {
"magicNumber": 1635018093, # struct.unpack('
}
self.fallback = self.process_type('HexBytes').value
self.docs = self.process_type('Vec').value
return {
"name": self.name,
"modifier": self.modifier,
"type": self.type,
"fallback": self.fallback,
"docs": self.docs
}
class MetadataV5Decoder(ScaleDecoder):
def __init__(self, data, sub_type=None):
self.version = None
self.modules = []
self.call_index = {}
self.event_index = {}
super().__init__(data, sub_type)
def process(self):
result_data = {
"magicNumber": 1635018093, # struct.unpack('