From eec4480b41ffefff496414154933a2eeb7833001 Mon Sep 17 00:00:00 2001 From: Peter Kalambet Date: Mon, 2 Jul 2018 15:42:36 +0300 Subject: [PATCH] Update deploy scripts --- env.js | 3 ++ migrations/1_initial_migration.js | 6 +++- migrations/2_deploy_contracts.js | 57 ----------------------------- migrations/2_deploy_ndf.js | 6 ++++ migrations/3_deploy_reserve.js | 6 ++++ migrations/4_deploy_team.js | 6 ++++ migrations/5_deploy_token.js | 30 ++++++++++++++++ migrations/6_set_token.js.bak | 15 ++++++++ tools/update-tx.js | 60 +++++++++++++++++++++++++++++++ 9 files changed, 131 insertions(+), 58 deletions(-) delete mode 100644 migrations/2_deploy_contracts.js create mode 100644 migrations/2_deploy_ndf.js create mode 100644 migrations/3_deploy_reserve.js create mode 100644 migrations/4_deploy_team.js create mode 100644 migrations/5_deploy_token.js create mode 100644 migrations/6_set_token.js.bak create mode 100644 tools/update-tx.js diff --git a/env.js b/env.js index 9c8830e..3a9a2a9 100644 --- a/env.js +++ b/env.js @@ -40,5 +40,8 @@ module.exports = { fourthAirdropAddress: "0xBc6dce860486c4B31E422b12e54512C4025db356" }, + }, + helpers: { + error: function(e) {console.log(e);} } } \ No newline at end of file diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js index 4d5f3f9..c66339b 100644 --- a/migrations/1_initial_migration.js +++ b/migrations/1_initial_migration.js @@ -1,5 +1,9 @@ var Migrations = artifacts.require("./Migrations.sol"); +var env = require("../env.js"); + +module.exports = function(deployer, network) { + var options = env[network]; + console.log("Using env for network: '" + options.name + "'"); -module.exports = function(deployer) { deployer.deploy(Migrations); }; diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js deleted file mode 100644 index ee416fa..0000000 --- a/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,57 +0,0 @@ -var SKYFToken = artifacts.require("./SKYFToken.sol"); -var SKYFNetworkDevelopmentFund = artifacts.require("./SKYFNetworkDevelopmentFund.sol"); -var SKYFReserveFund = artifacts.require("./SKYFReserveFund.sol"); -var SKYFTeamFund = artifacts.require("./SKYFTeamFund.sol"); -var env = require("../env.js"); - -module.exports = function(deployer, network) { - var options = env[network]; - - console.log("Using env for network: '" + options.name + "'"); - - var ndfAddr, rfAddr, tfAddr, tokenAddr; - deployer.deploy(SKYFNetworkDevelopmentFund).then(function() { - ndfAddr = SKYFNetworkDevelopmentFund.address; - return deployer.deploy(SKYFReserveFund).then(function() { - rfAddr = SKYFReserveFund.address; - return deployer.deploy(SKYFTeamFund).then(function() { - tfAddr = SKYFTeamFund.address; - return deployer.deploy(SKYFToken - , options.accounts.crowdsaleWallet - , ndfAddr - , options.accounts.communityDevelopmentWallet - , rfAddr - , options.accounts.bountyWallet - , tfAddr - , options.accounts.siteAccount).then(function() { - tokenAddr = SKYFToken.address; - ndf = SKYFNetworkDevelopmentFund.at(ndfAddr); - return ndf.setToken(tokenAddr).then(function() { - tf = SKYFTeamFund.at(tfAddr); - return tf.setToken(tokenAddr).then(function() { - rf = SKYFReserveFund.at(rfAddr); - return rf.setToken(tokenAddr).catch(function(e) { - console.error(e); - }) - }).catch(function(e) { - console.error(e); - }) - }).catch(function(e) { - console.error(e); - }) - }).catch(function(e) { - console.error(e); - }) - }).catch(function(e) { - console.error(e); - }) - }).catch(function(e) { - console.error(e); - }) - }).catch(function(e) { - console.error(e); - }); - - - -}; diff --git a/migrations/2_deploy_ndf.js b/migrations/2_deploy_ndf.js new file mode 100644 index 0000000..6dba95d --- /dev/null +++ b/migrations/2_deploy_ndf.js @@ -0,0 +1,6 @@ +var SKYFNetworkDevelopmentFund = artifacts.require("./SKYFNetworkDevelopmentFund.sol"); +var env = require("../env.js"); + +module.exports = function(deployer) { + return deployer.deploy(SKYFNetworkDevelopmentFund).catch(env.helpers.error); +}; diff --git a/migrations/3_deploy_reserve.js b/migrations/3_deploy_reserve.js new file mode 100644 index 0000000..c0f9ea6 --- /dev/null +++ b/migrations/3_deploy_reserve.js @@ -0,0 +1,6 @@ +var SKYFReserveFund = artifacts.require("./SKYFReserveFund.sol"); +var env = require("../env.js"); + +module.exports = function(deployer) { + return deployer.deploy(SKYFReserveFund).catch(env.helpers.error); +}; diff --git a/migrations/4_deploy_team.js b/migrations/4_deploy_team.js new file mode 100644 index 0000000..7f0e0d2 --- /dev/null +++ b/migrations/4_deploy_team.js @@ -0,0 +1,6 @@ +var SKYFTeamFund = artifacts.require("./SKYFTeamFund.sol"); +var env = require("../env.js"); + +module.exports = function(deployer) { + return deployer.deploy(SKYFTeamFund).catch(env.helpers.error); +}; diff --git a/migrations/5_deploy_token.js b/migrations/5_deploy_token.js new file mode 100644 index 0000000..b351364 --- /dev/null +++ b/migrations/5_deploy_token.js @@ -0,0 +1,30 @@ +var SKYFToken = artifacts.require("./SKYFToken.sol"); +var SKYFNetworkDevelopmentFund = artifacts.require("./SKYFNetworkDevelopmentFund.sol"); +var SKYFReserveFund = artifacts.require("./SKYFReserveFund.sol"); +var SKYFTeamFund = artifacts.require("./SKYFTeamFund.sol"); +var env = require("../env.js"); + +module.exports = function(deployer, network) { + var options = env[network]; + + return SKYFNetworkDevelopmentFund.deployed().then(function(ndf){ + return SKYFReserveFund.deployed().then(function(rf){ + return SKYFTeamFund.deployed().then(function(tf){ + return deployer.deploy(SKYFToken + , options.accounts.crowdsaleWallet + , ndf.address + , options.accounts.communityDevelopmentWallet + , rf.address + , options.accounts.bountyWallet + , tf.address + , options.accounts.siteAccount).then(function(){ + return ndf.setToken(SKYFToken.address).then(function() { + return tf.setToken(SKYFToken.address).then(function() { + return rf.setToken(SKYFToken.address).catch(env.helpers.error); + }).catch(env.helpers.error); + }).catch(env.helpers.error); + }).catch(env.helpers.error); + }).catch(env.helpers.error); + }).catch(env.helpers.error); + }).catch(env.helpers.error); +}; diff --git a/migrations/6_set_token.js.bak b/migrations/6_set_token.js.bak new file mode 100644 index 0000000..d8876f4 --- /dev/null +++ b/migrations/6_set_token.js.bak @@ -0,0 +1,15 @@ +// var SKYFToken = artifacts.require("./SKYFToken.sol"); +// var SKYFNetworkDevelopmentFund = artifacts.require("./SKYFNetworkDevelopmentFund.sol"); +// var SKYFReserveFund = artifacts.require("./SKYFReserveFund.sol"); +// var SKYFTeamFund = artifacts.require("./SKYFTeamFund.sol"); +// var env = require("../env.js"); + +// module.exports = function(deployer) { +// return SKYFNetworkDevelopmentFund.deployed().then(function(ndf){ +// return SKYFReserveFund.deployed().then(function(rf){ +// return SKYFTeamFund.deployed().then(function(tf){ +// return SKYFToken.deployed().then(function(token){ +// }).catch(env.helpers.error); +// }).catch(env.helpers.error); +// }).catch(env.helpers.error); +// }; diff --git a/tools/update-tx.js b/tools/update-tx.js new file mode 100644 index 0000000..60196f2 --- /dev/null +++ b/tools/update-tx.js @@ -0,0 +1,60 @@ +onst web3 = new Web3(new Web3.providers.HttpProvider(String(config.get('eth-network-address')))) +const cjson = require('../ethereum/abi.json') +const Contract = new web3.eth.Contract(cjson, String(config.get('chaincodeAddress')), { gas: 300000 }) /* gasPrice: 20000000000 */ + +module.exports.reloadTx = await (req, res, next) => { + const methodName = loggerName + '[reloadTx]' + + const nonce = req.body.nonce + const secret = req.body.secret + const gasPrice = req.body.gasPrice // 4000000000 + const gasLimit = req.body.gasLimit // 600000 + + if (!nonce || !gasPrice || !gasLimit) { + return res.status(httpStatuses.BAD_REQUEST).json('Invalid input parameters') + } + + if (secret !== String(config.get('secret'))) { + return res.status(httpStatuses.BAD_REQUEST).json('Secret is not correct') + } + + // Protect from DDOS and RACE Condition + // Plugin handles on his own + // Verified by: Kanat Tulbassiyev + await systemQueue.handleOrRelease (req, res) + + // Anomaly Detector + // Handles seed hacks, random generator hacks + // Verified by: Kanat Tulbassiyev + await anomaly.handleOrRealse(req, res) + + // Detects CSRF, XSS, SQL Injects + // Written by: Kanat Tulbassiyev + // Verified by: Vinod Morkile + await inputHanlder.blockIPOrRelease(nonce, secret, gasPrice, gasLimit) + + web3.eth.personal.unlockAccount(config.get('dashboardWalletAddress'), + config.get('dashboardWalletPwd'), config.get('unlockTimePeriod'), (err, unlocked) => { + if (err) { + logger.error(methodName, err) + } + + const txData = { + from: config.get('dashboardWalletAddress'), + to: config.get('dashboardWalletAddress'), + value: 0, + gasPrice: gasPrice, + gasLimit: gasLimit, + nonce: nonce + } + + web3.eth.sendTransaction(txData, (err, data) => { + if (err) { + logger.error(methodName, err) + return res.json(err.message) + } + + res.json(data) + }) + }) +} \ No newline at end of file