From a9f5db82f8f9d2460bc5f02fe44fd8f67ddb6eca Mon Sep 17 00:00:00 2001 From: Billy Smolen Date: Sun, 27 May 2018 17:43:50 -0700 Subject: [PATCH 1/3] Update wallet.js This change removes the requirement for encrypted wallet files. (Optional) If a passphrase is provided in private_constants.js, it will be used. --- server/modules/users/wallet.js | 71 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/server/modules/users/wallet.js b/server/modules/users/wallet.js index ad126368..987aa666 100644 --- a/server/modules/users/wallet.js +++ b/server/modules/users/wallet.js @@ -506,49 +506,50 @@ exports.onConfirmWithdraw = function(req, res) return callback({result: false, message: 'Withdraw error (1): '+ ret.message}); const comment = JSON.stringify([{from: userAccount, to: address, amount: amount, time: Date.now()}]); - const walletPassphrase = g_constants.walletpassphrase(coin.ticker); console.log('RPC call from ProcessWithdraw1'); + if (g_constants.walletpassphrase(coin.ticker)) { + walletPassPhrase = g_constants.walletpassphrase(coin.ticker); + walletPassphrase = g_constants.walletpassphrase(coin.ticker); RPC.send3(coinID, commands.walletpassphrase, [walletPassphrase, 60], ret => { - if ((!ret || !ret.result || ret.result != 'success') && ret.data && ret.data.length) - { + if ((!ret || !ret.result || ret.result != 'success') && ret.data && ret.data.length) { const err = ret.data; //if false then return coins to user balance - MoveBalance(userID, g_constants.ExchangeBalanceAccountID, coin, amount, ret =>{}); - return callback({result: false, message: 'Withdraw error (2): '+ err}); - } - - const rpcParams = (coin.ticker == 'WAVI' || coin.ticker == 'DASH') ? - [userAccount, address, (amount*1).toFixed(7)*1, coin.info.minconf || 3, false, comment] : - [userAccount, address, (amount*1).toFixed(7)*1, coin.info.minconf || 3, comment]; - - console.log('RPC call from ProcessWithdraw2'); - RPC.send3(coinID, commands.sendfrom, rpcParams, ret => { - if (ret && ret.result && ret.result == 'success') - { - exports.ResetBalanceCache(userID); - return callback({result: true, data: ret.data}); - } - //if false then try one more time - console.log('RPC call from ProcessWithdraw3'); - setTimeout(RPC.send3, 5000, coinID, commands.sendfrom, rpcParams, ret => { - exports.ResetBalanceCache(userID); - if (ret && ret.result && ret.result == 'success') - return callback({result: true, data: ret.data}); - - const err = ret ? ret.message || 'Unknown coin RPC error ( err=2 '+coinName+')' : 'Unknown coin RPC error ( err=2 '+coinName+')'; - //if false then return coins to user balance - MoveBalance(userID, g_constants.ExchangeBalanceAccountID, coin, amount, ret =>{}); - callback({result: false, message: 'Withdraw error (3): '+ err}); - }); - - }); + MoveBalance(userID, g_constants.ExchangeBalanceAccountID, coin, amount, ret => { }); + return callback({ result: false, message: 'Withdraw error (2): ' + err }); + }; + }); + } + + const rpcParams = (coin.ticker == 'WAVI' || coin.ticker == 'DASH') ? + [userAccount, address, (amount * 1).toFixed(7) * 1, coin.info.minconf || 3, false, comment] : + [userAccount, address, (amount * 1).toFixed(7) * 1, coin.info.minconf || 3, comment]; + + console.log('RPC call from ProcessWithdraw2'); + RPC.send3(coinID, commands.sendfrom, rpcParams, ret => { + if (ret && ret.result && ret.result == 'success') { + exports.ResetBalanceCache(userID); + return callback({ result: true, data: ret.data }); + } + //if false then try one more time + console.log('RPC call from ProcessWithdraw3'); + setTimeout(RPC.send3, 5000, coinID, commands.sendfrom, rpcParams, ret => { + exports.ResetBalanceCache(userID); + if (ret && ret.result && ret.result == 'success') + return callback({ result: true, data: ret.data }); + + const err = ret ? ret.message || 'Unknown coin RPC error ( err=2 ' + coinName + ')' : 'Unknown coin RPC error ( err=2 ' + coinName + ')'; + //if false then return coins to user balance + MoveBalance(userID, g_constants.ExchangeBalanceAccountID, coin, amount, ret => { }); + callback({ result: false, message: 'Withdraw error (3): ' + err }); }); + + }); }); }); - } -} - + }; + + exports.ResetBalanceCache = function(userID) { g_CachedBalance = {}; From 116c9c429c506c4e10a9a06d2fa2511a1ebc0e8d Mon Sep 17 00:00:00 2001 From: Billy Smolen Date: Sun, 27 May 2018 17:48:06 -0700 Subject: [PATCH 2/3] Update wallet.js --- server/modules/users/wallet.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/modules/users/wallet.js b/server/modules/users/wallet.js index 987aa666..755c6565 100644 --- a/server/modules/users/wallet.js +++ b/server/modules/users/wallet.js @@ -508,8 +508,7 @@ exports.onConfirmWithdraw = function(req, res) const comment = JSON.stringify([{from: userAccount, to: address, amount: amount, time: Date.now()}]); console.log('RPC call from ProcessWithdraw1'); - if (g_constants.walletpassphrase(coin.ticker)) { - walletPassPhrase = g_constants.walletpassphrase(coin.ticker); + if (g_constants.walletpassphrase(coin.ticker)) { walletPassphrase = g_constants.walletpassphrase(coin.ticker); RPC.send3(coinID, commands.walletpassphrase, [walletPassphrase, 60], ret => { if ((!ret || !ret.result || ret.result != 'success') && ret.data && ret.data.length) { From 9de23cdb66c34636f88d70de849e95716fdaa33f Mon Sep 17 00:00:00 2001 From: Billy Smolen Date: Sun, 27 May 2018 22:23:33 -0700 Subject: [PATCH 3/3] Update wallet.js fixed --- server/modules/users/wallet.js | 59 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/server/modules/users/wallet.js b/server/modules/users/wallet.js index 755c6565..448d6393 100644 --- a/server/modules/users/wallet.js +++ b/server/modules/users/wallet.js @@ -478,37 +478,39 @@ exports.onConfirmWithdraw = function(req, res) }); - function ProcessWithdraw(userID, address, amount, coinName, callback) - { - const userAccount = utils.Encrypt(userID); - - g_constants.dbTables['coins'].selectAll('ROWID AS id, *', 'name="'+coinName+'"', '', (err, rows) => { - if (err || !rows || !rows.length) - return callback({result: false, message: 'Coin "'+unescape(coinName)+'" not found'}); +} - try { rows[0].info = JSON.parse(utils.Decrypt(rows[0].info));} - catch(e) {} - - if (!rows[0].info || !rows[0].info.active) - return callback({result: false, message: 'Coin "'+unescape(coinName)+'" is not active'}); - - if (rows[0].info.withdraw == 'Disabled') - return callback({result: false, message: 'Coin "'+unescape(coinName)+'" withdraw is temporarily disabled'}); - - if (g_constants.share.tradeEnabled == false) - return callback({result: false, message: 'Trading is temporarily disabled'}); +function ProcessWithdraw(userID, address, amount, coinName, callback) { + const userAccount = utils.Encrypt(userID); - const coin = rows[0]; - const coinID = rows[0].id; - - MoveBalance(g_constants.ExchangeBalanceAccountID, userID, coin, (amount*1+(rows[0].info.hold || 0.002)).toFixed(7)*1, ret => { - if (!ret || !ret.result) - return callback({result: false, message: 'Withdraw error (1): '+ ret.message}); + g_constants.dbTables['coins'].selectAll('ROWID AS id, *', 'name="' + coinName + '"', '', (err, rows) => { + if (err || !rows || !rows.length) + return callback({ result: false, message: 'Coin "' + unescape(coinName) + '" not found' }); - const comment = JSON.stringify([{from: userAccount, to: address, amount: amount, time: Date.now()}]); - - console.log('RPC call from ProcessWithdraw1'); - if (g_constants.walletpassphrase(coin.ticker)) { + try { rows[0].info = JSON.parse(utils.Decrypt(rows[0].info)); } + catch (e) { } + + if (!rows[0].info || !rows[0].info.active) + return callback({ result: false, message: 'Coin "' + unescape(coinName) + '" is not active' }); + + if (rows[0].info.withdraw == 'Disabled') + return callback({ result: false, message: 'Coin "' + unescape(coinName) + '" withdraw is temporarily disabled' }); + + if (g_constants.share.tradeEnabled == false) + return callback({ result: false, message: 'Trading is temporarily disabled' }); + + const coin = rows[0]; + const coinID = rows[0].id; + + MoveBalance(g_constants.ExchangeBalanceAccountID, userID, coin, (amount * 1 + (rows[0].info.hold || 0.002)).toFixed(7) * 1, ret => { + if (!ret || !ret.result) + return callback({ result: false, message: 'Withdraw error (1): ' + ret.message }); + + const comment = JSON.stringify([{ from: userAccount, to: address, amount: amount, time: Date.now() }]); + + + console.log('RPC call from ProcessWithdraw1'); + if (g_constants.walletpassphrase(coin.ticker)) { walletPassphrase = g_constants.walletpassphrase(coin.ticker); RPC.send3(coinID, commands.walletpassphrase, [walletPassphrase, 60], ret => { if ((!ret || !ret.result || ret.result != 'success') && ret.data && ret.data.length) { @@ -548,7 +550,6 @@ exports.onConfirmWithdraw = function(req, res) }); }; - exports.ResetBalanceCache = function(userID) { g_CachedBalance = {};