diff --git a/Makefile b/Makefile index 48fc9ad..efda34d 100755 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 ################ @@ -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 diff --git a/icons/nanos_app_boilerplate.gif b/icons/nanos_app_poap.gif similarity index 100% rename from icons/nanos_app_boilerplate.gif rename to icons/nanos_app_poap.gif diff --git a/icons/nanox_app_boilerplate.gif b/icons/nanox_app_poap.gif similarity index 100% rename from icons/nanox_app_boilerplate.gif rename to icons/nanox_app_poap.gif diff --git a/src/handle_finalize.c b/src/handle_finalize.c index f6ba228..02de734 100644 --- a/src/handle_finalize.c +++ b/src/handle_finalize.c @@ -1,4 +1,4 @@ -#include "boilerplate_plugin.h" +#include "poap_plugin.h" void handle_finalize(void *parameters) { ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters; diff --git a/src/handle_init_contract.c b/src/handle_init_contract.c index b99479e..d35c507 100644 --- a/src/handle_init_contract.c +++ b/src/handle_init_contract.c @@ -1,4 +1,4 @@ -#include "boilerplate_plugin.h" +#include "poap_plugin.h" // Called once to init. void handle_init_contract(void *parameters) { @@ -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; } @@ -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: diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index b84abe6..35ba855 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -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... @@ -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); diff --git a/src/handle_provide_token.c b/src/handle_provide_token.c index c90fb74..e5e5e31 100644 --- a/src/handle_provide_token.c +++ b/src/handle_provide_token.c @@ -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 diff --git a/src/handle_query_contract_id.c b/src/handle_query_contract_id.c index 85a6bfb..76d27a8 100644 --- a/src/handle_query_contract_id.c +++ b/src/handle_query_contract_id.c @@ -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) { diff --git a/src/handle_query_contract_ui.c b/src/handle_query_contract_ui.c index 0b67cf2..18160b4 100644 --- a/src/handle_query_contract_ui.c +++ b/src/handle_query_contract_ui.c @@ -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. diff --git a/src/main.c b/src/main.c index d1c0422..ed16520 100644 --- a/src/main.c +++ b/src/main.c @@ -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. diff --git a/src/boilerplate_plugin.h b/src/poap_plugin.h similarity index 91% rename from src/boilerplate_plugin.h rename to src/poap_plugin.h index b35f3cd..8480c86 100644 --- a/src/boilerplate_plugin.h +++ b/src/poap_plugin.h @@ -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. @@ -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 diff --git a/tests/boilerplate/abis/0x7a250d5630b4cf539739df2c5dacb4c659f2488d.json b/tests/poap/abis/0x7a250d5630b4cf539739df2c5dacb4c659f2488d.json similarity index 100% rename from tests/boilerplate/abis/0x7a250d5630b4cf539739df2c5dacb4c659f2488d.json rename to tests/poap/abis/0x7a250d5630b4cf539739df2c5dacb4c659f2488d.json diff --git a/tests/boilerplate/b2c.json b/tests/poap/b2c.json similarity index 79% rename from tests/boilerplate/b2c.json rename to tests/poap/b2c.json index 9542655..d542490 100644 --- a/tests/boilerplate/b2c.json +++ b/tests/poap/b2c.json @@ -10,10 +10,10 @@ "path.1" ], "method": "swapExactETHForTokens", - "plugin": "Boilerplate" - } - } - } + "plugin": "Poap" + } + } + } ], - "name": "Boilerplate" + "name": "Poap" } \ No newline at end of file diff --git a/tests/src/generate_plugin_config.js b/tests/src/generate_plugin_config.js index 35b4c53..ed72d88 100644 --- a/tests/src/generate_plugin_config.js +++ b/tests/src/generate_plugin_config.js @@ -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]); @@ -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) { @@ -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"; @@ -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]; diff --git a/tests/src/swap_exact_eth_for_tokens.test.js b/tests/src/swap_exact_eth_for_tokens.test.js index 3feddd9..5edc465 100644 --- a/tests/src/swap_exact_eth_for_tokens.test.js +++ b/tests/src/swap_exact_eth_for_tokens.test.js @@ -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); @@ -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; diff --git a/tests/src/test.fixture.js b/tests/src/test.fixture.js index b5c8dfa..850ed65 100644 --- a/tests/src/test.fixture.js +++ b/tests/src/test.fixture.js @@ -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; @@ -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' @@ -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 {