Skip to content

Commit

Permalink
Merge pull request #2 from blooo-io/refactor/LAPP-3-replace-boilerpla…
Browse files Browse the repository at this point in the history
…te-with-poap

Refactor/lapp 3 replace boilerplate with poap
  • Loading branch information
n4l5u0r authored Nov 22, 2021
2 parents 0943b0f + d62f508 commit 1992e09
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 47 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif
include $(BOLOS_SDK)/Makefile.defines

# EDIT THIS: Put your plugin name
APPNAME = "Boilerplate"
APPNAME = "Poap"

APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --curve secp256k1

Expand All @@ -35,9 +35,9 @@ APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

# EDIT THIS: Change the name of the gif, and generate you own GIFs!
ifeq ($(TARGET_NAME), TARGET_NANOX)
ICONNAME=icons/nanox_app_boilerplate.gif
ICONNAME=icons/nanox_app_poap.gif
else
ICONNAME=icons/nanos_app_boilerplate.gif
ICONNAME=icons/nanos_app_poap.gif
endif

################
Expand Down Expand Up @@ -140,5 +140,5 @@ include $(BOLOS_SDK)/Makefile.rules
dep/%.d: %.c Makefile

listvariants:
# EDIT THIS: replace `boilerplate` by the lowercase name of your plugin
@echo VARIANTS NONE boilerplate
# EDIT THIS: replace `poap` by the lowercase name of your plugin
@echo VARIANTS NONE poap
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion src/handle_finalize.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "boilerplate_plugin.h"
#include "poap_plugin.h"

void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
Expand Down
6 changes: 3 additions & 3 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "boilerplate_plugin.h"
#include "poap_plugin.h"

// Called once to init.
void handle_init_contract(void *parameters) {
Expand Down Expand Up @@ -28,7 +28,7 @@ void handle_init_contract(void *parameters) {
// Look for the index of the selectorIndex passed in by `msg`.
uint8_t i;
for (i = 0; i < NUM_SELECTORS; i++) {
if (memcmp((uint8_t *) PIC(BOILERPLATE_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) {
if (memcmp((uint8_t *) PIC(POAP_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) {
context->selectorIndex = i;
break;
}
Expand All @@ -46,7 +46,7 @@ void handle_init_contract(void *parameters) {
case SWAP_EXACT_ETH_FOR_TOKENS:
context->next_param = MIN_AMOUNT_RECEIVED;
break;
case BOILERPLATE_DUMMY_2:
case POAP_DUMMY_2:
context->next_param = TOKEN_RECEIVED;
// Keep this
default:
Expand Down
4 changes: 2 additions & 2 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "boilerplate_plugin.h"
#include "poap_plugin.h"

// Copies the whole parameter (32 bytes long) from `src` to `dst`.
// Useful for numbers, data...
Expand Down Expand Up @@ -76,7 +76,7 @@ void handle_provide_parameter(void *parameters) {
case SWAP_EXACT_ETH_FOR_TOKENS:
handle_swap_exact_eth_for_tokens(msg, context);
break;
case BOILERPLATE_DUMMY_2:
case POAP_DUMMY_2:
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/handle_provide_token.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "boilerplate_plugin.h"
#include "poap_plugin.h"

// EDIT THIS: Adapt this function to your needs! Remember, the information for tokens are held in
// `msg->token1` and `msg->token2`. If those pointers are `NULL`, this means the ethereum app didn't
Expand Down
2 changes: 1 addition & 1 deletion src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "boilerplate_plugin.h"
#include "poap_plugin.h"

// Sets the first screen to display.
void handle_query_contract_id(void *parameters) {
Expand Down
2 changes: 1 addition & 1 deletion src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "boilerplate_plugin.h"
#include "poap_plugin.h"

// EDIT THIS: You need to adapt / remove the static functions (set_send_ui, set_receive_ui ...) to
// match what you wish to display.
Expand Down
12 changes: 6 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
#include "os.h"
#include "cx.h"

#include "boilerplate_plugin.h"
#include "poap_plugin.h"

// List of selectors supported by this plugin.
// EDIT THIS: Adapt the variable names and change the `0x` values to match your selectors.
static const uint8_t SWAP_EXACT_ETH_FOR_TOKENS_SELECTOR[SELECTOR_SIZE] = {0x7f, 0xf3, 0x6a, 0xb5};
static const uint8_t BOILERPLATE_DUMMY_SELECTOR_2[SELECTOR_SIZE] = {0x13, 0x37, 0x42, 0x42};
static const uint8_t POAP_DUMMY_SELECTOR_2[SELECTOR_SIZE] = {0x13, 0x37, 0x42, 0x42};

// Array of all the different boilerplate selectors. Make sure this follows the same order as the
// enum defined in `boilerplate_plugin.h`
// Array of all the different poap selectors. Make sure this follows the same order as the
// enum defined in `poap_plugin.h`
// EDIT THIS: Use the names of the array declared above.
const uint8_t *const BOILERPLATE_SELECTORS[NUM_SELECTORS] = {
const uint8_t *const POAP_SELECTORS[NUM_SELECTORS] = {
SWAP_EXACT_ETH_FOR_TOKENS_SELECTOR,
BOILERPLATE_DUMMY_SELECTOR_2,
POAP_DUMMY_SELECTOR_2,
};

// Function to dispatch calls from the ethereum app.
Expand Down
8 changes: 4 additions & 4 deletions src/boilerplate_plugin.h → src/poap_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

// Name of the plugin.
// EDIT THIS: Replace with your plugin name.
#define PLUGIN_NAME "Boilerplate"
#define PLUGIN_NAME "Poap"

// Enumeration of the different selectors possible.
// Should follow the exact same order as the array declared in main.c
// EDIT THIS: Change the naming (`selector_t`), and add your selector names.
typedef enum {
SWAP_EXACT_ETH_FOR_TOKENS = 0,
BOILERPLATE_DUMMY_2,
POAP_DUMMY_2,
} selector_t;

// Enumeration used to parse the smart contract data.
Expand All @@ -31,8 +31,8 @@ typedef enum {
UNEXPECTED_PARAMETER,
} parameter;

// EDIT THIS: Rename `BOILERPLATE` to be the same as the one initialized in `main.c`.
extern const uint8_t *const BOILERPLATE_SELECTORS[NUM_SELECTORS];
// EDIT THIS: Rename `POAP` to be the same as the one initialized in `main.c`.
extern const uint8_t *const POAP_SELECTORS[NUM_SELECTORS];

// Shared global memory with Ethereum app. Must be at most 5 * 32 bytes.
// EDIT THIS: This struct is used by your plugin to save the parameters you parse. You
Expand Down
10 changes: 5 additions & 5 deletions tests/boilerplate/b2c.json → tests/poap/b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"path.1"
],
"method": "swapExactETHForTokens",
"plugin": "Boilerplate"
}
}
}
"plugin": "Poap"
}
}
}
],
"name": "Boilerplate"
"name": "Poap"
}
14 changes: 7 additions & 7 deletions tests/src/generate_plugin_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// You will also need to create a `b2c.json` file that will hold the methodIDs and location of
// the erc20 tokens that should get displayed.
// EDIT THIS: replace with the name of your plugin (lowercase)
const pluginFolder = "boilerplate";
const pluginFolder = "poap";

function serialize_data(pluginName, contractAddress, selector) {
const len = Buffer.from([pluginName.length]);
Expand All @@ -22,10 +22,10 @@ function assert(condition, message) {

// Function to generate the plugin configuration.
function generate_plugin_config() {

var fs = require('fs');
var files = fs.readdirSync(`${pluginFolder}/abis/`);

// `contracts_to_abis` holds a maping of contract addresses to abis
let contracts_to_abis = {};
for (let abiFileName of files) {
Expand All @@ -38,12 +38,12 @@ function generate_plugin_config() {
// Add it to contracts
contracts_to_abis[contractAddress] = abi;
}

// Load the b2c.json file
const b2c = require(`../${pluginFolder}/b2c.json`);

let res = {};

// Place holder signature
const PLACE_HOLDER_SIGNATURE = "3045022100f6e1a922c745e244fa3ed9a865491672808ef93f492ee0410861d748c5de201f0220160d6522499f3a84fa3e744b3b81e49e129e997b28495e58671a1169b16fa777";

Expand All @@ -67,7 +67,7 @@ function generate_plugin_config() {


// Put them in `methods_info`
methods_info[selector] = {"erc20OfInterest": values["erc20OfInterest"], "plugin": pluginName, "serialized_data": serializedData, "signature": signature};
methods_info[selector] = { "erc20OfInterest": values["erc20OfInterest"], "plugin": pluginName, "serialized_data": serializedData, "signature": signature };
}
// Add the abi to methods_info
methods_info["abi"] = contracts_to_abis[contractAddress];
Expand Down
10 changes: 5 additions & 5 deletions tests/src/swap_exact_eth_for_tokens.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import "core-js/stable";
import "regenerator-runtime/runtime";
import { waitForAppScreen, zemu, genericTx, SPECULOS_ADDRESS, RANDOM_ADDRESS, txFromEtherscan} from './test.fixture';
import { waitForAppScreen, zemu, genericTx, SPECULOS_ADDRESS, RANDOM_ADDRESS, txFromEtherscan } from './test.fixture';
import { ethers } from "ethers";
import { parseEther, parseUnits} from "ethers/lib/utils";
import { parseEther, parseUnits } from "ethers/lib/utils";

// EDIT THIS: Replace with your contract address
const contractAddr = "0x7a250d5630b4cf539739df2c5dacb4c659f2488d";
// EDIT THIS: Replace `boilerplate` with your plugin name
const pluginName = "boilerplate";
// EDIT THIS: Replace `poap` with your plugin name
const pluginName = "poap";
const abi_path = `../${pluginName}/abis/` + contractAddr + '.json';
const abi = require(abi_path);

Expand All @@ -32,7 +32,7 @@ test('[Nano S] Swap Exact Eth For Tokens with beneficiary', zemu("nanos", async
// EDIT THIS: adapt the signature to your method
// signature: swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
// EDIT THIS: don't call `swapExactETHForTokens` but your own method and adapt the arguments.
const {data} = await contract.populateTransaction.swapExactETHForTokens(amountOutMin, path, beneficiary, deadline);
const { data } = await contract.populateTransaction.swapExactETHForTokens(amountOutMin, path, beneficiary, deadline);

// Get the generic transaction template
let unsignedTx = genericTx;
Expand Down
12 changes: 6 additions & 6 deletions tests/src/test.fixture.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Zemu from '@zondax/zemu';
import Eth from '@ledgerhq/hw-app-eth';
import { generate_plugin_config } from './generate_plugin_config';
import { parseEther, parseUnits, RLP} from "ethers/lib/utils";
import { parseEther, parseUnits, RLP } from "ethers/lib/utils";

const transactionUploadDelay = 60000;

Expand All @@ -24,11 +24,11 @@ const NANOX_ETH_PATH = Resolve('elfs/ethereum_nanox.elf');
const NANOS_PLUGIN_PATH = Resolve('elfs/plugin_nanos.elf');
const NANOX_PLUGIN_PATH = Resolve('elfs/plugin_nanox.elf');

// Edit this: replace `Boilerplate` by your plugin name
const NANOS_PLUGIN = { "Boilerplate": NANOS_PLUGIN_PATH };
const NANOX_PLUGIN = { "Boilerplate": NANOX_PLUGIN_PATH };
// Edit this: replace `Poap` by your plugin name
const NANOS_PLUGIN = { "Poap": NANOS_PLUGIN_PATH };
const NANOX_PLUGIN = { "Poap": NANOX_PLUGIN_PATH };

const boilerplateJSON = generate_plugin_config();
const poapJSON = generate_plugin_config();

const SPECULOS_ADDRESS = '0xFE984369CE3919AA7BB4F431082D027B4F8ED70C';
const RANDOM_ADDRESS = '0xaaaabbbbccccddddeeeeffffgggghhhhiiiijjjj'
Expand Down Expand Up @@ -100,7 +100,7 @@ function zemu(device, func) {
const eth = new Eth(transport);
eth.setPluginsLoadConfig({
baseURL: null,
extraPlugins: boilerplateJSON,
extraPlugins: poapJSON,
});
await func(sim, eth);
} finally {
Expand Down

0 comments on commit 1992e09

Please sign in to comment.