Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
xmr: serialize reimport removed
Browse files Browse the repository at this point in the history
- complex types are not surviving protocol boundary anymore, no need to fix hierarchy problems due to unimporting
  • Loading branch information
ph4r05 committed Oct 2, 2018
1 parent 3b04561 commit d5f43fa
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions src/apps/monero/xmr/serialize/xmrserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
>>> """
'''

import sys

from trezor import log

from apps.monero.xmr.serialize.base_types import IntType, UVarintType, XmrType
from apps.monero.xmr.serialize.erefs import eref, get_elem, set_elem
from apps.monero.xmr.serialize.int_serialize import (
Expand All @@ -54,18 +50,6 @@
)


def import_def(module, name):
if module not in sys.modules:
if not module.startswith("apps.monero"):
raise ValueError("Module not allowed: %s" % module)
if __debug__:
log.debug(__name__, "Importing: from %s import %s", module, name)
__import__(module, None, None, (name,), 0)

r = getattr(sys.modules[module], name)
return r


class Archive:
"""
Archive object for object binary serialization / deserialization.
Expand Down Expand Up @@ -255,7 +239,8 @@ def _get_type(self, elem_type):
if issubclass(elem_type, XmrType):
return elem_type

# Basic decision types
# Basic message types determined by the name.
# Due to unimport workflow the hierarchy linking may got lost.
etypes = (
UVarintType,
IntType,
Expand All @@ -270,31 +255,6 @@ def _get_type(self, elem_type):
if cname == e.__name__:
return e

# Inferred type: need to translate it to the current
try:
m = elem_type.__module__
r = import_def(m, cname)
sub_test = issubclass(r, XmrType)
if __debug__:
log.debug(
__name__,
"resolved %s, sub: %s, id_e: %s, id_mod: %s",
r,
sub_test,
id(r),
id(sys.modules[m]),
)
if not sub_test:
log.warning(__name__, "resolution hierarchy broken")

return r

except Exception as e:
raise ValueError(
"Could not translate elem type: %s %s, exc: %s %s"
% (type(elem_type), elem_type, type(e), e)
)

def _is_type(self, elem_type, test_type):
return issubclass(elem_type, test_type)

Expand Down

0 comments on commit d5f43fa

Please sign in to comment.