From d21f385fc0160f80152b930a3756b64b57ed1d45 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 25 Sep 2016 20:51:00 -0400 Subject: [PATCH] fix rpccorsdomain; deployment to livenet and testnet --- demo/chains.json | 20 +++++++++++++++----- demo/config/blockchain.json | 13 ++++++++++--- lib/blockchain.js | 1 + lib/deploy.js | 8 +++++++- lib/geth_commands.js | 11 +++++++---- lib/index.js | 2 ++ 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/demo/chains.json b/demo/chains.json index dc3d5973..9bc589a0 100644 --- a/demo/chains.json +++ b/demo/chains.json @@ -1,16 +1,26 @@ { - "0xb6cfeab83614da04c03db0fb8a6787a45d0be8d576fcc6f8f457a5a816d22ab3": { - "name": "development", - "networkId": "", + "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3": { + "name": "livenet", "contracts": { "5a52b16abb7dfccfc675550d0daba1683a3cf7e80fb5f0e199301f7dd57237fb": { - "address": "0x9b7d9cfed1dcc25ffa10cabf09ed69107634bcc7", + "address": "0x58a580ca43e04e82716c528bc134144042d99ff6", "name": "SimpleStorage" }, "708fa6b699f419627ab3c4c2d9c82f8f1a6fab03c122d0a9ee55d2d0d0ad1e4b": { - "address": "0x3134e7b4b2bf08f50b299ad35a2271c6f5ebed5b", + "address": "0x717ceee627be5e18b3cd0386d104281688f91cef", "name": "token" } } + }, + "0xeb9f1658ba4415557d3952c22cb6aadd416c6d803a47f7ab6c21acb7e758483c": { + "name": "livenet", + "contracts": { + "5a52b16abb7dfccfc675550d0daba1683a3cf7e80fb5f0e199301f7dd57237fb": { + "name": "SimpleStorage" + }, + "708fa6b699f419627ab3c4c2d9c82f8f1a6fab03c122d0a9ee55d2d0d0ad1e4b": { + "name": "token" + } + } } } \ No newline at end of file diff --git a/demo/config/blockchain.json b/demo/config/blockchain.json index 14d0c9a6..335e6e49 100644 --- a/demo/config/blockchain.json +++ b/demo/config/blockchain.json @@ -7,17 +7,24 @@ "nodiscover": true, "rpcHost": "localhost", "rpcPort": 8545, + "rpcCorsDomain": "http://localhost:8000", "account": { "password": "config/development/password" } }, "testnet": { + "networkType": "testnet", "rpcHost": "localhost", - "rpcPort": 8545, - "networkType": "testnet" + "rpcPort": 8545 }, "livenet": { - "networkType": "livenet" + "networkType": "livenet", + "rpcHost": "localhost", + "rpcPort": 8545, + "rpcCorsDomain": "http://localhost:8000", + "account": { + "password": "config/production/password" + } }, "privatenet": { "networkType": "custom", diff --git a/lib/blockchain.js b/lib/blockchain.js index c42c1c05..de6579d8 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -13,6 +13,7 @@ var Blockchain = function(blockchainConfig, Client) { mineWhenNeeded: this.blockchainConfig.mineWhenNeeded || false, rpcHost: this.blockchainConfig.rpcHost || 'localhost', rpcPort: this.blockchainConfig.rpcPort || 8545, + rpcCorsDomain: this.blockchainConfig.rpcCorsDomain || false, networkId: this.blockchainConfig.networkId || 12301, port: this.blockchainConfig.port || 30303, nodiscover: this.blockchainConfig.nodiscover || false, diff --git a/lib/deploy.js b/lib/deploy.js index bec255db..0f40fc94 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -40,8 +40,14 @@ Deploy.prototype.deployContract = function(contract, params, callback) { var contractParams = (params || contract.args).slice(); + console.log("using address" + this.web3.eth.accounts[0]); + + // TODO: probably needs to be defaultAccoun + // TODO: it wouldn't necessary be the first address + // idea: use defined blockchain address or first address contractParams.push({ - from: this.web3.eth.coinbase, + //from: this.web3.eth.coinbase, + from: this.web3.eth.accounts[0], data: contract.code, gas: contract.gas, gasPrice: contract.gasPrice diff --git a/lib/geth_commands.js b/lib/geth_commands.js index c5126ac8..0d2b3a04 100644 --- a/lib/geth_commands.js +++ b/lib/geth_commands.js @@ -82,7 +82,7 @@ GethCommands.prototype.mainCommand = function(address) { cmd += "--olympic "; } - if (config.networkType !== 'custom') { + if (config.networkType === 'custom') { cmd += "--networkid " + config.networkId + " "; } @@ -94,9 +94,12 @@ GethCommands.prototype.mainCommand = function(address) { cmd += "--rpc "; cmd += "--rpcport " + config.rpcPort + " "; cmd += "--rpcaddr " + config.rpcHost + " "; - //cmd += "--rpccorsdomain=\"" + "localhost" + "\" "; - cmd += "--rpccorsdomain=\"" + "*" + "\" "; - //cmd += "--rpccorsdomain=\"" + config.rpcWhitelist + "\" "; + if (config.rpcCorsDomain) { + // TODO: show gigantic warning when cors is set to * + cmd += "--rpccorsdomain=\"" + config.rpcCorsDomain + "\" "; + } else { + // TODO: show warning when cors is not set + } //"nodiscover": true, diff --git a/lib/index.js b/lib/index.js index 29318ea8..b719b115 100644 --- a/lib/index.js +++ b/lib/index.js @@ -98,6 +98,7 @@ var Embark = { self.logger.logFunction = Embark.monitor.logEntry; self.logger.contractsState = Embark.monitor.setContracts; self.logger.availableServices = Embark.monitor.availableServices; + // TODO: do this after monitor is rendered callback(); }, function monitorServices(callback) { @@ -200,6 +201,7 @@ var Embark = { //TODO: figure out where to put this since the web3 can be passed along if needed // perhaps it should go into the deploy object itself + // TODO: should come from the config object var web3 = new Web3(); var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort; web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));