-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhandle_provide_parameter.c
66 lines (60 loc) · 2.31 KB
/
handle_provide_parameter.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "poap_plugin.h"
// Copy token sent parameter to token_id
static void handle_token(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_parameter(context->token_id, msg->parameter, PARAMETER_LENGTH);
}
static void handle_beneficiary(const ethPluginProvideParameter_t *msg, context_t *context) {
memset(context->beneficiary, 0, sizeof(context->beneficiary));
memcpy(context->beneficiary,
&msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH],
sizeof(context->beneficiary));
PRINTF("BENEFICIARY: %.*H\n", ADDRESS_LENGTH, context->beneficiary);
}
static void handle_mint_token(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case EVENT_ID:
context->next_param = TOKEN;
break;
case TOKEN: // id of the token received
handle_token(msg, context);
context->next_param = BENEFICIARY;
break;
case BENEFICIARY: // to
handle_beneficiary(msg, context);
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}
void handle_provide_parameter(void *parameters) {
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;
msg->result = ETH_PLUGIN_RESULT_OK;
if (context->skip) {
// Skip this step, and don't forget to decrease skipping counter.
context->skip--;
} else {
if ((context->offset) && msg->parameterOffset != context->checkpoint + context->offset) {
PRINTF("offset: %d, checkpoint: %d, parameterOffset: %d\n",
context->offset,
context->checkpoint,
msg->parameterOffset);
return;
}
context->offset = 0; // Reset offset
switch (context->selectorIndex) {
case MINT_TOKEN:
handle_mint_token(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}
}