From 2576d9c3a416fdae33db685eb074cc531a905b3a Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 23 May 2016 15:44:09 +0200 Subject: [PATCH] trezor.storage -> trezor.config --- extmod/modtrezorconfig/modtrezorconfig.c | 66 +++++++++++++++++++++ extmod/modtrezorstorage/modtrezorstorage.c | 68 ---------------------- extmod/modtrezorstorage/storage-stmhal.h | 8 --- extmod/modtrezorstorage/storage-unix.h | 6 -- extmod/modtrezorstorage/storage.c | 12 ---- extmod/modtrezorstorage/storage.h | 11 ---- src/trezor/config.py | 10 ++++ src/trezor/storage.py | 10 ---- vendor/micropython | 2 +- 9 files changed, 77 insertions(+), 116 deletions(-) create mode 100644 extmod/modtrezorconfig/modtrezorconfig.c delete mode 100644 extmod/modtrezorstorage/modtrezorstorage.c delete mode 100644 extmod/modtrezorstorage/storage-stmhal.h delete mode 100644 extmod/modtrezorstorage/storage-unix.h delete mode 100644 extmod/modtrezorstorage/storage.c delete mode 100644 extmod/modtrezorstorage/storage.h create mode 100644 src/trezor/config.py delete mode 100644 src/trezor/storage.py diff --git a/extmod/modtrezorconfig/modtrezorconfig.c b/extmod/modtrezorconfig/modtrezorconfig.c new file mode 100644 index 000000000..014dcfd55 --- /dev/null +++ b/extmod/modtrezorconfig/modtrezorconfig.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) Pavol Rusnak, SatoshiLabs + * + * Licensed under Microsoft Reference Source License (Ms-RSL) + * see LICENSE.md file for details + */ + +#include +#include +#include + +#include "py/nlr.h" +#include "py/runtime.h" +#include "py/binary.h" +#include "py/objstr.h" + +#if MICROPY_PY_TREZORCONFIG + +typedef struct _mp_obj_Config_t { + mp_obj_base_t base; +} mp_obj_Config_t; + +STATIC mp_obj_t mod_TrezorConfig_Config_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 0, false); + mp_obj_Config_t *o = m_new_obj(mp_obj_Config_t); + o->base.type = type; + return MP_OBJ_FROM_PTR(o); +} + +STATIC mp_obj_t mod_TrezorConfig_Config_get(mp_obj_t self, mp_obj_t app, mp_obj_t key) { + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorConfig_Config_get_obj, mod_TrezorConfig_Config_get); + +STATIC mp_obj_t mod_TrezorConfig_Config_set(size_t n_args, const mp_obj_t *args) { + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorConfig_Config_set_obj, 4, 4, mod_TrezorConfig_Config_set); + +STATIC const mp_rom_map_elem_t mod_TrezorConfig_Config_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&mod_TrezorConfig_Config_get_obj) }, + { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&mod_TrezorConfig_Config_set_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(mod_TrezorConfig_Config_locals_dict, mod_TrezorConfig_Config_locals_dict_table); + +STATIC const mp_obj_type_t mod_TrezorConfig_Config_type = { + { &mp_type_type }, + .name = MP_QSTR_Config, + .make_new = mod_TrezorConfig_Config_make_new, + .locals_dict = (void*)&mod_TrezorConfig_Config_locals_dict, +}; + +STATIC const mp_rom_map_elem_t mp_module_TrezorConfig_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorConfig) }, + { MP_ROM_QSTR(MP_QSTR_Config), MP_ROM_PTR(&mod_TrezorConfig_Config_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorConfig_globals, mp_module_TrezorConfig_globals_table); + +const mp_obj_module_t mp_module_TrezorConfig = { + .base = { &mp_type_module }, + .name = MP_QSTR_TrezorConfig, + .globals = (mp_obj_dict_t*)&mp_module_TrezorConfig_globals, +}; + +#endif // MICROPY_PY_TREZORCONFIG diff --git a/extmod/modtrezorstorage/modtrezorstorage.c b/extmod/modtrezorstorage/modtrezorstorage.c deleted file mode 100644 index d3846a739..000000000 --- a/extmod/modtrezorstorage/modtrezorstorage.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under Microsoft Reference Source License (Ms-RSL) - * see LICENSE.md file for details - */ - -#include -#include -#include - -#include "py/nlr.h" -#include "py/runtime.h" -#include "py/binary.h" -#include "py/objstr.h" - -#if MICROPY_PY_TREZORSTORAGE - -#include "storage.h" - -typedef struct _mp_obj_Storage_t { - mp_obj_base_t base; -} mp_obj_Storage_t; - -STATIC mp_obj_t mod_TrezorStorage_Storage_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 0, 0, false); - mp_obj_Storage_t *o = m_new_obj(mp_obj_Storage_t); - o->base.type = type; - return MP_OBJ_FROM_PTR(o); -} - -STATIC mp_obj_t mod_TrezorStorage_Storage_get(mp_obj_t self, mp_obj_t key, mp_obj_t defval) { - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorStorage_Storage_get_obj, mod_TrezorStorage_Storage_get); - -STATIC mp_obj_t mod_TrezorStorage_Storage_set(mp_obj_t self, mp_obj_t key, mp_obj_t value) { - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorStorage_Storage_set_obj, mod_TrezorStorage_Storage_set); - -STATIC const mp_rom_map_elem_t mod_TrezorStorage_Storage_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&mod_TrezorStorage_Storage_get_obj) }, - { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&mod_TrezorStorage_Storage_set_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(mod_TrezorStorage_Storage_locals_dict, mod_TrezorStorage_Storage_locals_dict_table); - -STATIC const mp_obj_type_t mod_TrezorStorage_Storage_type = { - { &mp_type_type }, - .name = MP_QSTR_Storage, - .make_new = mod_TrezorStorage_Storage_make_new, - .locals_dict = (void*)&mod_TrezorStorage_Storage_locals_dict, -}; - -STATIC const mp_rom_map_elem_t mp_module_TrezorStorage_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorStorage) }, - { MP_ROM_QSTR(MP_QSTR_Storage), MP_ROM_PTR(&mod_TrezorStorage_Storage_type) }, -}; - -STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorStorage_globals, mp_module_TrezorStorage_globals_table); - -const mp_obj_module_t mp_module_TrezorStorage = { - .base = { &mp_type_module }, - .name = MP_QSTR_TrezorStorage, - .globals = (mp_obj_dict_t*)&mp_module_TrezorStorage_globals, -}; - -#endif // MICROPY_PY_TREZORSTORAGE diff --git a/extmod/modtrezorstorage/storage-stmhal.h b/extmod/modtrezorstorage/storage-stmhal.h deleted file mode 100644 index 001a2bd49..000000000 --- a/extmod/modtrezorstorage/storage-stmhal.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under Microsoft Reference Source License (Ms-RSL) - * see LICENSE.md file for details - */ - -#include STM32_HAL_H diff --git a/extmod/modtrezorstorage/storage-unix.h b/extmod/modtrezorstorage/storage-unix.h deleted file mode 100644 index c6e0a3731..000000000 --- a/extmod/modtrezorstorage/storage-unix.h +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under Microsoft Reference Source License (Ms-RSL) - * see LICENSE.md file for details - */ diff --git a/extmod/modtrezorstorage/storage.c b/extmod/modtrezorstorage/storage.c deleted file mode 100644 index 97b414b80..000000000 --- a/extmod/modtrezorstorage/storage.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under Microsoft Reference Source License (Ms-RSL) - * see LICENSE.md file for details - */ - -#if defined STM32_HAL_H -#include "storage-stmhal.h" -#else -#include "storage-unix.h" -#endif diff --git a/extmod/modtrezorstorage/storage.h b/extmod/modtrezorstorage/storage.h deleted file mode 100644 index 29d61a9ce..000000000 --- a/extmod/modtrezorstorage/storage.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under Microsoft Reference Source License (Ms-RSL) - * see LICENSE.md file for details - */ - -#ifndef __STORAGE_H__ -#define __STORAGE_H__ - -#endif diff --git a/src/trezor/config.py b/src/trezor/config.py new file mode 100644 index 000000000..641ce9ce5 --- /dev/null +++ b/src/trezor/config.py @@ -0,0 +1,10 @@ +from TrezorConfig import Config + +_config = Config() + +def get(app, key, default=None): + v = _config.get(app, key) + return v if v else default + +def set(app, key, value): + return _config.set(app, key, value) diff --git a/src/trezor/storage.py b/src/trezor/storage.py deleted file mode 100644 index 47a57ab93..000000000 --- a/src/trezor/storage.py +++ /dev/null @@ -1,10 +0,0 @@ -from TrezorStorage import Storage - -_storage = Storage() - -def get(key, defval=None): - return _storage.get(key, defval) - - -def set(key, value): - return _storage.set(key, value) diff --git a/vendor/micropython b/vendor/micropython index 9cee3cdb8..4509a515d 160000 --- a/vendor/micropython +++ b/vendor/micropython @@ -1 +1 @@ -Subproject commit 9cee3cdb8fc0444e292308cbbabee12e98e2fd07 +Subproject commit 4509a515d6057d2fca4b642b055108c2ff6bf78b