Merge pull request #26 from lamassu/whitespace-nuke
style(whitespace): trailing whitespaces removed
This commit is contained in:
commit
0515d48fc7
6 changed files with 22 additions and 22 deletions
|
|
@ -8,7 +8,7 @@ var routes = require('./routes');
|
|||
var Trader = require('./trader');
|
||||
var PostgresqlInterface = require('./postgresql_interface');
|
||||
var logger = require('./logger');
|
||||
|
||||
|
||||
module.exports = function (options) {
|
||||
var app = express();
|
||||
var connectionString;
|
||||
|
|
@ -65,7 +65,7 @@ module.exports = function (options) {
|
|||
config.isAuthorized(routes.getFingerprint(req), function (err, device) {
|
||||
if (err) {
|
||||
res.json({err: 'Internal Server Error'});
|
||||
return next(err);
|
||||
return next(err);
|
||||
}
|
||||
if (!device) {
|
||||
res.json(404, {err: 'Not Found'});
|
||||
|
|
|
|||
|
|
@ -20,16 +20,16 @@ var PostgresqlInterface = function (conString) {
|
|||
PostgresqlInterface.factory = function factory(conString) { return new PostgresqlInterface(conString); };
|
||||
module.exports = PostgresqlInterface;
|
||||
|
||||
PostgresqlInterface.prototype.summonTransaction =
|
||||
PostgresqlInterface.prototype.summonTransaction =
|
||||
function summonTransaction(deviceFingerprint, tx, cb) {
|
||||
// First do an INSERT
|
||||
// If it worked, go ahead with transaction
|
||||
// If duplicate, fetch status and return
|
||||
var self = this;
|
||||
this.client.query('INSERT INTO transactions (id, status, device_fingerprint, ' +
|
||||
'to_address, satoshis, currency_code, fiat) ' +
|
||||
'to_address, satoshis, currency_code, fiat) ' +
|
||||
'VALUES ($1, $2, $3, $4, $5, $6, $7)', [tx.txId, 'pending', deviceFingerprint,
|
||||
tx.toAddress, tx.satoshis, tx.currencyCode, tx.fiat],
|
||||
tx.toAddress, tx.satoshis, tx.currencyCode, tx.fiat],
|
||||
function (err) {
|
||||
if (err && PG_ERRORS[err.code] === 'uniqueViolation')
|
||||
return self._fetchTransaction(tx.txId, cb);
|
||||
|
|
@ -38,30 +38,30 @@ PostgresqlInterface.prototype.summonTransaction =
|
|||
});
|
||||
};
|
||||
|
||||
PostgresqlInterface.prototype.reportTransactionError =
|
||||
PostgresqlInterface.prototype.reportTransactionError =
|
||||
function reportTransactionError(tx, errString, status) {
|
||||
this.client.query('UPDATE transactions SET status=$1, error=$2 WHERE id=$3',
|
||||
this.client.query('UPDATE transactions SET status=$1, error=$2 WHERE id=$3',
|
||||
[status, errString, tx.txId]);
|
||||
};
|
||||
|
||||
PostgresqlInterface.prototype.completeTransaction =
|
||||
PostgresqlInterface.prototype.completeTransaction =
|
||||
function completeTransaction(tx, txHash) {
|
||||
if (txHash)
|
||||
this.client.query('UPDATE transactions SET tx_hash=$1, status=$2, completed=now() WHERE id=$3',
|
||||
this.client.query('UPDATE transactions SET tx_hash=$1, status=$2, completed=now() WHERE id=$3',
|
||||
[txHash, 'completed', tx.txId]);
|
||||
else
|
||||
this.client.query('UPDATE transactions SET status=$1, error=$2 WHERE id=$3',
|
||||
['failed', 'No txHash received', tx.txId]);
|
||||
this.client.query('UPDATE transactions SET status=$1, error=$2 WHERE id=$3',
|
||||
['failed', 'No txHash received', tx.txId]);
|
||||
};
|
||||
|
||||
PostgresqlInterface.prototype._fetchTransaction =
|
||||
PostgresqlInterface.prototype._fetchTransaction =
|
||||
function _fetchTransaction(txId, cb) {
|
||||
this.client.query('SELECT status, tx_hash, error FROM transactions WHERE id=$1',
|
||||
[txId], function (err, results) {
|
||||
if (err) return cb(err);
|
||||
|
||||
// This should never happen, since we already checked for existence
|
||||
if (results.rows.length === 0) return cb(new Error('Couldn\'t find transaction.'));
|
||||
if (results.rows.length === 0) return cb(new Error('Couldn\'t find transaction.'));
|
||||
|
||||
var result = results.rows[0];
|
||||
cb(null, {txHash: result.tx_hash, err: result.error, status: result.status});
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ function send(req, res) {
|
|||
var fingerprint = getFingerprint(req);
|
||||
_trader.sendBitcoins(fingerprint, req.body, function(err, txHash) {
|
||||
res.json({
|
||||
err: err && err.message,
|
||||
txHash: txHash,
|
||||
err: err && err.message,
|
||||
txHash: txHash,
|
||||
errType: err && err.name
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ Trader.prototype.configure = function (config) {
|
|||
};
|
||||
|
||||
// IMPORTANT: This function returns the estimated minimum available balance
|
||||
// in fiat as of the start of the current user session on the device. User
|
||||
// in fiat as of the start of the current user session on the device. User
|
||||
// session starts when a user presses then Start button and ends when we
|
||||
// send the bitcoins.
|
||||
Trader.prototype.fiatBalance = function (deviceFingerprint) {
|
||||
|
|
@ -125,7 +125,7 @@ Trader.prototype.fiatBalance = function (deviceFingerprint) {
|
|||
// `balance.transferBalance` is the balance of our transfer account (the one
|
||||
// we use to send Bitcoins to clients) in satoshis.
|
||||
var transferBalance = balance.transferBalance;
|
||||
|
||||
|
||||
// Since `transferBalance` is in satoshis, we need to turn it into
|
||||
// bitcoins and then fiat to learn how much fiat currency we can exchange.
|
||||
//
|
||||
|
|
@ -193,7 +193,7 @@ Trader.prototype.sendBitcoins = function (deviceFingerprint, tx, cb) {
|
|||
if (txRec.status === 'insufficientFunds') txErr.name = 'InsufficientFunds';
|
||||
}
|
||||
|
||||
// transaction exists, but txHash might be null,
|
||||
// transaction exists, but txHash might be null,
|
||||
// in which case ATM should continue polling
|
||||
self.pollBalance();
|
||||
cb(txErr, txRec.txHash);
|
||||
|
|
@ -213,7 +213,7 @@ Trader.prototype.trade = function (rec, deviceFingerprint) {
|
|||
delete self._sessionInfo[deviceFingerprint];
|
||||
}, SESSION_TIMEOUT)
|
||||
};
|
||||
}
|
||||
}
|
||||
this._tradeQueue.push({fiat: rec.fiat, satoshis: rec.satoshis, currency: rec.currency});
|
||||
};
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ Trader.prototype._tradeForexMultiplier = function _tradeForexMultiplier() {
|
|||
Trader.prototype._tradeBalanceFunc = function _tradeBalanceFunc(callback) {
|
||||
if (!this.tradeExchange) return callback(null, null);
|
||||
var forexMultiplier = this._tradeForexMultiplier();
|
||||
if (!forexMultiplier) return callback(new Error('Can\'t compute balance, no tickers yet.'));
|
||||
if (!forexMultiplier) return callback(new Error('Can\'t compute balance, no tickers yet.'));
|
||||
this.tradeExchange.balance(function (err, localBalance) {
|
||||
if (err) return callback(err);
|
||||
callback(null, localBalance * forexMultiplier);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ describe('send test', function() {
|
|||
'txs': []
|
||||
};
|
||||
|
||||
var payment_response = {
|
||||
var payment_response = {
|
||||
'message': 'Sent 0.1 BTC to 1LhkU2R8nJaU8Zj6jB8VjWrMpvVKGqCZ64',
|
||||
'tx_hash': 'f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c',
|
||||
'notice': 'Some funds are pending confirmation and cannot be spent yet (Value 0.001 BTC)'
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ describe('trader/fiatBalance', function() {
|
|||
assert.equal(fiatBalance, 150 / LOW_BALANCE_MARGIN);
|
||||
});
|
||||
|
||||
it('should calculate balance correctly with transfer and ' +
|
||||
it('should calculate balance correctly with transfer and ' +
|
||||
'trade exchange with different currencies', function() {
|
||||
var trader = new Trader(db);
|
||||
trader.configure({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue