Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class VecQueuedKeys(Vec):
type_string = 'Vec<(ValidatorId, Keys)>'
def process(self):
element_count = self.process_type('Compact').value
result = []
for _ in range(0, element_count):
element = self.process_type('QueuedKeys')
self.elements.append(element)
result.append(element.value)
return result
class Conviction(Enum):
CONVICTION_MASK = 0b01111111
DEFAULT_CONVICTION = 0b00000000
value_list = ['None', 'Locked1x', 'Locked2x', 'Locked3x', 'Locked4x', 'Locked5x', 'Locked6x']
class GenericBlock(ScaleType):
# TODO implement generic block type
def process(self):
raise NotImplementedError()
def process_encode(self, value):
raise NotImplementedError()
class Null(ScaleType):
def process(self):
return None
def process_encode(self, value):
return ScaleBytes(bytearray())
class InherentOfflineReport(Null):
pass
class StorageHasher(Enum):
value_list = ['Blake2_128', 'Blake2_256', 'Blake2_128Concat', 'Twox128', 'Twox256', 'Twox64Concat', 'Identity']
def is_blake2_128(self):
return self.index == 0
def is_blake2_256(self):
return self.index == 1
def is_twoblake2_128_concat(self):
return self.index == 2
def is_twox128(self):
return self.index == 3
def is_twox256(self):
type_mapping = (('engine', 'ConsensusEngineId'), ('data', 'HexBytes'))
class Seal(Struct):
type_string = '(ConsensusEngineId, Bytes)'
type_mapping = (('engine', 'ConsensusEngineId'), ('data', 'HexBytes'))
class PreRuntime(Struct):
type_string = '(ConsensusEngineId, Bytes)'
type_mapping = (('engine', 'ConsensusEngineId'), ('data', 'HexBytes'))
class LogDigest(Enum):
value_list = ['Other', 'AuthoritiesChange', 'ChangesTrieRoot', 'SealV0', 'Consensus', 'Seal', 'PreRuntime']
def __init__(self, data, **kwargs):
self.log_type = None
self.index_value = None
super().__init__(data, **kwargs)
def process(self):
self.index = int(self.get_next_bytes(1).hex())
self.index_value = self.value_list[self.index]
self.log_type = self.process_type(self.value_list[self.index])
return {'type': self.log_type.type_string, 'value': self.log_type.value}
if item == value:
self.index = idx
return ScaleBytes(bytearray([self.index]))
raise ValueError("Value '{}' not present in value list of this enum".format(value))
def get_enum_value(self):
if self.value:
if self.type_mapping:
return list(self.value.values())[0]
else:
return self.value_list[self.index]
class Data(Enum):
type_mapping = [
["None", "Null"],
["Raw", "Bytes"],
["BlakeTwo256", "H256"],
["Sha256", "H256"],
["Keccak256", "H256"],
["ShaThree256", "H256"]
]
def process(self):
self.index = int(self.get_next_bytes(1).hex(), 16)
if self.index == 0:
return {'None': None}
def update_type_registry_types(self, types_dict):
from scalecodec.types import Enum, Struct, Set
for type_string, decoder_class_data in types_dict.items():
if type(decoder_class_data) == dict:
# Create dynamic decoder class
if decoder_class_data['type'] == 'struct':
decoder_class = type(type_string, (Struct,), {'type_mapping': decoder_class_data['type_mapping']})
elif decoder_class_data['type'] == 'enum':
decoder_class = type(type_string, (Enum,), {
'value_list': decoder_class_data.get('value_list'),
'type_mapping': decoder_class_data.get('type_mapping')
})
elif decoder_class_data['type'] == 'set':
decoder_class = type(type_string, (Set,), {
'value_list': decoder_class_data.get('value_list'),
'value_type': decoder_class_data.get('value_type', 'u64')
})
else:
raise NotImplementedError("Dynamic decoding type '{}' not supported".format(
decoder_class_data['type'])
)
else: