Skip to content

Commit

Permalink
Merge pull request #20 from blooo-io/fix/plugin-sdk
Browse files Browse the repository at this point in the history
fix: ethereum-sdk bump
  • Loading branch information
n4l5u0r authored Feb 1, 2022
2 parents 3c879c1 + 5068fe8 commit cc3ef4c
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
12 changes: 2 additions & 10 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#include "ricochet_plugin.h"

// Copies the whole parameter (32 bytes long) from `src` to `dst`.
// Useful for numbers, data...
static void copy_parameter(uint8_t *dst, size_t dst_len, uint8_t *src) {
// Take the minimum between dst_len and parameter_length to make sure we don't overwrite memory.
size_t len = MIN(dst_len, PARAMETER_LENGTH);
memcpy(dst, src, len);
}

// Copy amount sent parameter to amount
static void handle_amount_value(const ethPluginInitContract_t *msg, context_t *context) {
copy_parameter(context->amount,
sizeof(context->amount),
msg->pluginSharedRO->txContent->value.value);
msg->pluginSharedRO->txContent->value.value,
sizeof(context->amount));
}

// Called once to init.
Expand Down
10 changes: 1 addition & 9 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#include "ricochet_plugin.h"

// Copies the whole parameter (32 bytes long) from `src` to `dst`.
// Useful for numbers, data...
static void copy_parameter(uint8_t *dst, size_t dst_len, uint8_t *src) {
// Take the minimum between dst_len and parameter_length to make sure we don't overwrite memory.
size_t len = MIN(dst_len, PARAMETER_LENGTH);
memcpy(dst, src, len);
}

// Copy amount sent parameter to amoun
static void handle_amount(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_parameter(context->amount, sizeof(context->amount), msg->parameter);
copy_parameter(context->amount, msg->parameter, sizeof(context->amount));
}

static void handle_agreement_class(const ethPluginProvideParameter_t *msg, context_t *context) {
Expand Down
24 changes: 12 additions & 12 deletions src/handle_provide_token.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ricochet_plugin.h"

void handle_downgrade_tokens(ethPluginProvideToken_t *msg, context_t *context) {
void handle_downgrade_tokens(context_t *context) {
super_token_ticker_t *currentToken = NULL;
for (uint8_t i = 0; i < NUM_SUPER_TOKEN_COLLECTION; i++) {
currentToken = (super_token_ticker_t *) PIC(&SUPER_TOKEN_COLLECTION[i]);
Expand All @@ -18,7 +18,7 @@ void handle_downgrade_tokens(ethPluginProvideToken_t *msg, context_t *context) {
}
}

void handle_upgrade_tokens(ethPluginProvideToken_t *msg, context_t *context) {
void handle_upgrade_tokens(context_t *context) {
super_token_ticker_t *currentToken = NULL;
for (uint8_t i = 0; i < NUM_SUPER_TOKEN_COLLECTION; i++) {
currentToken = (super_token_ticker_t *) PIC(&SUPER_TOKEN_COLLECTION[i]);
Expand All @@ -36,7 +36,7 @@ void handle_upgrade_tokens(ethPluginProvideToken_t *msg, context_t *context) {
}
}

void handle_cfa_tokens(ethPluginProvideToken_t *msg, context_t *context) {
void handle_cfa_tokens(context_t *context) {
contract_address_ticker_t *currentContract = NULL;

for (uint8_t i = 0; i < NUM_CONTRACT_ADDRESS_COLLECTION; i++) {
Expand All @@ -46,10 +46,10 @@ void handle_cfa_tokens(ethPluginProvideToken_t *msg, context_t *context) {
context->contract_address_received,
ADDRESS_LENGTH) == 0 &&
context->method_id == STOP_STREAM) ||
memcmp(currentContract->contract_address,
context->contract_address_sent,
ADDRESS_LENGTH) == 0 &&
(context->method_id == UPDATE_STREAM || context->method_id == START_STREAM)) {
(memcmp(currentContract->contract_address,
context->contract_address_sent,
ADDRESS_LENGTH) == 0 &&
(context->method_id == UPDATE_STREAM || context->method_id == START_STREAM))) {
strlcpy(context->ticker_sent,
(char *) currentContract->ticker_sent,
sizeof(context->ticker_sent));
Expand All @@ -61,31 +61,31 @@ void handle_cfa_tokens(ethPluginProvideToken_t *msg, context_t *context) {
}
}

void handle_received_address(ethPluginProvideToken_t *msg, context_t *context) {
void handle_received_address(ethPluginProvideInfo_t *msg, context_t *context) {
memset(context->contract_address_received, 0, sizeof(context->contract_address_received));
memcpy(context->contract_address_received,
msg->pluginSharedRO->txContent->destination,
sizeof(context->contract_address_received));
}

void handle_provide_token(void *parameters) {
ethPluginProvideToken_t *msg = (ethPluginProvideToken_t *) parameters;
ethPluginProvideInfo_t *msg = (ethPluginProvideInfo_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;

switch (context->selectorIndex) {
case DOWNGRADE:
case DOWNGRADE_TO_ETH:
context->decimals = DEFAULT_DECIMAL;
handle_received_address(msg, context);
handle_downgrade_tokens(msg, context);
handle_downgrade_tokens(context);
break;
case UPGRADE:
case UPGRADE_TO_ETH:
handle_received_address(msg, context);
handle_upgrade_tokens(msg, context);
handle_upgrade_tokens(context);
break;
case CALL_AGREEMENT:
handle_cfa_tokens(msg, context);
handle_cfa_tokens(context);
break;
case BATCH_CALL:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "ricochet_plugin.h"

void handle_init_cfa_screen(ethQueryContractID_t *msg, context_t *context) {
void handle_init_cfa_screen(ethQueryContractID_t *msg, const context_t *context) {
cfa_method_t *cfaMethod = NULL;

for (uint8_t i = 0; i < NUM_CFA_METHOD_COLLECTION; i++) {
cfaMethod = (cfa_method_t *) PIC(&CFA_METHOD_COLLECTION[i]);
if (compare_array(cfaMethod->method, context->method_cfa, SELECTOR_SIZE) == 0) {
if (compare_array(cfaMethod->method, (uint8_t *) context->method_cfa, SELECTOR_SIZE) == 0) {
strlcpy(msg->version, (char *) cfaMethod->method_name, msg->versionLength);
break;
}
Expand Down
10 changes: 4 additions & 6 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ char compare_array(uint8_t a[], uint8_t b[], int size) {
}

static unsigned long long amountToDecimal(context_t *context, int size) {
uint8_t i;
long long int value = 0;

for (uint8_t i = 0; i < size; i++) {
value = value * 256 + context->amount[i];
}
Expand Down Expand Up @@ -61,7 +59,7 @@ static void set_cfa_from_ui(ethQueryContractUI_t *msg, context_t *context) {
}

if (context->method_id != STOP_STREAM) {
unsigned long long value = amountToDecimal(context->amount, sizeof(context->amount));
unsigned long long value = amountToDecimal(context, sizeof(context->amount));
value *= 2592000; // switch from token per sec to token per month for UX only.
decimalToAmount(value, context);

Expand Down Expand Up @@ -115,7 +113,7 @@ static void set_batch_call_from_ui(ethQueryContractUI_t *msg, context_t *context
}
}

unsigned long long value = amountToDecimal(context->amount, sizeof(context->amount));
unsigned long long value = amountToDecimal(context, sizeof(context->amount));
value *= 2592000; // switch from token per sec to token per month for UX only.

decimalToAmount(value, context);
Expand Down Expand Up @@ -182,7 +180,7 @@ static void set_receive_ui(ethQueryContractUI_t *msg, context_t *context) {
}

// Helper function that returns the enum corresponding to the screen that should be displayed.
static screens_t get_screen(const ethQueryContractUI_t *msg, const context_t *context) {
static screens_t get_screen(const ethQueryContractUI_t *msg) {
uint8_t index = msg->screenIndex;

switch (index) {
Expand All @@ -206,7 +204,7 @@ void handle_query_contract_ui(void *parameters) {
memset(msg->msg, 0, msg->msgLength);
msg->result = ETH_PLUGIN_RESULT_OK;

screens_t screen = get_screen(msg, context);
screens_t screen = get_screen(msg);

switch (context->selectorIndex) {
case DOWNGRADE:
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void dispatch_plugin_calls(int message, void *parameters) {
case ETH_PLUGIN_PROVIDE_PARAMETER:
handle_provide_parameter(parameters);
break;
case ETH_PLUGIN_PROVIDE_TOKEN:
case ETH_PLUGIN_PROVIDE_INFO:
handle_provide_token(parameters);
break;
case ETH_PLUGIN_FINALIZE:
Expand Down
4 changes: 3 additions & 1 deletion src/ricochet_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,6 @@ void handle_provide_parameter(void *parameters);
void handle_query_contract_ui(void *parameters);
void handle_finalize(void *parameters);
void handle_provide_token(void *parameters);
void handle_query_contract_id(void *parameters);
void handle_query_contract_id(void *parameters);

char compare_array(uint8_t a[], uint8_t b[], int size);
Binary file modified tests/elfs/ethereum_nanos.elf
Binary file not shown.
Binary file modified tests/elfs/ethereum_nanox.elf
Binary file not shown.
Binary file modified tests/elfs/ricochet_nanos.elf
Binary file not shown.
Binary file modified tests/elfs/ricochet_nanox.elf
Binary file not shown.

0 comments on commit cc3ef4c

Please sign in to comment.