merged in latest from master
This commit is contained in:
commit
142dbe7f8b
6 changed files with 85 additions and 72 deletions
|
|
@ -39,16 +39,16 @@ PostgresqlInterface.prototype.recordDeviceEvent =
|
|||
cb);
|
||||
};
|
||||
|
||||
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);
|
||||
|
|
@ -57,30 +57,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});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue