Skip to content

Commit

Permalink
Merge pull request #8 from blooo-io/feat/upgraded-smart-contract-nft
Browse files Browse the repository at this point in the history
  • Loading branch information
n4l5u0r authored Aug 14, 2022
2 parents 848a2fa + 502d140 commit e66d5c1
Show file tree
Hide file tree
Showing 43 changed files with 833 additions and 666 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --curve secp25
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPVERSION_M = 1
APPVERSION_N = 0
APPVERSION_P = 1
APPVERSION_N = 1
APPVERSION_P = 0
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

APPNAME = "[ L ] Market"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Smart contracts covered by this plugin are:

| Network | Version | Smart Contract |
| --- | --- | --- |
| Ropsten | V0 | `0xD7aFf4dB67e1Aa519807221a09c83ADe09833992`|
| Goerli | V0 | `0x6c304a1f99cecd3a9983001e943f3de00ed811d0`|


## Build
Expand All @@ -51,6 +51,7 @@ cd LedgerHQ-app-plugin-nft/tests # go to the tests folder in LedgerHQ-app-
To test the plugin go to the tests folder from the "LedgerHQ-app-plugin-nft" and run the script "test"
```shell
cd LedgerHQ-app-plugin-nft/tests # go to the tests folder in LedgerHQ-app-plugin-nft
yarn # install dependencies
yarn test # run the script test
```
## Continuous Integration
Expand Down
9 changes: 5 additions & 4 deletions src/contract.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "ledger_nft_plugin.h"

// Function: mint
// Selector: 0x1249c58b
static const uint8_t MINT_SELECTOR[SELECTOR_SIZE] = {0x12, 0x49, 0xc5, 0x8b};
// Selector: 0xa0712d68
static const uint8_t MINT_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};

// Function: preSaleMint
// Selector: 0xc111fb91
static const uint8_t PRE_SALE_MINT_SELECTOR[SELECTOR_SIZE] = {0xc1, 0x11, 0xfb, 0x91};
// Selector: 0x827481ea
static const uint8_t PRE_SALE_MINT_SELECTOR[SELECTOR_SIZE] = {0x82, 0x74, 0x81, 0xea};

// Plugin uses 0x00000 as a dummy address to reprecent ETH.
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ void handle_finalize(void *parameters) {
msg->uiType = ETH_UI_TYPE_GENERIC;

// 2 additional screens are required to display the `token and `beneficiary` fields
msg->numScreens = 1;
msg->numScreens = 2;
msg->result = ETH_PLUGIN_RESULT_OK;
}
3 changes: 2 additions & 1 deletion src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void handle_init_contract(void *parameters) {

if (msg->pluginContextLength < sizeof(context_t)) {
PRINTF("Plugin parameters structure is bigger than allowed size\n");
// msg->result = ETH_PLUGIN_RESULT_ERROR;
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}

Expand All @@ -34,6 +34,7 @@ void handle_init_contract(void *parameters) {
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
context->next_param = AMOUNT;
break;
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
Expand Down
20 changes: 20 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#include "ledger_nft_plugin.h"

void handle_amount(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_parameter(context->amount, msg->parameter, sizeof(context->amount));
}

void handle_mint(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case AMOUNT: // tokenA
handle_amount(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;
Expand All @@ -21,6 +40,7 @@ void handle_provide_parameter(void *parameters) {
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
handle_mint(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
Expand Down
16 changes: 13 additions & 3 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ledger_nft_plugin.h"

// Set UI for "Amount" screen.
static void set_amount_ui(ethQueryContractUI_t *msg, context_t *context) {
// Set UI for "Payable Amount" screen.
static void set_payable_amount_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Amount", msg->titleLength);

// set network ticker (ETH, BNB, etc) if needed
Expand All @@ -17,14 +17,21 @@ static void set_amount_ui(ethQueryContractUI_t *msg, context_t *context) {
msg->msgLength);
}

static void set_amount_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Quantity", msg->titleLength);

amountToString(context->amount, sizeof(context->amount), 0, "", msg->msg, msg->msgLength);
}

// 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 __attribute__((unused))) {
uint8_t index = msg->screenIndex;

switch (index) {
case 0:
return AMOUNT_SCREEN;
case 1:
return PAYABLE_AMOUNT_SCREEN;
default:
return ERROR;
}
Expand All @@ -44,6 +51,9 @@ void handle_query_contract_ui(void *parameters) {
case AMOUNT_SCREEN:
set_amount_ui(msg, context);
break;
case PAYABLE_AMOUNT_SCREEN:
set_payable_amount_ui(msg, context);
break;
default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/ledger_nft_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ typedef enum {

// Enumeration used to parse the smart contract data.
typedef enum {
PAYABLE_AMOUNT,
AMOUNT,
NONE,
} parameter;

typedef enum {
AMOUNT_SCREEN,
PAYABLE_AMOUNT_SCREEN,
ERROR,
} screens_t;

Expand All @@ -37,6 +39,7 @@ extern const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS];
typedef struct context_t {
// For display.
uint8_t amount[PARAMETER_LENGTH];
uint8_t payable_amount[PARAMETER_LENGTH];
uint8_t contract_address_sent[ADDRESS_LENGTH];
char ticker_sent[MAX_TICKER_LEN];

Expand Down
Loading

0 comments on commit e66d5c1

Please sign in to comment.