From 6c7f5fa8d218c78b29b380532e972ace1fd1f528 Mon Sep 17 00:00:00 2001 From: Evgeniy Filatov Date: Wed, 7 Nov 2018 17:59:35 +0200 Subject: [PATCH] initial commit --- .gitignore | 7 + app/css/.gitkeep | 0 app/images/.gitkeep | 0 app/index.html | 11 + app/js/.gitkeep | 0 app/js/index.js | 6 + babel-loader-overrides.js | 29 +++ config/blockchain.js | 120 +++++++++++ config/communication.js | 46 +++++ config/contracts.js | 72 +++++++ config/development/devpassword | 1 + config/development/password | 1 + config/namesystem.js | 39 ++++ config/pipeline.js | 23 +++ config/privatenet/genesis-parity.json | 147 ++++++++++++++ config/privatenet/genesis.json | 18 ++ config/privatenet/password | 1 + config/storage.js | 59 ++++++ config/testnet/password | 1 + config/webserver.js | 6 + contracts/.gitkeep | 0 embark.json | 24 +++ package-lock.json | 5 + package.json | 12 ++ test/contract_spec.js | 43 ++++ webpack.config.js | 276 ++++++++++++++++++++++++++ 26 files changed, 947 insertions(+) create mode 100644 .gitignore create mode 100644 app/css/.gitkeep create mode 100644 app/images/.gitkeep create mode 100644 app/index.html create mode 100644 app/js/.gitkeep create mode 100644 app/js/index.js create mode 100644 babel-loader-overrides.js create mode 100644 config/blockchain.js create mode 100644 config/communication.js create mode 100644 config/contracts.js create mode 100644 config/development/devpassword create mode 100644 config/development/password create mode 100644 config/namesystem.js create mode 100644 config/pipeline.js create mode 100644 config/privatenet/genesis-parity.json create mode 100644 config/privatenet/genesis.json create mode 100644 config/privatenet/password create mode 100644 config/storage.js create mode 100644 config/testnet/password create mode 100644 config/webserver.js create mode 100644 contracts/.gitkeep create mode 100644 embark.json create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 test/contract_spec.js create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..72a305e --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.embark +chains.json +config/production/password +config/livenet/password +coverage +dist +node_modules diff --git a/app/css/.gitkeep b/app/css/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/images/.gitkeep b/app/images/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..8068e7c --- /dev/null +++ b/app/index.html @@ -0,0 +1,11 @@ + + + Embark + + + + +

Welcome to Embark!

+

See the Embark's documentation to see what you can do with Embark!

+ + diff --git a/app/js/.gitkeep b/app/js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/js/index.js b/app/js/index.js new file mode 100644 index 0000000..5b0f64d --- /dev/null +++ b/app/js/index.js @@ -0,0 +1,6 @@ +import EmbarkJS from 'Embark/EmbarkJS'; + +// import your contracts +// e.g if you have a contract named SimpleStorage: +//import SimpleStorage from 'Embark/contracts/SimpleStorage'; + diff --git a/babel-loader-overrides.js b/babel-loader-overrides.js new file mode 100644 index 0000000..a9c5c75 --- /dev/null +++ b/babel-loader-overrides.js @@ -0,0 +1,29 @@ +/** + * This source code was adapted from: + * https://github.com/facebook/create-react-app/blob/v2.0.4/packages/babel-preset-react-app/webpack-overrides.js + * + * Copyright (c) 2015-present, Facebook, Inc. + * + * The MIT license for this code may be found on GitHub: + * https://github.com/facebook/create-react-app/blob/v2.0.4/packages/babel-preset-react-app/LICENSE + */ + +const crypto = require('crypto'); +const macroCheck = new RegExp('[./]macro'); + +module.exports = function () { + return { + config(config, {source}) { + // don't cache babel macros + // https://github.com/babel/babel/issues/8497 + if (macroCheck.test(source)) { + return Object.assign({}, config.options, { + caller: Object.assign({}, config.options.caller, { + macroInvalidationToken: crypto.randomBytes(32).toString('hex') + }) + }); + } + return config.options; + } + }; +}; diff --git a/config/blockchain.js b/config/blockchain.js new file mode 100644 index 0000000..b51d5b4 --- /dev/null +++ b/config/blockchain.js @@ -0,0 +1,120 @@ +module.exports = { + // applies to all environments + default: { + enabled: true, + rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") + rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) + rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced) + // When set to "auto", Embark will automatically set the cors to the address of the webserver + wsRPC: true, // Enable the WS-RPC server + wsOrigins: "auto", // Origins from which to accept websockets requests + // When set to "auto", Embark will automatically set the cors to the address of the webserver + wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") + wsPort: 8546 // WS-RPC server listening port (default: 8546) + }, + + // default environment, merges with the settings in default + // assumed to be the intended environment by `embark run` and `embark blockchain` + development: { + ethereumClientName: "geth", // Can be geth or parity (default:geth) + //ethereumClientBin: "geth", // path to the client binary. Useful if it is not in the global PATH + networkType: "custom", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId + networkId: 1337, // Network id used when networkType is custom + isDev: true, // Uses and ephemeral proof-of-authority network with a pre-funded developer account, mining enabled + datadir: ".embark/development/datadir", // Data directory for the databases and keystore (Geth 1.8.15 and Parity 2.0.4 can use the same base folder, till now they does not conflict with each other) + mineWhenNeeded: true, // Uses our custom script (if isDev is false) to mine only when needed + nodiscover: true, // Disables the peer discovery mechanism (manual peer addition) + maxpeers: 0, // Maximum number of network peers (network disabled if set to 0) (default: 25) + proxy: true, // Proxy is used to present meaningful information about transactions + targetGasLimit: 8000000, // Target gas limit sets the artificial target gas floor for the blocks to mine + simulatorMnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", // Mnemonic used by the simulator to generate a wallet + simulatorBlocktime: 0, // Specify blockTime in seconds for automatic mining. Default is 0 and no auto-mining. + account: { + // numAccounts: 3, // When specified, creates accounts for use in the dapp. This option only works in the development environment, and can be used as a quick start option that bypasses the need for MetaMask in development. These accounts are unlocked and funded with the below settings. + // password: "config/development/password", // Password for the created accounts (as specified in the `numAccounts` setting). If `mineWhenNeeded` is enabled (and isDev is not), this password is used to create a development account controlled by the node. + // balance: "5 ether", // Balance to be given to the created accounts (as specified in the `numAccounts` setting) + devPassword: "config/development/devpassword" // [Parity-only] File with a void line to unlock the Parity dev account + } + }, + + // merges with the settings in default + // used with "embark run privatenet" and/or "embark blockchain privatenet" + privatenet: { + networkType: "custom", + networkId: 1337, + isDev: false, + datadir: ".embark/privatenet/datadir", + // -- mineWhenNeeded -- + // This options is only valid when isDev is false. + // Enabling this option uses our custom script to mine only when needed. + // Embark creates a development account for you (using `geth account new`) and funds the account. This account can be used for + // development (and even imported in to MetaMask). To enable correct usage, a password for this account must be specified + // in the `account > password` setting below. + // NOTE: once `mineWhenNeeded` is enabled, you must run an `embark reset` on your dApp before running + // `embark blockchain` or `embark run` for the first time. + mineWhenNeeded: true, + // -- genesisBlock -- + // This option is only valid when mineWhenNeeded is true (which is only valid if isDev is false). + // When enabled, geth uses POW to mine transactions as it would normally, instead of using POA as it does in --dev mode. + // On the first `embark blockchain or embark run` after this option is enabled, geth will create a new chain with a + // genesis block, which can be configured using the `genesisBlock` configuration option below. + genesisBlock: "config/privatenet/genesis.json", // Genesis block to initiate on first creation of a development node + nodiscover: true, + maxpeers: 0, + proxy: true, + account: { + // address: "", // When specified, uses that address instead of the default one for the network + password: "config/privatenet/password" // Password to unlock the account + }, + targetGasLimit: 8000000, + simulatorMnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", + simulatorBlocktime: 0 + }, + + privateparitynet: { + ethereumClientName: "parity", + networkType: "custom", + networkId: 1337, + isDev: false, + genesisBlock: "config/privatenet/genesis-parity.json", // Genesis block to initiate on first creation of a development node + datadir: ".embark/privatenet/datadir", + mineWhenNeeded: false, + nodiscover: true, + maxpeers: 0, + proxy: true, + account: { + // address: "", // When specified, uses that address instead of the default one for the network + password: "config/privatenet/password" // Password to unlock the account + }, + targetGasLimit: 8000000, + simulatorMnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", + simulatorBlocktime: 0 + }, + + // merges with the settings in default + // used with "embark run testnet" and/or "embark blockchain testnet" + testnet: { + networkType: "testnet", + syncMode: "light", + account: { + password: "config/testnet/password" + } + }, + + // merges with the settings in default + // used with "embark run livenet" and/or "embark blockchain livenet" + livenet: { + networkType: "livenet", + syncMode: "light", + rpcCorsDomain: "http://localhost:8000", + wsOrigins: "http://localhost:8000", + account: { + password: "config/livenet/password" + } + } + + // you can name an environment with specific settings and then specify with + // "embark run custom_name" or "embark blockchain custom_name" + //custom_name: { + //} +}; diff --git a/config/communication.js b/config/communication.js new file mode 100644 index 0000000..c401dcd --- /dev/null +++ b/config/communication.js @@ -0,0 +1,46 @@ +module.exports = { + // default applies to all environments + default: { + enabled: true, + provider: "whisper", // Communication provider. Currently, Embark only supports whisper + available_providers: ["whisper"], // Array of available providers + }, + + // default environment, merges with the settings in default + // assumed to be the intended environment by `embark run` + development: { + connection: { + host: "localhost", // Host of the blockchain node + port: 8546, // Port of the blockchain node + type: "ws" // Type of connection (ws or rpc) + } + }, + + // merges with the settings in default + // used with "embark run privatenet" + privatenet: { + }, + + // merges with the settings in default + // used with "embark run testnet" + testnet: { + }, + + // merges with the settings in default + // used with "embark run livenet" + livenet: { + }, + + // you can name an environment with specific settings and then specify with + // "embark run custom_name" + //custom_name: { + //} + // Use this section when you need a specific symmetric or private keys in whisper + /* + ,keys: { + symmetricKey: "your_symmetric_key",// Symmetric key for message decryption + privateKey: "your_private_key" // Private Key to be used as a signing key and for message decryption + } + */ + //} +}; diff --git a/config/contracts.js b/config/contracts.js new file mode 100644 index 0000000..29828c2 --- /dev/null +++ b/config/contracts.js @@ -0,0 +1,72 @@ +module.exports = { + // default applies to all environments + default: { + // Blockchain node to deploy the contracts + deployment: { + host: "localhost", // Host of the blockchain node + port: 8545, // Port of the blockchain node + type: "rpc" // Type of connection (ws or rpc), + // Accounts to use instead of the default account to populate your wallet + /*,accounts: [ + { + privateKey: "your_private_key", + balance: "5 ether" // You can set the balance of the account in the dev environment + // Balances are in Wei, but you can specify the unit with its name + }, + { + privateKeyFile: "path/to/file", // Either a keystore or a list of keys, separated by , or ; + password: "passwordForTheKeystore" // Needed to decrypt the keystore file + }, + { + mnemonic: "12 word mnemonic", + addressIndex: "0", // Optionnal. The index to start getting the address + numAddresses: "1", // Optionnal. The number of addresses to get + hdpath: "m/44'/60'/0'/0/" // Optionnal. HD derivation path + } + ]*/ + }, + // order of connections the dapp should connect to + dappConnection: [ + "$WEB3", // uses pre existing web3 object if available (e.g in Mist) + "ws://localhost:8546", + "http://localhost:8545" + ], + gas: "auto", + contracts: { + // example: + //SimpleStorage: { + // args: [ 100 ] + //} + } + }, + + // default environment, merges with the settings in default + // assumed to be the intended environment by `embark run` + development: { + dappConnection: [ + "ws://localhost:8546", + "http://localhost:8545", + "$WEB3" // uses pre existing web3 object if available (e.g in Mist) + ] + }, + + // merges with the settings in default + // used with "embark run privatenet" + privatenet: { + }, + + // merges with the settings in default + // used with "embark run testnet" + testnet: { + }, + + // merges with the settings in default + // used with "embark run livenet" + livenet: { + }, + + // you can name an environment with specific settings and then specify with + // "embark run custom_name" or "embark blockchain custom_name" + //custom_name: { + //} +}; diff --git a/config/development/devpassword b/config/development/devpassword new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/config/development/devpassword @@ -0,0 +1 @@ + diff --git a/config/development/password b/config/development/password new file mode 100644 index 0000000..fca906b --- /dev/null +++ b/config/development/password @@ -0,0 +1 @@ +dev_password \ No newline at end of file diff --git a/config/namesystem.js b/config/namesystem.js new file mode 100644 index 0000000..f3d1446 --- /dev/null +++ b/config/namesystem.js @@ -0,0 +1,39 @@ +module.exports = { + // default applies to all environments + default: { + enabled: true, + available_providers: ["ens"], + provider: "ens" + }, + + // default environment, merges with the settings in default + // assumed to be the intended environment by `embark run` + development: { + register: { + rootDomain: "embark.eth", + subdomains: { + 'status': '0x1a2f3b98e434c02363f3dac3174af93c1d690914' + } + } + }, + + // merges with the settings in default + // used with "embark run privatenet" + privatenet: { + }, + + // merges with the settings in default + // used with "embark run testnet" + testnet: { + }, + + // merges with the settings in default + // used with "embark run livenet" + livenet: { + }, + + // you can name an environment with specific settings and then specify with + // "embark run custom_name" or "embark blockchain custom_name" + //custom_name: { + //} +}; diff --git a/config/pipeline.js b/config/pipeline.js new file mode 100644 index 0000000..ec2a187 --- /dev/null +++ b/config/pipeline.js @@ -0,0 +1,23 @@ +// Embark has support for Flow enabled by default in its built-in webpack +// config: type annotations will automatically be stripped out of DApp sources +// without any additional configuration. Note that type checking is not +// performed during builds. + +// To enable Flow type checking refer to the preconfigured template: +// https://github.com/embark-framework/embark-flow-template +// A new DApp can be created from that template with: +// embark new --template flow + +module.exports = { + typescript: false + // Setting `typescript: true` in this config will disable Flow support in + // Embark's default webpack config and enable TypeScript support: .ts and + // .tsx sources will automatically be transpiled into JavaScript without any + // additional configuration. Note that type checking is not performed during + // builds. + + // To enable TypeScript type checking refer to the preconfigured template: + // https://github.com/embark-framework/embark-typescript-template + // A new DApp can be created from that template with: + // embark new --template typescript +}; diff --git a/config/privatenet/genesis-parity.json b/config/privatenet/genesis-parity.json new file mode 100644 index 0000000..03f574b --- /dev/null +++ b/config/privatenet/genesis-parity.json @@ -0,0 +1,147 @@ +{ + "name": "DevelopmentChain", + "engine": { + "instantSeal": null + }, + "params": { + "gasLimitBoundDivisor": "0x0400", + "accountStartNonce": "0x0", + "maximumExtraDataSize": "0x20", + "minGasLimit": "0x1388", + "networkID": "0x11", + "registrar": "0x0000000000000000000000000000000000001337", + "eip150Transition": "0x0", + "eip160Transition": "0x0", + "eip161abcTransition": "0x0", + "eip161dTransition": "0x0", + "eip155Transition": "0x0", + "eip98Transition": "0x7fffffffffffff", + "eip86Transition": "0x7fffffffffffff", + "maxCodeSize": 24576, + "maxCodeSizeTransition": "0x0", + "eip140Transition": "0x0", + "eip211Transition": "0x0", + "eip214Transition": "0x0", + "eip658Transition": "0x0", + "wasmActivationTransition": "0x0" + }, + "genesis": { + "seal": { + "generic": "0x0" + }, + "difficulty": "0x20000", + "author": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x7A1200" + }, + "accounts": { + "0000000000000000000000000000000000000001": { + "balance": "1", + "builtin": { + "name": "ecrecover", + "pricing": { + "linear": { + "base": 3000, + "word": 0 + } + } + } + }, + "0000000000000000000000000000000000000002": { + "balance": "1", + "builtin": { + "name": "sha256", + "pricing": { + "linear": { + "base": 60, + "word": 12 + } + } + } + }, + "0000000000000000000000000000000000000003": { + "balance": "1", + "builtin": { + "name": "ripemd160", + "pricing": { + "linear": { + "base": 600, + "word": 120 + } + } + } + }, + "0000000000000000000000000000000000000004": { + "balance": "1", + "builtin": { + "name": "identity", + "pricing": { + "linear": { + "base": 15, + "word": 3 + } + } + } + }, + "0000000000000000000000000000000000000005": { + "balance": "1", + "builtin": { + "name": "modexp", + "activate_at": 0, + "pricing": { + "modexp": { + "divisor": 20 + } + } + } + }, + "0000000000000000000000000000000000000006": { + "balance": "1", + "builtin": { + "name": "alt_bn128_add", + "activate_at": 0, + "pricing": { + "linear": { + "base": 500, + "word": 0 + } + } + } + }, + "0000000000000000000000000000000000000007": { + "balance": "1", + "builtin": { + "name": "alt_bn128_mul", + "activate_at": 0, + "pricing": { + "linear": { + "base": 40000, + "word": 0 + } + } + } + }, + "0000000000000000000000000000000000000008": { + "balance": "1", + "builtin": { + "name": "alt_bn128_pairing", + "activate_at": 0, + "pricing": { + "alt_bn128_pairing": { + "base": 100000, + "pair": 80000 + } + } + } + }, + "0000000000000000000000000000000000001337": { + "balance": "1", + "constructor": "0x606060405233600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550670de0b6b3a764000060035534610000575b612904806100666000396000f3006060604052361561013c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306b2ff471461014157806313af40351461018c57806319362a28146101bf5780633f3935d114610248578063432ced04146102b75780634f39ca59146102eb5780636795dbcd1461032457806369fe0e2d146103c857806379ce9fac146103fd5780638da5cb5b1461045557806390b97fc1146104a457806392698814146105245780639890220b1461055d578063ac4e73f914610584578063ac72c12014610612578063c3a358251461064b578063ddca3f43146106c3578063deb931a2146106e6578063df57b74214610747578063e30bd740146107a8578063eadf976014610862578063ef5454d6146108e7578063f25eb5c114610975578063f6d339e414610984575b610000565b3461000057610172600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610a1f565b604051808215151515815260200191505060405180910390f35b34610000576101bd600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610a81565b005b346100005761022e60048080356000191690602001909190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803560001916906020019091905050610ba2565b604051808215151515815260200191505060405180910390f35b346100005761029d600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610dc9565b604051808215151515815260200191505060405180910390f35b6102d1600480803560001916906020019091905050611035565b604051808215151515815260200191505060405180910390f35b346100005761030a60048080356000191690602001909190505061115f565b604051808215151515815260200191505060405180910390f35b346100005761038660048080356000191690602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050611378565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34610000576103e3600480803590602001909190505061140d565b604051808215151515815260200191505060405180910390f35b346100005761043b60048080356000191690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506114b4565b604051808215151515815260200191505060405180910390f35b34610000576104626115fb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b346100005761050660048080356000191690602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050611621565b60405180826000191660001916815260200191505060405180910390f35b34610000576105436004808035600019169060200190919050506116b2565b604051808215151515815260200191505060405180910390f35b346100005761056a611715565b604051808215151515815260200191505060405180910390f35b34610000576105f8600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611824565b604051808215151515815260200191505060405180910390f35b3461000057610631600480803560001916906020019091905050611d8b565b604051808215151515815260200191505060405180910390f35b34610000576106ad60048080356000191690602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050611dee565b6040518082815260200191505060405180910390f35b34610000576106d0611e83565b6040518082815260200191505060405180910390f35b3461000057610705600480803560001916906020019091905050611e89565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3461000057610766600480803560001916906020019091905050611ed2565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34610000576107d9600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611f1b565b6040518080602001828103825283818151815260200191508051906020019080838360008314610828575b80518252602083111561082857602082019150602081019050602083039250610804565b505050905090810190601f1680156108545780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34610000576108cd60048080356000191690602001909190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803590602001909190505061200c565b604051808215151515815260200191505060405180910390f35b346100005761095b600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612236565b604051808215151515815260200191505060405180910390f35b3461000057610982612425565b005b3461000057610a0560048080356000191690602001909190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612698565b604051808215151515815260200191505060405180910390f35b60006000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805460018160011615610100020316600290049050141590505b919050565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610add57610b9f565b8073ffffffffffffffffffffffffffffffffffffffff16600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f70aea8d848e8a90fb7661b227dc522eb6395c3dac71b63cb59edd5c9899b236460405180905060405180910390a380600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b5b50565b6000833373ffffffffffffffffffffffffffffffffffffffff1660016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141515610c1d57610dc1565b82600160008760001916600019168152602001908152602001600020600201856040518082805190602001908083835b60208310610c705780518252602082019150602081019050602083039250610c4d565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390208160001916905550836040518082805190602001908083835b60208310610cdf5780518252602082019150602081019050602083039250610cbc565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902085600019167fb829c3e412537bbe794c048ccb9e4605bb4aaaa8e4d4c15c1a6e0c2adc1716ea866040518080602001828103825283818151815260200191508051906020019080838360008314610d82575b805182526020831115610d8257602082019150602081019050602083039250610d5e565b505050905090810190601f168015610dae5780820380516001836020036101000a031916815260200191505b509250505060405180910390a3600191505b5b509392505050565b6000813373ffffffffffffffffffffffffffffffffffffffff1660016000836040518082805190602001908083835b60208310610e1b5780518252602082019150602081019050602083039250610df8565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390206000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141515610ea45761102f565b82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610f2d57805160ff1916838001178555610f5b565b82800160010185558215610f5b579182015b82811115610f5a578251825591602001919060010190610f3f565b5b509050610f8091905b80821115610f7c576000816000905550600101610f64565b5090565b50503373ffffffffffffffffffffffffffffffffffffffff16836040518082805190602001908083835b60208310610fcd5780518252602082019150602081019050602083039250610faa565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390207f098ae8581bb8bd9af1beaf7f2e9f51f31a8e5a8bfada4e303a645d71d9c9192060405180905060405180910390a3600191505b5b50919050565b600081600060016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614151561109b57611159565b6003543410156110aa57611158565b3360016000856000191660001916815260200190815260200160002060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055503373ffffffffffffffffffffffffffffffffffffffff1683600019167f4963513eca575aba66fdcd25f267aae85958fe6fb97e75fa25d783f1a091a22160405180905060405180910390a3600191505b5b5b50919050565b6000813373ffffffffffffffffffffffffffffffffffffffff1660016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156111da57611372565b6002600060016000866000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805460018160011615610100020316600290046000825580601f1061127c57506112b3565b601f0160209004906000526020600020908101906112b291905b808211156112ae576000816000905550600101611296565b5090565b5b5060016000846000191660001916815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550503373ffffffffffffffffffffffffffffffffffffffff1683600019167fef1961b4d2909dc23643b309bfe5c3e5646842d98c3a58517037ef3871185af360405180905060405180910390a3600191505b5b50919050565b6000600160008460001916600019168152602001908152602001600020600201826040518082805190602001908083835b602083106113cc57805182526020820191506020810190506020830392506113a9565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020546001900490505b92915050565b6000600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561146b576114af565b816003819055507f6bbc57480a46553fa4d156ce702beef5f3ad66303b0ed1a5d4cb44966c6584c3826040518082815260200191505060405180910390a1600190505b5b919050565b6000823373ffffffffffffffffffffffffffffffffffffffff1660016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614151561152f576115f4565b8260016000866000191660001916815260200190815260200160002060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1685600019167f7b97c62130aa09acbbcbf7482630e756592496f1759eaf702f469cf64dfb779460405180905060405180910390a4600191505b5b5092915050565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600160008460001916600019168152602001908152602001600020600201826040518082805190602001908083835b602083106116755780518252602082019150602081019050602083039250611652565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390205490505b92915050565b6000600060016000846000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141590505b919050565b6000600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561177357611821565b7fdef931299fe61d176f949118058530c1f3f539dcb6950b4e372c9b835c33ca073073ffffffffffffffffffffffffffffffffffffffff16316040518082815260200191505060405180910390a13373ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051809050600060405180830381858888f19350505050151561181b57610000565b600190505b5b90565b60006000836040518082805190602001908083835b6020831061185c5780518252602082019150602081019050602083039250611839565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390203373ffffffffffffffffffffffffffffffffffffffff1660016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614151561190157611d83565b846040518082805190602001908083835b602083106119355780518252602082019150602081019050602083039250611912565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390209150600060016000846000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614158015611ab4575081600019166002600060016000866000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518082805460018160011615610100020316600290048015611aa15780601f10611a7f576101008083540402835291820191611aa1565b820191906000526020600020905b815481529060010190602001808311611a8d575b5050915050604051809103902060001916145b15611c79576002600060016000856000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805460018160011615610100020316600290046000825580601f10611b5b5750611b92565b601f016020900490600052602060002090810190611b9191905b80821115611b8d576000816000905550600101611b75565b5090565b5b5060016000836000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16856040518082805190602001908083835b60208310611c1c5780518252602082019150602081019050602083039250611bf9565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390207f12491ad95fd945e444d88a894ffad3c21959880a4dcd8af99d4ae4ffc71d4abd60405180905060405180910390a35b8360016000846000191660001916815260200190815260200160002060010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508373ffffffffffffffffffffffffffffffffffffffff16856040518082805190602001908083835b60208310611d215780518252602082019150602081019050602083039250611cfe565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390207f728435a0031f6a04538fcdd24922a7e06bc7bc945db03e83d22122d1bc5f28df60405180905060405180910390a3600192505b5b505092915050565b6000600060016000846000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141590505b919050565b6000600160008460001916600019168152602001908152602001600020600201826040518082805190602001908083835b60208310611e425780518252602082019150602081019050602083039250611e1f565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020546001900490505b92915050565b60035481565b600060016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505b919050565b600060016000836000191660001916815260200190815260200160002060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505b919050565b6020604051908101604052806000815250600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015611fff5780601f10611fd457610100808354040283529160200191611fff565b820191906000526020600020905b815481529060010190602001808311611fe257829003601f168201915b505050505090505b919050565b6000833373ffffffffffffffffffffffffffffffffffffffff1660016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156120875761222e565b82600102600160008760001916600019168152602001908152602001600020600201856040518082805190602001908083835b602083106120dd57805182526020820191506020810190506020830392506120ba565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390208160001916905550836040518082805190602001908083835b6020831061214c5780518252602082019150602081019050602083039250612129565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902085600019167fb829c3e412537bbe794c048ccb9e4605bb4aaaa8e4d4c15c1a6e0c2adc1716ea8660405180806020018281038252838181518152602001915080519060200190808383600083146121ef575b8051825260208311156121ef576020820191506020810190506020830392506121cb565b505050905090810190601f16801561221b5780820380516001836020036101000a031916815260200191505b509250505060405180910390a3600191505b5b509392505050565b6000600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156122945761241f565b82600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061231d57805160ff191683800117855561234b565b8280016001018555821561234b579182015b8281111561234a57825182559160200191906001019061232f565b5b50905061237091905b8082111561236c576000816000905550600101612354565b5090565b50508173ffffffffffffffffffffffffffffffffffffffff16836040518082805190602001908083835b602083106123bd578051825260208201915060208101905060208303925061239a565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390207f098ae8581bb8bd9af1beaf7f2e9f51f31a8e5a8bfada4e303a645d71d9c9192060405180905060405180910390a3600190505b5b92915050565b3373ffffffffffffffffffffffffffffffffffffffff16600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060405180828054600181600116156101000203166002900480156124d65780601f106124b45761010080835404028352918201916124d6565b820191906000526020600020905b8154815290600101906020018083116124c2575b505091505060405180910390207f12491ad95fd945e444d88a894ffad3c21959880a4dcd8af99d4ae4ffc71d4abd60405180905060405180910390a360016000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060405180828054600181600116156101000203166002900480156125b05780601f1061258e5761010080835404028352918201916125b0565b820191906000526020600020905b81548152906001019060200180831161259c575b505091505060405180910390206000191660001916815260200190815260200160002060010160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805460018160011615610100020316600290046000825580601f1061265d5750612694565b601f01602090049060005260206000209081019061269391905b8082111561268f576000816000905550600101612677565b5090565b5b505b565b6000833373ffffffffffffffffffffffffffffffffffffffff1660016000836000191660001916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141515612713576128d0565b8273ffffffffffffffffffffffffffffffffffffffff16600102600160008760001916600019168152602001908152602001600020600201856040518082805190602001908083835b6020831061277f578051825260208201915060208101905060208303925061275c565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390208160001916905550836040518082805190602001908083835b602083106127ee57805182526020820191506020810190506020830392506127cb565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902085600019167fb829c3e412537bbe794c048ccb9e4605bb4aaaa8e4d4c15c1a6e0c2adc1716ea866040518080602001828103825283818151815260200191508051906020019080838360008314612891575b8051825260208311156128915760208201915060208101905060208303925061286d565b505050905090810190601f1680156128bd5780820380516001836020036101000a031916815260200191505b509250505060405180910390a3600191505b5b5093925050505600a165627a7a7230582066b2da4773a0f1d81efe071c66b51c46868a871661efd18c0f629353ff4c1f9b0029" + }, + "00a329c0648769a73afac7f9381e08fb43dbea72": { + "balance": "1606938044258990275541962092341162602522202993782792835301376" + } + } +} \ No newline at end of file diff --git a/config/privatenet/genesis.json b/config/privatenet/genesis.json new file mode 100644 index 0000000..a67418b --- /dev/null +++ b/config/privatenet/genesis.json @@ -0,0 +1,18 @@ +{ + "config": { + "homesteadBlock": 0, + "byzantiumBlock": 0, + "daoForkSupport": true + }, + "nonce": "0x0000000000000042", + "difficulty": "0x0", + "alloc": { + "0x3333333333333333333333333333333333333333": {"balance": "15000000000000000000"} + }, + "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x3333333333333333333333333333333333333333", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x7a1200" +} diff --git a/config/privatenet/password b/config/privatenet/password new file mode 100644 index 0000000..c747d67 --- /dev/null +++ b/config/privatenet/password @@ -0,0 +1 @@ +dev_password diff --git a/config/storage.js b/config/storage.js new file mode 100644 index 0000000..d7d5390 --- /dev/null +++ b/config/storage.js @@ -0,0 +1,59 @@ +module.exports = { + // default applies to all environments + default: { + enabled: true, + ipfs_bin: "ipfs", + available_providers: ["ipfs"], + upload: { + provider: "ipfs", + host: "localhost", + port: 5001 + }, + dappConnection: [ + { + provider: "ipfs", + host: "localhost", + port: 5001, + getUrl: "http://localhost:8080/ipfs/" + } + ] + // Configuration to start Swarm in the same terminal as `embark run` + /*,account: { + address: "YOUR_ACCOUNT_ADDRESS", // Address of account accessing Swarm + password: "PATH/TO/PASSWORD/FILE" // File containing the password of the account + }, + swarmPath: "PATH/TO/SWARM/EXECUTABLE" // Path to swarm executable (default: swarm)*/ + }, + + // default environment, merges with the settings in default + // assumed to be the intended environment by `embark run` + development: { + enabled: true, + upload: { + provider: "ipfs", + host: "localhost", + port: 5001, + getUrl: "http://localhost:8080/ipfs/" + } + }, + + // merges with the settings in default + // used with "embark run privatenet" + privatenet: { + }, + + // merges with the settings in default + // used with "embark run testnet" + testnet: { + }, + + // merges with the settings in default + // used with "embark run livenet" + livenet: { + }, + + // you can name an environment with specific settings and then specify with + // "embark run custom_name" + //custom_name: { + //} +}; diff --git a/config/testnet/password b/config/testnet/password new file mode 100644 index 0000000..414f849 --- /dev/null +++ b/config/testnet/password @@ -0,0 +1 @@ +test_password diff --git a/config/webserver.js b/config/webserver.js new file mode 100644 index 0000000..506490b --- /dev/null +++ b/config/webserver.js @@ -0,0 +1,6 @@ +module.exports = { + enabled: true, + host: "localhost", + openBrowser: true, + port: 8000 +}; diff --git a/contracts/.gitkeep b/contracts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/embark.json b/embark.json new file mode 100644 index 0000000..536ffe5 --- /dev/null +++ b/embark.json @@ -0,0 +1,24 @@ +{ + "contracts": ["contracts/**"], + "app": { + "css/app.css": ["app/css/**"], + "js/app.js": ["app/js/index.js"], + "images/": ["app/images/**"], + "index.html": "app/index.html" + }, + "buildDir": "dist/", + "config": "config/", + "versions": { + "web3": "1.0.0-beta", + "solc": "0.4.25", + "ipfs-api": "17.2.4" + }, + "plugins": { + }, + "options": { + "solc": { + "optimize": true, + "optimize-runs": 200 + } + } +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b1097d8 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "MyApp", + "version": "0.0.1", + "lockfileVersion": 1 +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..61c0954 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "MyApp", + "version": "0.0.1", + "description": "", + "scripts": { + "test": "embark test" + }, + "author": "", + "license": "ISC", + "homepage": "", + "devDependencies": {} +} diff --git a/test/contract_spec.js b/test/contract_spec.js new file mode 100644 index 0000000..71d999f --- /dev/null +++ b/test/contract_spec.js @@ -0,0 +1,43 @@ +// /*global contract, config, it, assert*/ +/* +const SimpleStorage = require('Embark/contracts/SimpleStorage'); + +let accounts; + +// For documentation please see https://embark.status.im/docs/contracts_testing.html +config({ + //deployment: { + // accounts: [ + // // you can configure custom accounts with a custom balance + // // see https://embark.status.im/docs/contracts_testing.html#Configuring-accounts + // ] + //}, + contracts: { + "SimpleStorage": { + args: [100] + } + } +}, (_err, web3_accounts) => { + accounts = web3_accounts +}); + +contract("SimpleStorage", function () { + this.timeout(0); + + it("should set constructor value", async function () { + let result = await SimpleStorage.methods.storedData().call(); + assert.strictEqual(parseInt(result, 10), 100); + }); + + it("set storage value", async function () { + await SimpleStorage.methods.set(150).send(); + let result = await SimpleStorage.methods.get().call(); + assert.strictEqual(parseInt(result, 10), 150); + }); + + it("should have account with balance", async function() { + let balance = await web3.eth.getBalance(accounts[0]); + assert.ok(parseInt(balance, 10) > 0); + }); +} +*/ diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..d60591d --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,276 @@ +/* global __dirname module process require */ + +const path = require('path'); + +const dappPath = process.env.DAPP_PATH; +const embarkPath = process.env.EMBARK_PATH; + +const dappNodeModules = path.join(dappPath, 'node_modules'); +const embarkNodeModules = path.join(embarkPath, 'node_modules'); + +function customRequire(mod) { + return require(customRequire.resolve(mod)); +} + +customRequire.resolve = function (mod) { + return require.resolve( + mod, + {paths: [dappNodeModules, embarkNodeModules]} + ); +}; + +// some packages, plugins, and presets referenced/required in this webpack +// config are deps of embark and will effectively be transitive dapp deps +// unless specified in the dapp's own package.json + +const cloneDeep = customRequire('lodash.clonedeep'); +// const CompressionPlugin = customRequire('compression-webpack-plugin'); +const glob = customRequire('glob'); +const HardSourceWebpackPlugin = customRequire('hard-source-webpack-plugin'); + +const embarkAliases = require(path.join(dappPath, '.embark/embark-aliases.json')); +const embarkAssets = require(path.join(dappPath, '.embark/embark-assets.json')); +const embarkJson = require(path.join(dappPath, 'embark.json')); +const embarkPipeline = require(path.join(dappPath, '.embark/embark-pipeline.json')); + +const buildDir = path.join(dappPath, embarkJson.buildDir); + +// it's important to `embark reset` if a pkg version is specified in +// embark.json and changed/removed later, otherwise pkg resolution may behave +// unexpectedly +let versions; +try { + versions = glob.sync(path.join(dappPath, '.embark/versions/*/*')); +} catch (e) { + versions = []; +} + +const entry = Object.keys(embarkAssets) + .filter(key => key.match(/\.js$/)) + .reduce((obj, key) => { + // webpack entry paths should start with './' if they're relative to the + // webpack context; embark.json "app" keys correspond to lists of .js + // source paths relative to the top-level dapp dir and may be missing the + // leading './' + obj[key] = embarkAssets[key] + .map(file => { + let file_path = file.path; + if (!file.path.match(/^\.\//)) { + file_path = './' + file_path; + } + return file_path; + }); + return obj; + }, {}); + +function resolve(pkgName) { + if (Array.isArray(pkgName)) { + const _pkgName = pkgName[0]; + pkgName[0] = customRequire.resolve(_pkgName); + return pkgName; + } + return customRequire.resolve(pkgName); +} + +// base config +// ----------------------------------------------------------------------------- + +// order and options of babel plugins and presets adapted from babel-preset-react-app: +// see: https://github.com/facebook/create-react-app/tree/v2.0.4/packages/babel-preset-react-app +// + babel plugins run before babel presets. +// + babel plugin ordering is first to last. +// + babel preset ordering is reversed (last to first). +// see: https://babeljs.io/docs/en/plugins#plugin-ordering + +const base = { + context: dappPath, + entry: entry, + module: { + rules: [ + { + test: /\.scss$/, + use: [ + 'style-loader', + 'css-loader', + 'sass-loader' + ] + }, + { + test: /\.css$/, + use: [ + 'style-loader', + 'css-loader' + ] + }, + { + test: /\.(png|woff|woff2|eot|ttf|svg)$/, + loader: 'url-loader?limit=100000' + }, + { + test: /\.jsx?$/, + loader: 'babel-loader', + exclude: /(node_modules|bower_components|\.embark[\\/]versions)/, + options: { + cacheDirectory: true, + cacheCompression: false, + customize: path.join(__dirname, 'babel-loader-overrides.js'), + plugins: [ + [ + 'babel-plugin-module-resolver', { + alias: embarkAliases + } + ], + 'babel-plugin-macros', + '@babel/plugin-transform-destructuring', + [ + '@babel/plugin-proposal-class-properties', { + loose: true + } + ], + [ + '@babel/plugin-proposal-object-rest-spread', { + useBuiltIns: true + } + ], + [ + '@babel/plugin-transform-runtime', { + corejs: 2, + useESModules: true + } + ], + '@babel/plugin-syntax-dynamic-import' + ].map(resolve), + presets: [ + [ + '@babel/preset-env', { + exclude: ['transform-typeof-symbol'], + modules: false, + targets: { + browsers: ['last 1 version', 'not dead', '> 0.2%'] + } + } + ], + [ + '@babel/preset-react', { + useBuiltIns: true + } + ] + ].map(resolve) + } + } + ] + }, + output: { + filename: (chunkData) => chunkData.chunk.name, + // globalObject workaround for node-compatible UMD builds with webpack 4 + // see: https://github.com/webpack/webpack/issues/6522#issuecomment-371120689 + // see: https://github.com/webpack/webpack/issues/6522#issuecomment-418864518 + globalObject: '(typeof self !== \'undefined\' ? self : this)', + libraryTarget: 'umd', + path: buildDir + }, + plugins: [new HardSourceWebpackPlugin()], + // profiling and generating verbose stats increases build time; if stats + // are generated embark will write the output to: + // path.join(dappPath, '.embark/stats.[json,report]') + // to visualize the stats info in a browser run: + // npx webpack-bundle-analyzer .embark/stats.json + profile: true, stats: 'verbose', + resolve: { + alias: embarkAliases, + extensions: [ + // webpack defaults + // see: https://webpack.js.org/configuration/resolve/#resolve-extensions + '.wasm', '.mjs', '.js', '.json', + // additional extensions + '.jsx' + ], + modules: [ + ...versions, + 'node_modules', + embarkNodeModules + ] + }, + resolveLoader: { + modules: [ + 'node_modules', + embarkNodeModules + ] + } +}; + +const baseBabelLoader = base.module.rules[3]; + +// Flow +// ----------------------------------------------------------------------------- + +// should be false in configs that have isTypeScriptEnabled = true +const isFlowEnabled = !embarkPipeline.typescript; +if (isFlowEnabled) { + // position @babel/plugin-transform-flow-strip-types per babel-preset-react-app + baseBabelLoader.options.plugins.unshift( + customRequire.resolve('@babel/plugin-transform-flow-strip-types') + ); +} + +// TypeScript +// ----------------------------------------------------------------------------- + +// should be false in configs that have isFlowEnabled = true +const isTypeScriptEnabled = !!embarkPipeline.typescript; +if (isTypeScriptEnabled) { + // position @babel/preset-typescript as the last preset (runs first) + // see: https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/ + baseBabelLoader.options.presets.push( + customRequire.resolve('@babel/preset-typescript') + ); + // additional extensions + baseBabelLoader.test = /\.(js|ts)x?$/; + base.resolve.extensions.push('.ts', '.tsx'); +} + +if (isFlowEnabled && isTypeScriptEnabled) { + throw new Error('isFlowEnabled and isTypeScriptEnabled cannot both be true'); +} + +// development config +// ----------------------------------------------------------------------------- + +const development = cloneDeep(base); +// full source maps increase build time but are useful during dapp development +development.devtool = 'source-map'; +development.mode = 'development'; +// alternatively: +// development.mode = 'none'; +development.name = 'development'; +const devBabelLoader = development.module.rules[3]; +devBabelLoader.options.compact = false; +// enable 'development' option for @babel/preset-react +const devPresetReact = devBabelLoader.options.presets[1]; +const devPresetReactOptions = devPresetReact[1]; +devPresetReactOptions.development = true; + +// production config +// ----------------------------------------------------------------------------- + +const production = cloneDeep(base); +production.mode = 'production'; +production.name = 'production'; +const prodBabelLoader = production.module.rules[3]; +// position babel-plugin-transform-react-remove-prop-types per babel-preset-react-app +prodBabelLoader.options.plugins.splice(prodBabelLoader.length - 1, 0, [ + customRequire.resolve('babel-plugin-transform-react-remove-prop-types'), + { + removeImport: true + } +]); +// compression of webpack's JS output not enabled by default +// production.plugins.push(new CompressionPlugin()); + +// export a list of named configs +// ----------------------------------------------------------------------------- + +module.exports = [ + development, + production +];