diff --git a/gateway/utils.py b/gateway/utils.py index f81b8a6942225ae5ae699bc034dd18cacd1cde0b..c3d2d22c563c6d8e435073fcf0f54acd9ceca450 100644 --- a/gateway/utils.py +++ b/gateway/utils.py @@ -36,3 +36,20 @@ def hex32bytes_string(some_hex32bytes): return Web3.toText(some_hex32bytes.decode().strip('\\\u0000')) except UnicodeDecodeError as ude: return some_hex32bytes + + +class HexBytesToDict: + def dehex_dict(self, dictionary): + for k, v in dictionary.items(): + if isinstance(v, dict): + self.dehex_dict(dictionary[k]) + elif isinstance(v, list): + self.dehex_list(dictionary[k]) + elif isinstance(v, HexBytes): + dictionary[k] = v.hex() + + def dehex_list(self, sequence): + i = 0 + while i < len(sequence): + sequence[i] = sequence[i].decode() + i = i + 1