Skip to content

Commit

Permalink
Merge pull request #13 from blooo-io/fix/plugin-sdk-upgrade
Browse files Browse the repository at this point in the history
fix: update of the plugin sdk
  • Loading branch information
n4l5u0r authored Mar 4, 2022
2 parents 84f6ca8 + 669e837 commit 74e54af
Show file tree
Hide file tree
Showing 54 changed files with 25,203 additions and 1,538 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v2
with:
node-version: "14.4.0"
node-version: "16.4.0"
- name: Install yarn
run: |
npm install -g yarn
Expand Down
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
7 changes: 0 additions & 7 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;

msg->uiType = ETH_UI_TYPE_GENERIC;

// 2 additional screens are required to display the `token and `beneficiary` fields
msg->numScreens = 2;
msg->result = ETH_PLUGIN_RESULT_OK;

if (context->selectorIndex == SAFE_TRANSFER) {
// An additional screen is required to display the `token` field for safe_transfer method.
msg->numScreens += 1;
}
}
3 changes: 0 additions & 3 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ void handle_init_contract(void *parameters) {
case MINT_TOKEN:
context->next_param = EVENT_ID;
break;
case SAFE_TRANSFER:
context->next_param = FROM_ADDRESS;
break;
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
40 changes: 1 addition & 39 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#include "poap_plugin.h"

// Copies the whole parameter (32 bytes long) from `src` to `dst`.
// Useful for numbers, data...
static void copy_parameter(uint8_t *dst, uint8_t *src) {
memcpy(dst, src, PARAMETER_LENGTH);
}

// 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);
copy_parameter(context->token_id, msg->parameter, PARAMETER_LENGTH);
}

static void handle_beneficiary(const ethPluginProvideParameter_t *msg, context_t *context) {
Expand All @@ -19,13 +13,6 @@ static void handle_beneficiary(const ethPluginProvideParameter_t *msg, context_t
PRINTF("BENEFICIARY: %.*H\n", ADDRESS_LENGTH, context->beneficiary);
}

static void handle_from_address(const ethPluginProvideParameter_t *msg, context_t *context) {
memset(context->from_address, 0, sizeof(context->from_address));
memcpy(context->from_address,
&msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH],
sizeof(context->from_address));
PRINTF("FROM_ADDRESS: %.*H\n", ADDRESS_LENGTH, context->from_address);
}
static void handle_mint_token(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case EVENT_ID:
Expand All @@ -47,28 +34,6 @@ static void handle_mint_token(ethPluginProvideParameter_t *msg, context_t *conte
break;
}
}
static void handle_safe_transfer(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case FROM_ADDRESS: // from_address
handle_from_address(msg, context);
context->next_param = BENEFICIARY;
break;
case BENEFICIARY: // to
handle_beneficiary(msg, context);
context->next_param = TOKEN;
break;
case TOKEN: // id of the token received
handle_token(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;
Expand All @@ -92,9 +57,6 @@ void handle_provide_parameter(void *parameters) {
case MINT_TOKEN:
handle_mint_token(msg, context);
break;
case SAFE_TRANSFER:
handle_safe_transfer(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
3 changes: 0 additions & 3 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ void handle_query_contract_id(void *parameters) {
strlcpy(msg->name, PLUGIN_NAME, msg->nameLength);

switch (context->selectorIndex) {
case SAFE_TRANSFER:
strlcpy(msg->version, "Safe Transfer", msg->versionLength);
break;
case MINT_TOKEN:
strlcpy(msg->version, "Mint", msg->versionLength);
break;
Expand Down
16 changes: 0 additions & 16 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ static void set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
getEthAddressStringFromBinary(context->beneficiary, msg->msg + 2, msg->pluginSharedRW->sha3, 0);
}

// Set UI for "From Address" screen.
static void set_from_address_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "From Address", msg->titleLength);

msg->msg[0] = '0';
msg->msg[1] = 'x';

getEthAddressStringFromBinary(context->from_address,
msg->msg + 2,
msg->pluginSharedRW->sha3,
0);
}

// Set UI for "Warning" screen.
static void set_warning_ui(ethQueryContractUI_t *msg,
const context_t *context __attribute__((unused))) {
Expand Down Expand Up @@ -82,9 +69,6 @@ void handle_query_contract_ui(void *parameters) {
screens_t screen = get_screen(msg, context);

switch (screen) {
case FROM_ADDRESS_SCREEN:
set_from_address_ui(msg, context);
break;
case TOKEN_SCREEN:
set_token_ui(msg, context);
break;
Expand Down
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

#include "poap_plugin.h"

// Function: mintToken(uint256 eventId, uint256 tokenId, address receiver, bytes signedMessage)
// Selector: 0x3da5b8f0
static const uint8_t MINT_TOKEN_SELECTOR[SELECTOR_SIZE] = {0x3d, 0xa5, 0xb8, 0xf0};
static const uint8_t SAFE_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0x42, 0x84, 0x2e, 0x0e};
// Function: mintToken(uint256 eventId, uint256 tokenId, address receiver, uint256 expirationTime,
// bytes signature)
// Selector: 0xaf68b302
static const uint8_t MINT_TOKEN_SELECTOR[SELECTOR_SIZE] = {0xaf, 0x68, 0xb3, 0x02};

// Array of all the different poap selectors.
const uint8_t *const POAP_SELECTORS[NUM_SELECTORS] = {MINT_TOKEN_SELECTOR, SAFE_TRANSFER_SELECTOR};
const uint8_t *const POAP_SELECTORS[NUM_SELECTORS] = {MINT_TOKEN_SELECTOR};

// Function to dispatch calls from the ethereum app.
void dispatch_plugin_calls(int message, void *parameters) {
Expand Down
4 changes: 1 addition & 3 deletions src/poap_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "eth_plugin_interface.h"
#include <string.h>

#define NUM_SELECTORS 2
#define NUM_SELECTORS 1
#define PLUGIN_NAME "Poap"
#define TOKEN_FOUND 1 << 1
#define SELECTOR_SIZE 4
Expand All @@ -13,7 +13,6 @@

typedef enum {
MINT_TOKEN,
SAFE_TRANSFER,
} selector_t;

// Enumeration used to parse the smart contract data.
Expand All @@ -39,7 +38,6 @@ extern const uint8_t *const POAP_SELECTORS[NUM_SELECTORS];
typedef struct context_t {
// For display.
uint8_t beneficiary[ADDRESS_LENGTH];
uint8_t from_address[ADDRESS_LENGTH];
uint8_t token_id[PARAMETER_LENGTH]; // not crypto token dedicated poap token value int number
char ticker[MAX_TICKER_LEN];

Expand Down
16 changes: 16 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
env: {
es2021: true,
node: true,
jest: true,
},
extends: ["eslint:recommended"],
parserOptions: {
sourceType: "module",
},
rules: {
"linebreak-style": ["error", "unix"],
semi: ["error", "always"],
},
};

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/poap_nanos.elf
Binary file not shown.
Binary file modified tests/elfs/poap_nanox.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/globalsetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ module.exports = async () => {
await catchExit();
await Zemu.checkAndPullImage();
await Zemu.stopAllEmuContainers();
fsExtra.emptyDirSync("snapshots/tmp")
fsExtra.emptyDirSync("snapshots/tmp");
};
Loading

0 comments on commit 74e54af

Please sign in to comment.