forked from trezor/trezor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'ba500bf4ec1ef9cd953bdf5a47888c5226db8d0b' into xmr
# Conflicts: # src/apps/monero/__init__.py # src/apps/monero/key_image_sync.py # src/apps/monero/protocol/tsx_sign_builder.py # src/apps/monero/sign_tx.py
- Loading branch information
Showing
4 changed files
with
204 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,43 @@ | ||
import gc | ||
import micropython | ||
|
||
from trezor import log | ||
from trezor.messages import MessageType | ||
|
||
|
||
async def key_image_sync(ctx, msg, state): | ||
log.debug( | ||
__name__, | ||
"### KI SYNC. Free: {} Allocated: {}".format(gc.mem_free(), gc.mem_alloc()), | ||
) | ||
log.debug(__name__, "KI sync state: %s", state.ctx_ki) | ||
async def key_image_sync(ctx, msg): | ||
state = None | ||
|
||
from apps.monero.protocol import key_image_sync | ||
while True: | ||
res, state = await key_image_sync_step(ctx, msg, state) | ||
if msg.final_msg: | ||
break | ||
msg = await ctx.call(res, MessageType.MoneroKeyImageSyncRequest) | ||
|
||
log.debug( | ||
__name__, | ||
"### KI sync imported. Free: {} Allocated: {}".format( | ||
gc.mem_free(), gc.mem_alloc() | ||
), | ||
) | ||
return res | ||
|
||
gc.collect() | ||
micropython.mem_info() | ||
micropython.mem_info(1) | ||
|
||
try: | ||
if msg.init: | ||
log.debug(__name__, "ki_sync, init") | ||
from apps.monero.controller import iface | ||
async def key_image_sync_step(ctx, msg, state): | ||
if __debug__: | ||
log.debug(__name__, "f: %s a: %s", gc.mem_free(), gc.mem_alloc()) | ||
log.debug(__name__, "s: %s", state) | ||
|
||
state.ctx_ki = key_image_sync.KeyImageSync( | ||
ctx=ctx, iface=iface.get_iface(ctx) | ||
) | ||
return await state.ctx_ki.init(ctx, msg.init) | ||
from apps.monero.protocol import key_image_sync | ||
|
||
elif msg.step: | ||
log.debug(__name__, "ki_sync, step") | ||
return await state.ctx_ki.sync(ctx, msg.step) | ||
if __debug__: | ||
log.debug(__name__, "f: %s a: %s", gc.mem_free(), gc.mem_alloc()) | ||
gc.collect() | ||
|
||
elif msg.final_msg: | ||
log.debug(__name__, "ki_sync, final") | ||
res = await state.ctx_ki.final(ctx, msg.final_msg) | ||
state.ctx_ki = None | ||
return res | ||
if msg.init: | ||
from apps.monero.controller import iface | ||
|
||
else: | ||
raise ValueError("Unknown error") | ||
state = key_image_sync.KeyImageSync(ctx=ctx, iface=iface.get_iface(ctx)) | ||
return await state.init(ctx, msg.init), state | ||
|
||
except Exception as e: | ||
state.ctx_ki = None | ||
elif msg.step: | ||
return await state.sync(ctx, msg.step), state | ||
|
||
log.debug(__name__, "KI error, %s: %s", type(e), e) | ||
raise | ||
# from trezor.messages.Failure import Failure | ||
elif msg.final_msg: | ||
return await state.final(ctx, msg.final_msg), None | ||
|
||
# return Failure() | ||
else: | ||
raise ValueError("Unknown error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.