Guest User

Untitled

a guest
Mar 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // Initialization Skipped
  2.  
  3. const bank = "0x49b36fa1772bdb4d9249f43179832ccdb3732ffc";
  4. const defaultGasPrice = web3.toHex(4);
  5. const defaultGasLimit = 3700000;
  6. const topUpWei = 777;
  7.  
  8. // Sign up
  9. router.post('/api/v1/address', function(req, res){
  10. const data = { name: req.body.name.replace(" ", ""), passphrase: req.body.passphrase };
  11.  
  12. let address;
  13.  
  14. return Promise.resolve()
  15. .then(function() {
  16. address = web3.personal.newAccount(data.passphrase);
  17. })
  18. .then(function() {
  19. return web3.personal.unlockAccount(bank, "");
  20. })
  21. .then(function(ret) {
  22. if (ret) {
  23. return web3.eth.sendTransaction({ from: bank, to: address, value: topUpWei, gas: defaultGasLimit, gasPrice: defaultGasPrice });
  24. }
  25. throw ({ message: 'unable to decrypt mint wallet' });
  26. })
  27. .then(function(ret) {
  28. if (ret) {
  29. return web3.personal.unlockAccount(address, data.passphrase);
  30. }
  31. throw ({ message: 'unable to send initial Ethers' });
  32. })
  33. .then(function(ret) {
  34. if (ret) {
  35. return contractDeployed.createWallet(data.name, 2, { from: address, gas: defaultGasLimit, gasPrice: defaultGasPrice });
  36. }
  37. throw ({ message: 'unable to decrypt ' + data.name + ' wallet' });
  38. })
  39. .then(function(ret) {
  40. if (!ret) {
  41. throw ({ message: 'unable to create wallet ' + data.name });
  42. }
  43. })
  44. .then(function() {
  45. return res.status(200).json({ address: address });
  46. })
  47. .catch(function(err) {
  48. console.log(err.message);
  49. return res.status(500).json({error: err.message});
  50. });
  51.  
  52. return Promise.resolve(null);
  53. });
  54.  
  55. module.exports = router;
Add Comment
Please, Sign In to add comment