migration fix + removed some old incoming checking
This commit is contained in:
parent
d9a9c9f4eb
commit
71aa425dd1
5 changed files with 20 additions and 53 deletions
|
|
@ -254,19 +254,6 @@ function reapOutgoingTx(session, tx) {
|
|||
});
|
||||
}
|
||||
|
||||
function reapIncomingTx(session, tx) {
|
||||
infoPlugin.checkAddress(tx.toAddress, tx.satoshis, function(err, status,
|
||||
satoshisReceived, txHash) {
|
||||
if (err) return logger.error(err);
|
||||
if (status === 'notSeen') return;
|
||||
var newTx = _.clone(tx);
|
||||
newTx.txHash = txHash;
|
||||
db.addIncomingTx(session, newTx, status, satoshisReceived, function(err) {
|
||||
if (err) logger.error(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function reapTx(row) {
|
||||
var session = {fingerprint: row.device_fingerprint, id: row.session_id};
|
||||
var tx = {
|
||||
|
|
@ -276,8 +263,7 @@ function reapTx(row) {
|
|||
currencyCode: row.currency_code,
|
||||
incoming: row.incoming
|
||||
};
|
||||
if (row.incoming) reapIncomingTx(session, tx);
|
||||
else reapOutgoingTx(session, tx);
|
||||
if (!row.incoming) reapOutgoingTx(session, tx);
|
||||
}
|
||||
|
||||
function reapTxs() {
|
||||
|
|
|
|||
|
|
@ -403,40 +403,6 @@ exports.sentCoins = function sentCoins(session, tx, authority, toSend, fee,
|
|||
});
|
||||
};
|
||||
|
||||
function maybeRemovePending(client, session, insufficientFunds, authority, cb) {
|
||||
|
||||
// Keep waiting for authorization, unless deposit is insufficient
|
||||
if (authority === 'published' && !insufficientFunds) return cb();
|
||||
|
||||
removePendingTx(client, session, cb);
|
||||
}
|
||||
|
||||
exports.addIncomingTx = function addIncomingTx(session, tx, authority,
|
||||
satoshisReceived, cb) {
|
||||
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
var satoshisRequested = tx.satoshis;
|
||||
var insufficientFunds = satoshisReceived < satoshisRequested;
|
||||
async.series([
|
||||
async.apply(silentQuery, client, 'BEGIN', null),
|
||||
async.apply(maybeRemovePending, client, session, insufficientFunds,
|
||||
authority),
|
||||
async.apply(insertIncoming, client, session, tx, satoshisReceived, 0,
|
||||
'deposit', authority)
|
||||
], function(err) {
|
||||
if (err) {
|
||||
rollback(client, done);
|
||||
return cb(err);
|
||||
}
|
||||
silentQuery(client, 'COMMIT', null, function() {
|
||||
done();
|
||||
cb();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function ensureNotFinal(client, session, cb) {
|
||||
var sql = 'SELECT id FROM transactions ' +
|
||||
'WHERE device_fingerprint=$1 AND session_id=$2 AND incoming=$3 ' +
|
||||
|
|
|
|||
|
|
@ -164,6 +164,11 @@ function pair(req, res) {
|
|||
);
|
||||
}
|
||||
|
||||
function registerRaqia(req, res) {
|
||||
var raqia = require('./raqia.json');
|
||||
res.json(raqia);
|
||||
}
|
||||
|
||||
function init(localConfig) {
|
||||
lamassuConfig = localConfig.lamassuConfig;
|
||||
plugins = localConfig.plugins;
|
||||
|
|
@ -184,6 +189,7 @@ function init(localConfig) {
|
|||
app.post('/verify_user', authMiddleware, verifyUser);
|
||||
app.post('/verify_transaction', authMiddleware, verifyTx);
|
||||
app.post('/pair', pair);
|
||||
app.get('/register_raqia', registerRaqia);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,22 @@
|
|||
var db = require('./db');
|
||||
|
||||
exports.up = function(next) {
|
||||
db.query('CREATE TABLE IF NOT EXISTS bills ( ' +
|
||||
var sqls = [
|
||||
'CREATE TABLE IF NOT EXISTS bills ( ' +
|
||||
'id uuid PRIMARY KEY, ' +
|
||||
'device_fingerprint text NOT NULL, ' +
|
||||
'denomination integer NOT NULL, ' +
|
||||
'currency_code text NOT NULL, ' +
|
||||
'satoshis integer NOT NULL, ' +
|
||||
'to_address text NOT NULL, ' +
|
||||
'session_id uuid NOT NULL, ' +
|
||||
'transaction_id uuid NOT NULL, ' +
|
||||
'device_time bigint NOT NULL, ' +
|
||||
'created timestamp NOT NULL DEFAULT now() )', next);
|
||||
'created timestamp NOT NULL DEFAULT now() )',
|
||||
|
||||
'ALTER TABLE bills RENAME COLUMN transaction_id TO session_id'
|
||||
];
|
||||
|
||||
db.multi(sqls, next);
|
||||
};
|
||||
|
||||
exports.down = function(next) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
"async": "~0.2.9",
|
||||
"bunyan": "~0.22.3",
|
||||
"express": "~3.4.7",
|
||||
"inquirer": "^0.8.0",
|
||||
"joi": "^5.1.0",
|
||||
"lamassu-bitcoinaverage": "~1.0.0",
|
||||
"lamassu-bitcoind": "~1.0.0",
|
||||
"lamassu-bitpay": "~1.0.0",
|
||||
|
|
@ -30,7 +32,8 @@
|
|||
"url": "https://github.com/lamassu/lamassu-server.git"
|
||||
},
|
||||
"bin": {
|
||||
"lamassu-server": "./bin/lamassu-server"
|
||||
"lamassu-server": "./bin/lamassu-server",
|
||||
"ssu-raqia": "./bin/ssu-raqia"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --recursive test"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue