Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

device_ledger: include status code name in error message #6322

Open
wants to merge 1 commit into
base: master
from

Conversation

@xiphon
Copy link
Contributor

xiphon commented Feb 7, 2020

No description provided.

@@ -64,6 +69,81 @@ namespace hw {
crypto::secret_key dbg_spendkey;
#endif

#define LEDGER_STATUS(status) {status, #status}
static const std::map<unsigned int, const char *> status_codes = {

This comment has been minimized.

Copy link
@vtnerd

vtnerd Feb 7, 2020

Contributor

If these codes were sorted, this can be a constexpr table with a std::lower_bound search over it. Unfortunately, constexpr constructors for std::pair aren't available in C++11. Only a struct and lambda usage is necessary, so the coding overhead is still minimal.

This would saves a bit of memory and startup cost, and eliminates the possibility of static initialization order issues. I haven't attempt to track down the latter, so its possible this is guaranteed to work on all scenarios (right now).

This comment has been minimized.

Copy link
@xiphon

xiphon Feb 8, 2020

Author Contributor

Good idea, let's avoid static initialization with constexpr table. Updated.

Copy link
Contributor

moneromooo-monero left a comment

The class seems like a long winded way to do it, but fair enough.

@xiphon xiphon force-pushed the xiphon:ledger-error-desc branch from abf96ad to 29b7cd1 Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.