Refactor blockchain backing service

This commit is contained in:
Yemel Jardi 2014-08-28 14:23:49 -03:00
commit 33801e9587
12 changed files with 569 additions and 548 deletions

View file

@ -7,7 +7,7 @@ function FakeBlockchain(opts) {
}
FakeBlockchain.prototype.getTransactions = function(addresses, cb) {
return cb([]);
return cb(null, []);
};
@ -15,6 +15,9 @@ FakeBlockchain.prototype.fixUnspent = function(u) {
this.u = u;
};
FakeBlockchain.prototype.destroy = function() {
};
FakeBlockchain.prototype.getUnspent = function(addresses, cb) {
return cb(null, this.u || [{
'address': 'mji7zocy8QzYywQakwWf99w9bCT6orY1C1',
@ -41,9 +44,9 @@ FakeBlockchain.prototype.getUnspent2 = function(addresses, cb) {
}]);
};
FakeBlockchain.prototype.sendRawTransaction = function(rawtx, cb) {
FakeBlockchain.prototype.broadcast = function(rawtx, cb) {
var txid = '0be0fb4579911be829e3077202e1ab47fcc12cf3ab8f8487ccceae768e1f95fa';
return cb(txid);
return cb(null, txid);
};
FakeBlockchain.prototype.checkSentTx = function (tx, cb) {

View file

@ -0,0 +1,27 @@
'use strict';
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var FakeSocket = function (url, opts) {
var self = this;
self.connected = false;
setTimeout(function() {
self.connected = true;
self.emit('connect');
}, 0);
}
util.inherits(FakeSocket, EventEmitter);
FakeSocket.prototype.removeEventListener = function() {
return;
}
FakeSocket.prototype.destroy = function() {
this.connected = false;
this.removeAllListeners();
};
module.exports = FakeSocket;