WIP
This commit is contained in:
parent
2c756e231a
commit
2e51bf646e
2 changed files with 4 additions and 43 deletions
|
|
@ -30,7 +30,6 @@ var tradeInterval = null;
|
||||||
var reapTxInterval = null;
|
var reapTxInterval = null;
|
||||||
|
|
||||||
var tradesQueue = [];
|
var tradesQueue = [];
|
||||||
var dispenseStatuses = {};
|
|
||||||
|
|
||||||
// that's basically a constructor
|
// that's basically a constructor
|
||||||
exports.init = function init(databaseHandle) {
|
exports.init = function init(databaseHandle) {
|
||||||
|
|
@ -280,35 +279,6 @@ exports.sendBitcoins = function sendBitcoins(deviceFingerprint, rawTx, cb) {
|
||||||
executeTx(deviceFingerprint, rawTx, cb);
|
executeTx(deviceFingerprint, rawTx, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
// sets given status both "locally" (dispenseStatuses) and saves to db
|
|
||||||
function _setDispenseStatus(deviceFingerprint, tx, status, deposit) {
|
|
||||||
tx.status = status;
|
|
||||||
|
|
||||||
// No need to set default state again
|
|
||||||
if (status !== 'noDeposit')
|
|
||||||
// save to db ASAP
|
|
||||||
db.changeTxStatus(tx.txId, status, {
|
|
||||||
hash: tx.txHash
|
|
||||||
});
|
|
||||||
|
|
||||||
var fiat = 0;
|
|
||||||
if (status === 'authorizedDeposit')
|
|
||||||
fiat = tx.fiat;
|
|
||||||
|
|
||||||
var statusObject = null;
|
|
||||||
if (status !== 'dispensedDeposit')
|
|
||||||
statusObject = {
|
|
||||||
status: status,
|
|
||||||
txId: tx.txId,
|
|
||||||
deposit: deposit || 0,
|
|
||||||
dispenseFiat: fiat,
|
|
||||||
expectedDeposit: tx.satoshis
|
|
||||||
};
|
|
||||||
|
|
||||||
// keep local copy
|
|
||||||
dispenseStatuses[deviceFingerprint] = statusObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.cashOut = function cashOut(deviceFingerprint, tx, cb) {
|
exports.cashOut = function cashOut(deviceFingerprint, tx, cb) {
|
||||||
var tmpInfo = {
|
var tmpInfo = {
|
||||||
label: 'TX ' + Date.now(),
|
label: 'TX ' + Date.now(),
|
||||||
|
|
@ -324,11 +294,6 @@ exports.cashOut = function cashOut(deviceFingerprint, tx, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.dispenseAck = function dispenseAck(deviceFingerprint, tx) {
|
exports.dispenseAck = function dispenseAck(deviceFingerprint, tx) {
|
||||||
_setDispenseStatus(deviceFingerprint, tx, 'dispensedDeposit');
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.dispenseStatus = function dispenseStatus(deviceFingerprint) {
|
|
||||||
return dispenseStatuses[deviceFingerprint];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fiatBalance = function fiatBalance() {
|
exports.fiatBalance = function fiatBalance() {
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,12 @@ var _ = require('lodash');
|
||||||
var should = require('chai').should();
|
var should = require('chai').should();
|
||||||
var mockery = require('mockery');
|
var mockery = require('mockery');
|
||||||
|
|
||||||
|
|
||||||
var config = require('./mocks/config.json');
|
var config = require('./mocks/config.json');
|
||||||
var CONFIG = _.cloneDeep(config);
|
var CONFIG = _.cloneDeep(config);
|
||||||
function requireFreshConfig() {
|
function requireFreshConfig() {
|
||||||
return _.cloneDeep(CONFIG);
|
return _.cloneDeep(CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var walletMock = require('./mocks/wallet');
|
var walletMock = require('./mocks/wallet');
|
||||||
var tickerMock = require('./mocks/ticker');
|
var tickerMock = require('./mocks/ticker');
|
||||||
var traderMock = require('./mocks/trader');
|
var traderMock = require('./mocks/trader');
|
||||||
|
|
@ -26,7 +24,6 @@ mockery.registerMock('lamassu-mockTrader', traderMock);
|
||||||
mockery.registerMock('lamassu-mockVerifier', verifierMock);
|
mockery.registerMock('lamassu-mockVerifier', verifierMock);
|
||||||
mockery.registerMock('lamassu-mockInfo', infoMock);
|
mockery.registerMock('lamassu-mockInfo', infoMock);
|
||||||
|
|
||||||
|
|
||||||
describe('Plugins', function() {
|
describe('Plugins', function() {
|
||||||
var plugins = null;
|
var plugins = null;
|
||||||
|
|
||||||
|
|
@ -138,7 +135,6 @@ describe('Plugins', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Ticker', function() {
|
describe('Ticker', function() {
|
||||||
it('should have called .ticker() at least once', function() {
|
it('should have called .ticker() at least once', function() {
|
||||||
tickerMock.getTickerCalls().should.be.at.least(1);
|
tickerMock.getTickerCalls().should.be.at.least(1);
|
||||||
|
|
@ -162,7 +158,6 @@ describe('Plugins', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Wallet', function() {
|
describe('Wallet', function() {
|
||||||
|
|
||||||
var db = require('./mocks/db');
|
var db = require('./mocks/db');
|
||||||
|
|
@ -207,7 +202,8 @@ describe('Plugins', function() {
|
||||||
satoshis: 1e7
|
satoshis: 1e7
|
||||||
};
|
};
|
||||||
|
|
||||||
plugins.sendBitcoins(db.FINGERPRINT_NEW, txDetails, function(err, response) {
|
plugins.sendBitcoins(db.FINGERPRINT_NEW, txDetails, function(err,
|
||||||
|
response) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
should.exist(response);
|
should.exist(response);
|
||||||
/* jshint expr: true */
|
/* jshint expr: true */
|
||||||
|
|
@ -227,7 +223,8 @@ describe('Plugins', function() {
|
||||||
toAddress: walletMock.ADDR,
|
toAddress: walletMock.ADDR,
|
||||||
satoshis: 1e9
|
satoshis: 1e9
|
||||||
};
|
};
|
||||||
plugins.sendBitcoins(db.FINGERPRINT_FUNDS, txDetails, function(err, txHash) {
|
plugins.sendBitcoins(db.FINGERPRINT_FUNDS, txDetails, function(err,
|
||||||
|
txHash) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
err.should.be.instanceof(Error);
|
err.should.be.instanceof(Error);
|
||||||
err.name.should.equal('InsufficientFunds');
|
err.name.should.equal('InsufficientFunds');
|
||||||
|
|
@ -268,4 +265,3 @@ describe('Plugins', function() {
|
||||||
|
|
||||||
describe('Trader', function() {});
|
describe('Trader', function() {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue