Make idempotent send work, together with a test
This commit is contained in:
parent
f90ded6144
commit
aa81cfe33b
2 changed files with 37 additions and 17 deletions
|
|
@ -26,8 +26,8 @@ PostgresqlInterface.prototype.summonTransaction =
|
|||
// If it worked, go ahead with transaction
|
||||
// If duplicate, fetch status and return
|
||||
var self = this;
|
||||
this.client.query('INSERT INTO transactions (id, status, deviceFingerprint, ' +
|
||||
'toAddress, satoshis, currencyCode, fiat) ' +
|
||||
this.client.query('INSERT INTO transactions (id, status, "deviceFingerprint", ' +
|
||||
'"toAddress", satoshis, "currencyCode", fiat) ' +
|
||||
'VALUES ($1, $2, $3, $4, $5, $6, $7)', [tx.txId, 'pending', deviceFingerprint,
|
||||
tx.toAddress, tx.satoshis, tx.currencyCode, tx.fiat],
|
||||
function (err) {
|
||||
|
|
@ -47,7 +47,7 @@ PostgresqlInterface.prototype.reportTransactionError =
|
|||
PostgresqlInterface.prototype.completeTransaction =
|
||||
function completeTransaction(tx, txHash) {
|
||||
if (txHash)
|
||||
this.client.query('UPDATE transactions SET txHash=$1, status=$2, completed=now() WHERE id=$3',
|
||||
this.client.query('UPDATE transactions SET "txHash"=$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',
|
||||
|
|
@ -56,14 +56,14 @@ PostgresqlInterface.prototype.completeTransaction =
|
|||
|
||||
PostgresqlInterface.prototype._fetchTransaction =
|
||||
function _fetchTransaction(txId, cb) {
|
||||
this.client.query('SELECT status, txHash FROM transactions WHERE id=$1',
|
||||
[txId], function (err, rows) {
|
||||
this.client.query('SELECT status, "txHash" 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 (rows === 0) return cb(new Error('Couldn\'t find transaction.'));
|
||||
if (results.rows.length === 0) return cb(new Error('Couldn\'t find transaction.'));
|
||||
|
||||
var result = rows[0];
|
||||
var result = results.rows[0];
|
||||
cb(null, false, result.txHash);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue