Skip to content

Commit

Permalink
xmr: tsx builder external state removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Sep 13, 2018
1 parent fee4a5a commit 0b175bc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 132 deletions.
65 changes: 2 additions & 63 deletions src/apps/monero/protocol/tsx_sign_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TTransactionBuilder:
STEP_MLSAG = const(600)
STEP_SIGN = const(700)

def __init__(self, iface=None, creds=None, state=None, **kwargs):
def __init__(self, iface=None, creds=None):
self.iface = iface
self.creds = creds
self.key_master = None
Expand Down Expand Up @@ -78,11 +78,7 @@ def __init__(self, iface=None, creds=None, state=None, **kwargs):
self.full_message_hasher = None
self.full_message = None
self.exp_tx_prefix_hash = None

if state is None:
self._init()
else:
self.state_load(state)
self._init()

def _init(self):
from apps.monero.xmr.sub.keccak_hasher import KeccakXmrArchive
Expand All @@ -94,63 +90,6 @@ def _init(self):
self.tx_prefix_hasher = KeccakXmrArchive()
self.full_message_hasher = PreMlsagHasher()

def state_load(self, t):
from apps.monero.protocol.tsx_sign_state import TState

self._mem_trace("Restore: %s" % str(t.state) if __debug__ else None, True)

for attr in t.__dict__:
if attr.startswith("_"):
continue

cval = getattr(t, attr)
if cval is None:
setattr(self, attr, cval)
continue

if attr == "state":
self.state = TState()
self.state.state_load(t.state)
elif attr == "tx_prefix_hasher":
from apps.monero.xmr.sub.keccak_hasher import KeccakXmrArchive

self.tx_prefix_hasher = KeccakXmrArchive(ctx=t.tx_prefix_hasher)
elif attr == "full_message_hasher":
from apps.monero.xmr.sub.mlsag_hasher import PreMlsagHasher

self.full_message_hasher = PreMlsagHasher(state=t.full_message_hasher)
else:
setattr(self, attr, cval)
gc.collect()

def state_save(self):
from apps.monero.protocol.tsx_sign_state_holder import TsxSignStateHolder

t = TsxSignStateHolder()

for attr in self.__dict__:
if attr.startswith("_"):
continue

cval = getattr(self, attr)
if cval is None:
setattr(t, attr, cval)
continue

if attr == "state":
t.state = self.state.state_save()
elif attr in ["iface"]:
continue
elif attr.startswith("STEP"):
continue
elif attr == "tx_prefix_hasher":
t.tx_prefix_hasher = self.tx_prefix_hasher.ctx()
elif attr == "full_message_hasher":
t.full_message_hasher = self.full_message_hasher.state_save()
else:
setattr(t, attr, cval)
return t

def _mem_trace(self, x=None, collect=False):
if __debug__:
log.debug(
Expand Down
56 changes: 0 additions & 56 deletions src/apps/monero/protocol/tsx_sign_state_holder.py

This file was deleted.

17 changes: 4 additions & 13 deletions src/apps/monero/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,15 @@ async def sign_tx_step(ctx, msg, state):
if msg.init:
init = msg.init
creds = await wrapper.monero_get_creds(ctx, init.address_n, init.network_type)
state = None
else:
creds = None

tsx = TTransactionBuilder(iface.get_iface(ctx), creds, state)
del creds
del state
state = TTransactionBuilder(iface.get_iface(ctx), creds)
del creds

gc.collect()
res = await sign_tx_dispatch(tsx, msg)
res = await sign_tx_dispatch(state, msg)
gc.collect()

if tsx.is_terminal():
if state.is_terminal():
state = None
else:
state = tsx.state_save()

gc.collect()
return res, state


Expand Down

0 comments on commit 0b175bc

Please sign in to comment.