Make plugins result status explicits on every case

This commit is contained in:
TamtamHero
2020-11-14 18:14:34 +01:00
parent e7428586d1
commit d432e57431
2 changed files with 20 additions and 10 deletions

View File

@@ -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;

View File

@@ -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;
}
}