From 92ea8067b007b0bcc3be659fd252c34c4192e1cd Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 12 Sep 2018 09:13:55 +0200 Subject: [PATCH] API: execute runTx and getAccounts for all network except mainnet --- src/app/plugin/pluginAPI.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 81bd2e00cb..a6c8f8dd54 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -48,22 +48,32 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => }, udapp: { runTx: (mod, tx, cb) => { - if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow sending a transaction through a web3 connection. Only vm mode is allowed') - udapp.silentRunTx(tx, (error, result) => { + executionContext.detectNetwork((error, network) => { if (error) return cb(error) - cb(null, { - transactionHash: result.transactionHash, - status: result.result.status, - gasUsed: '0x' + result.result.gasUsed.toString('hex'), - error: result.result.vm.exceptionError, - return: result.result.vm.return ? '0x' + result.result.vm.return.toString('hex') : '0x', - createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined + if (network.name === 'Main' && network.id === '1') { + return cb('It is not allowed to make this action against mainnet') + } + udapp.silentRunTx(tx, (error, result) => { + if (error) return cb(error) + cb(null, { + transactionHash: result.transactionHash, + status: result.result.status, + gasUsed: '0x' + result.result.gasUsed.toString('hex'), + error: result.result.vm.exceptionError, + return: result.result.vm.return ? '0x' + result.result.vm.return.toString('hex') : '0x', + createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined + }) }) }) }, getAccounts: (mod, cb) => { - if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow retrieving accounts through a web3 connection. Only vm mode is allowed') - udapp.getAccounts(cb) + executionContext.detectNetwork((error, network) => { + if (error) return cb(error) + if (network.name === 'Main' && network.id === '1') { + return cb('It is not allowed to make this action against mainnet') + } + udapp.getAccounts(cb) + }) }, createVMAccount: (mod, privateKey, balance, cb) => { if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed')