Merge pull request #1516 from matiu/bug/invalid-tx

Bug/invalid tx
This commit is contained in:
Gustavo Maximiliano Cortez 2014-10-01 13:12:56 -03:00
commit 76e98d6e87
6 changed files with 614 additions and 44133 deletions

View file

@ -197,8 +197,8 @@ Insight.prototype.broadcast = function(rawtx, cb) {
this.requestPost('/api/tx/send', { this.requestPost('/api/tx/send', {
rawtx: rawtx rawtx: rawtx
}, function(err, res, body) { }, function(err, res, body) {
if (err || res.statusCode != 200) cb(err || res); if (err || res.status != 200) cb(err || res);
cb(null, body.txid); cb(null, body ? body.txid: null);
}); });
}; };

View file

@ -10,6 +10,7 @@ var Script = bitcore.Script;
var Key = bitcore.Key; var Key = bitcore.Key;
var buffertools = bitcore.buffertools; var buffertools = bitcore.buffertools;
var preconditions = require('preconditions').instance(); var preconditions = require('preconditions').instance();
var log = require('../log');
function TxProposals(opts) { function TxProposals(opts) {
opts = opts || {}; opts = opts || {};
@ -27,11 +28,16 @@ TxProposals.fromObj = function(o, forceOpts) {
}); });
o.txps.forEach(function(o2) { o.txps.forEach(function(o2) {
var t = TxProposal.fromObj(o2, forceOpts); try {
if (t.builder) { var t = TxProposal.fromObj(o2, forceOpts);
} catch (e) {
log.info('Ignoring corrupted TxProposal:', o2, e);
}
if (t && t.builder) {
var id = t.getId(); var id = t.getId();
ret.txps[id] = t; ret.txps[id] = t;
} }
}); });
return ret; return ret;
}; };

View file

@ -341,7 +341,7 @@ Wallet.prototype._checkSentTx = function(ntxid, cb) {
this.blockchain.getTransaction(txid, function(err, tx) { this.blockchain.getTransaction(txid, function(err, tx) {
if (err) return cb(false); if (err) return cb(false);
cb(ret); return cb(ret);
}); });
}; };

File diff suppressed because one or more lines are too long

View file

@ -40,12 +40,14 @@ describe('TxProposals', function() {
should.exist(txps); should.exist(txps);
txps.network.name.should.equal('livenet'); txps.network.name.should.equal('livenet');
}); });
it('should fail create an instance from an Object with errors', function() { it('should skip Objects with errors', function() {
(function() {var txps = TxProposals.fromObj({ var txps = TxProposals.fromObj({
networkName:'livenet', networkName:'livenet',
walletId: '123a12', walletId: '123a12',
txps: [ { a: 1 }], txps: [ { a: 1 }],
}) }).should.throw('Illegal'); });
should.exist(txps);
Object.keys(txps.txps).length.should.equal(0);
}); });
}); });
describe('#getNtxids', function() { describe('#getNtxids', function() {

View file

@ -128,7 +128,7 @@ describe('Insight model', function() {
sinon.stub(blockchain, "requestPost", function(url, data, cb) { sinon.stub(blockchain, "requestPost", function(url, data, cb) {
url.should.be.equal('/api/tx/send'); url.should.be.equal('/api/tx/send');
var res = {statusCode: 200}; var res = {status: 200};
var body = {txid: 1234}; var body = {txid: 1234};
setTimeout(function() { setTimeout(function() {
cb(null, res, body); cb(null, res, body);