WIP 1st stage refactor to new DB
This commit is contained in:
parent
dc6740ddf2
commit
0cec3670a9
3 changed files with 96 additions and 64 deletions
|
|
@ -188,19 +188,17 @@ function _sendBitcoins(toAddress, satoshis, cb) {
|
|||
}
|
||||
|
||||
function executeTx(deviceFingerprint, tx, cb) {
|
||||
db.addTx(deviceFingerprint, tx, function(err, result) {
|
||||
db.addOutgoingTx(deviceFingerprint, tx, function(err, satoshisToSend) {
|
||||
if (err) return cb(err);
|
||||
var satoshisToSend = result.satoshisToSend;
|
||||
var dbTxId = result.id;
|
||||
|
||||
if (satoshisToSend === 0)
|
||||
return cb(null, {statusCode: 204, txId: tx.txId, txHash: null});
|
||||
|
||||
_sendBitcoins(tx.toAddress, satoshisToSend, function(err, txHash) {
|
||||
_sendBitcoins(tx.toAddress, satoshisToSend, function(_err, txHash) {
|
||||
var fee = null; // Need to fill this out in plugins
|
||||
db.addDigitalTx(dbTxId, err, txHash, fee);
|
||||
db.sentCoins(tx, satoshisToSend, fee, _err, txHash);
|
||||
|
||||
if (err) return cb(err);
|
||||
if (_err) return cb(err);
|
||||
|
||||
pollBalance();
|
||||
cb(null, {
|
||||
|
|
@ -212,16 +210,16 @@ function executeTx(deviceFingerprint, tx, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function reapIncomingTx(deviceFingerprint, tx) {
|
||||
function reapOutgoingTx(deviceFingerprint, tx) {
|
||||
executeTx(deviceFingerprint, tx, function(err) {
|
||||
if (err) logger.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
function reapOutgoingTx(deviceFingerprint, tx) {
|
||||
function reapIncomingTx(deviceFingerprint, tx) {
|
||||
infoPlugin.checkAddress(tx.toAddress, function(err, status, satoshisReceived) {
|
||||
if (status === 'notSeen') return;
|
||||
db.addOutgoingTx(deviceFingerprint, tx, status, satoshisReceived);
|
||||
db.addIngoingTx(deviceFingerprint, tx, status, satoshisReceived);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +317,7 @@ exports.cashOut = function cashOut(deviceFingerprint, tx, cb) {
|
|||
return cb(new Error(err));
|
||||
|
||||
tx.toAddress = address;
|
||||
tx.incoming = false;
|
||||
tx.incoming = true;
|
||||
|
||||
db.addPendingTx(deviceFingerprint, tx, function(err) {
|
||||
cb(err, address);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue