Friendlier error reporting for sendRawTransaction
This commit is contained in:
parent
a10e2b4a43
commit
70fc47f343
@ -6,6 +6,7 @@
|
|||||||
var Address = require('../models/Address');
|
var Address = require('../models/Address');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
var Rpc = require('../../lib/Rpc');
|
var Rpc = require('../../lib/Rpc');
|
||||||
|
|
||||||
@ -14,7 +15,21 @@ var bdb = require('../../lib/BlockDb').default();
|
|||||||
|
|
||||||
exports.send = function(req, res) {
|
exports.send = function(req, res) {
|
||||||
Rpc.sendRawTransaction(req.body.rawtx, function(err, txid) {
|
Rpc.sendRawTransaction(req.body.rawtx, function(err, txid) {
|
||||||
if (err) return common.handleErrors(err, res);
|
if (err) {
|
||||||
|
var message;
|
||||||
|
if(err.code == -25) {
|
||||||
|
message = util.format(
|
||||||
|
'Generic error %s (code %s)',
|
||||||
|
err.message, err.code);
|
||||||
|
} else if(err.code == -26) {
|
||||||
|
message = util.format(
|
||||||
|
'Transaction rejected by network (code %s). Reason: %s',
|
||||||
|
err.code, err.message);
|
||||||
|
} else {
|
||||||
|
message = util.format('%s (code %s)', err.message, err.code);
|
||||||
|
}
|
||||||
|
return res.status(400).send(message);
|
||||||
|
}
|
||||||
res.json({'txid' : txid});
|
res.json({'txid' : txid});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -97,10 +97,8 @@ Rpc.getBlock = function(hash, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Rpc.sendRawTransaction = function(rawtx, cb) {
|
Rpc.sendRawTransaction = function(rawtx, cb) {
|
||||||
var self = this;
|
|
||||||
bitcoreRpc.sendRawTransaction(rawtx, function(err, txid) {
|
bitcoreRpc.sendRawTransaction(rawtx, function(err, txid) {
|
||||||
if (err && err.code === -5) return cb(err); // transaction already in block chain
|
if (err) return cb(err);
|
||||||
if (err) return cb(self.errMsg(err));
|
|
||||||
|
|
||||||
return cb(err, txid.result);
|
return cb(err, txid.result);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user