Guest User

Untitled

a guest
May 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. app.post('/registeruser',function(req,res){
  2.  
  3.  
  4. var userid = 2;
  5. var username = req.body.username;
  6. var firstname = req.body.firstname;
  7. var lastname = req.body.lastname;
  8. var email = req.body.email;
  9. var password = req.body.password;
  10. var bitcoincashreceivingaddress;
  11. var bitcoinreceivingaddress ;
  12. var litecoinreceivingaddress ;
  13. var user_balance = 0;
  14.  
  15. bitcoincashaddress()
  16. .then(function(response,resolve){
  17. bitcoincashreceivingaddress = response;
  18. return bitcoinaddress();
  19. }).then(function(body2){
  20.  
  21. bitcoinreceivingaddress = body2;
  22. return litecoinaddress();
  23.  
  24. }).then(function(body3){
  25. litecoinreceivingaddress = body3;
  26.  
  27. connection.query("Insert into Usertable(userid,Username,firstname,lastname,emailaddress,password) values ('"+userid+"','"+username+"','"+firstname+"','"+lastname+"','"+email+"','"+password+"')", function (error, results, fields) {
  28. if (error) throw error;
  29. console.log('The result is: ', results);
  30. });
  31.  
  32.  
  33. connection.query("Insert into Wallettable(receivingaddress,user_balance,user_id,coinid) values ('"+bitcoinreceivingaddress+"',"+user_balance+",'"+userid+"','1')", function (error, results, fields) {
  34. if (error) throw error;
  35. console.log('The result is: ', results);
  36. });
  37. connection.end();
  38.  
  39.  
  40.  
  41. }).catch(function(err){
  42. console.log(err);
  43.  
  44. });
  45.  
  46.  
  47.  
  48.  
  49.  
  50. function bitcoincashaddress (){
  51. return new Promise (function (success, failure) {
  52. bitgo.coin('tbch').wallets().getWallet({ id: 'dumyaddress' })
  53. .then(function(wallet) {
  54. return wallet.createAddress();
  55. })
  56. .then(function(newAddress) {
  57. var userbchaddress = newAddress.address;
  58. success(userbchaddress);
  59.  
  60. }).catch(function (err) {
  61.  
  62. failure('Error in signup . Contact Admin');
  63. });
  64. });
  65.  
  66. }
  67.  
  68. function bitcoinaddress (){
  69. return new Promise (function (success, failure) {
  70. bitgo.coin('tbtc').wallets().getWallet({ id: 'dumyaddress' })
  71. .then(function(wallet) {
  72. return wallet.createAddress();
  73. })
  74. .then(function(newAddress) {
  75. var userbtcaddress = newAddress.address;
  76. success(userbtcaddress);
  77.  
  78. }).catch(function (err) {
  79.  
  80. failure('Error in creating bitcoincash address');
  81. });
  82. });
  83.  
  84. }
  85.  
  86. function litecoinaddress (){
  87. return new Promise (function (success, failure) {
  88. bitgo.coin('tltc').wallets().getWallet({ id: 'dumyaddress' })
  89. .then(function(wallet) {
  90. return wallet.createAddress();
  91. })
  92. .then(function(newAddress) {
  93. var userltcaddress = newAddress.address;
  94. success(userltcaddress);
  95.  
  96. }).catch(function (err) {
  97.  
  98. failure('Error in creating litecoin address');
  99. });
  100. });
  101.  
  102. }
  103. });
Add Comment
Please, Sign In to add comment