-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhandle_init_contract.c
45 lines (37 loc) · 1.32 KB
/
handle_init_contract.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "poap_plugin.h"
// Called once to init.
void handle_init_contract(void *parameters) {
ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters;
if (msg->interfaceVersion != ETH_PLUGIN_INTERFACE_VERSION_LATEST) {
msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
return;
}
if (msg->pluginContextLength < sizeof(context_t)) {
PRINTF("Plugin parameters structure is bigger than allowed size\n");
// msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
context_t *context = (context_t *) msg->pluginContext;
memset(context, 0, sizeof(*context));
uint8_t i;
for (i = 0; i < NUM_SELECTORS; i++) {
if (memcmp((uint8_t *) PIC(POAP_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) {
context->selectorIndex = i;
break;
}
}
if (i == NUM_SELECTORS) {
msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
}
// Set `next_param` to be the first field we expect to parse.
switch (context->selectorIndex) {
case MINT_TOKEN:
context->next_param = EVENT_ID;
break;
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
msg->result = ETH_PLUGIN_RESULT_OK;
}