add rebroadcast test

This commit is contained in:
Matias Alejo Garcia 2014-08-05 16:25:02 -03:00
commit 5a2dfe690d
5 changed files with 131 additions and 66 deletions

View file

@ -2,6 +2,7 @@
var imports = require('soop').imports();
var bitcore = require('bitcore');
var coinUtil = bitcore.util;
var preconditions = require('preconditions').singleton();
var http;
@ -39,9 +40,9 @@ function _asyncForEach(array, fn, callback) {
function removeRepeatedElements(ar) {
var ya = false,
v = "",
aux = [].concat(ar),
r = Array();
v = "",
aux = [].concat(ar),
r = Array();
for (var i in aux) { //
v = aux[i];
ya = false;
@ -78,6 +79,25 @@ Insight.prototype._getOptions = function(method, path, data) {
};
};
// This is vulneable to txid maneability
// TODO: if ret = false,
// check output address from similar transactions.
//
Insight.prototype.checkSentTx = function(tx, cb) {
var hash = coinUtil.formatHashFull(tx.getHash());
var options = this._getOptions('GET', '/api/tx/' + hash);
this._request(options, function(err, res) {
if (err) return cb(err);
var ret = false;
if (res && res.txid === hash) {
ret = hash;
}
return cb(err, ret);
});
};
Insight.prototype.getTransactions = function(addresses, cb) {
preconditions.shouldBeArray(addresses);
preconditions.shouldBeFunction(cb);
@ -164,8 +184,8 @@ Insight.prototype.checkActivity = function(addresses, cb) {
var getOutputs = function(t) {
return flatArray(
t.vout.map(function(vout) {
return vout.scriptPubKey.addresses;
})
return vout.scriptPubKey.addresses;
})
);
};