feat(trade): trade now understands partial txs

This commit is contained in:
Damian Mee 2014-09-09 07:00:02 +02:00
parent be6900a7a9
commit f37b210c2e

View file

@ -184,10 +184,32 @@ exports.trade = function trade(rawTrade, deviceFingerprint) {
};
}
// record (vel log) inserted bill
db.recordBill(deviceFingerprint, rawTrade);
// cache partial Transaction (if supported by machine)
if (rawTrade.partialTx) {
var tx = {
txId: rawTrade.txId,
status: 'partial',
toAddress: rawTrade.toAddress,
currencyCode: rawTrade.currency,
satoshis: rawTrade.partialTx.satoshis,
fiat: rawTrade.partialTx.fiat
};
db.summonTransaction(deviceFingerprint, tx, function(err, txInfo) {
logger.debug('plugins|cache|err', err);
logger.debug('plugins|cache|info', txInfo);
});
}
// add bill to trader queue (if trader is enabled)
if (traderPlugin) {
tradesQueue.push({
currency: rawTrade.currency,
satoshis: rawTrade.satoshis
});
}
};
exports.fiatBalance = function fiatBalance() {
@ -222,7 +244,7 @@ exports.sendBitcoins = function sendBitcoins(deviceFingerprint, tx, callback) {
db.summonTransaction(deviceFingerprint, tx, function(err, txInfo) {
if (err) return callback(err);
if (!txInfo) {
if (!txInfo || txInfo.status === 'partial') {
clearSession(deviceFingerprint);
return walletPlugin.sendBitcoins(