From d432e574319689eade45db03f3060fbcd0cf644d Mon Sep 17 00:00:00 2001 From: TamtamHero <10632523+TamtamHero@users.noreply.github.com> Date: Sat, 14 Nov 2020 18:14:34 +0100 Subject: [PATCH] Make plugins result status explicits on every case --- src_plugins/compound/compound_plugin.c | 28 +++++++++++++++++--------- src_plugins/erc20/erc20_plugin.c | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src_plugins/compound/compound_plugin.c b/src_plugins/compound/compound_plugin.c index 815d71c..4985bc6 100644 --- a/src_plugins/compound/compound_plugin.c +++ b/src_plugins/compound/compound_plugin.c @@ -85,23 +85,26 @@ void compound_plugin_call(int message, void *parameters) { if (!allzeroes(msg->pluginSharedRO->txContent->value.value, 32)){ if(context->selectorIndex != CETH_MINT){ msg->result = ETH_PLUGIN_RESULT_ERROR; + break; } } + if (i == NUM_COMPOUND_SELECTORS) { + PRINTF("Unknown selector %.*H\n", SELECTOR_SIZE, msg->selector); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } + if (msg->dataSize != COMPOUND_EXPECTED_DATA_SIZE[context->selectorIndex]) { + PRINTF("Unexpected data size for command %d expected %d got %d\n", context->selectorIndex, + COMPOUND_EXPECTED_DATA_SIZE[context->selectorIndex], msg->dataSize); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } if(context->selectorIndex == CETH_MINT){ // ETH amount 0x1234 is stored 0x12340000...000 instead of 0x00....001234, so we strip the following zeroes when copying memset(context->amount, 0, sizeof(context->amount)); memmove(context->amount + sizeof(context->amount) - msg->pluginSharedRO->txContent->value.length, msg->pluginSharedRO->txContent->value.value, 32); } - if (i == NUM_COMPOUND_SELECTORS) { - PRINTF("Unknown selector %.*H\n", SELECTOR_SIZE, msg->selector); - break; - } - if (msg->dataSize != COMPOUND_EXPECTED_DATA_SIZE[context->selectorIndex]) { - PRINTF("Unexpected data size for command %d expected %d got %d\n", context->selectorIndex, - COMPOUND_EXPECTED_DATA_SIZE[context->selectorIndex], msg->dataSize); - break; - } - PRINTF("compound plugin init\n"); + PRINTF("compound plugin inititialized\n"); msg->result = ETH_PLUGIN_RESULT_OK; } break; @@ -118,9 +121,14 @@ void compound_plugin_call(int message, void *parameters) { break; default: PRINTF("Unhandled parameter offset\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; break; } } + else { + PRINTF("CETH contract expects no parameters\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + } } break; diff --git a/src_plugins/erc20/erc20_plugin.c b/src_plugins/erc20/erc20_plugin.c index 552f7dc..c3b6f1c 100644 --- a/src_plugins/erc20/erc20_plugin.c +++ b/src_plugins/erc20/erc20_plugin.c @@ -76,6 +76,7 @@ void erc20_plugin_call(int message, void *parameters) { } if (i == NUM_ERC20_SELECTORS) { PRINTF("Unknown selector %.*H\n", SELECTOR_SIZE, msg->selector); + msg->result = ETH_PLUGIN_RESULT_ERROR; break; } PRINTF("erc20 plugin init\n"); @@ -99,6 +100,7 @@ void erc20_plugin_call(int message, void *parameters) { break; default: PRINTF("Unhandled parameter offset\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; break; } }