Skip to content

Commit

Permalink
Merge pull request #6 from cmgustavo/feature/tx-details
Browse files Browse the repository at this point in the history
Feature/tx details
  • Loading branch information
Ryan X. Charles committed Mar 12, 2014
2 parents e918dea + 9ec9887 commit 7f188bf
Show file tree
Hide file tree
Showing 77 changed files with 27 additions and 9,636 deletions.
12 changes: 4 additions & 8 deletions lib/coinpunk/controllers/tx.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var controller = require("./controller.js");

var TxController = function (root, express, db, bitcoind, insight) {
this.bitcoind = bitcoind;
var TxController = function (root, express, db, insight) {
this.insight = insight;
controller.Controller.call(this, root, express, db, insight);
};
Expand Down Expand Up @@ -50,24 +49,21 @@ TxController.prototype._search_hashes = function(req,res) {
return;
}

for(i=0;i<req.body.txHashes.length;i++) {
queries.push({method: 'getrawtransaction', params: [req.body.txHashes[i], 1]});
}
this.bitcoind.batch(queries, function(err, results) {
this.insight.getTransactions(req.body.txHashes, function(err, results) {
if(err) console.log(err);

var txes = [];

for(var i=0; i<results.length;i++) {
var result = results[i].result;
var result = results[i];
if(result === null)
continue;

txes.push({
hash: result.txid,
time: result.time,
amount: result.amount,
fee: result.fee,
fee: result.fees,
confirmations: result.confirmations || 0,
blockhash: result.blockhash,
blockindex: result.blockindex,
Expand Down
3 changes: 1 addition & 2 deletions lib/coinpunk/controllers/wallet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var controller = require('./controller.js');
var speakeasy = require('speakeasy');

var WalletController = function (root, express, db, bitcoind, websocket, insight) {
var WalletController = function (root, express, db, websocket, insight) {
var that = this;
that.bitcoind = bitcoind;
controller.Controller.call(this, root, express, db, insight);

// Set up a websocket for streaming transactions.
Expand Down
6 changes: 3 additions & 3 deletions lib/coinpunk/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ var wallet = require('./controllers/wallet.js');
var tx = require('./controllers/tx.js');
var user = require('./controllers/user.js');

module.exports.create = function (express, db, bitcoind, websocket, insight) {
module.exports.create = function (express, db, websocket, insight) {
// Create our controllers.
// The third parameter passed is the new REST API root.
var authKeyController = new authkey.AuthKeyController(
'/api/dev/authkey', express, db
);

var walletController = new wallet.WalletController(
'/api/dev/wallet', express, db, bitcoind, websocket, insight
'/api/dev/wallet', express, db, websocket, insight
);

var txController = new tx.TxController(
'/api/dev/tx', express, db, bitcoind, insight
'/api/dev/tx', express, db, insight
);

var userController = new user.UserController(
Expand Down
4 changes: 1 addition & 3 deletions lib/coinpunk/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var express = require('express');
var request = require('request');
var Bitcoind = require('./server/bitcoind');
var Insight = require('./server/insight');
var MongoDB = require('./server/db/mongo');
var sockjs = require('sockjs');
Expand All @@ -11,7 +10,6 @@ var routes = require('./routes.js');

var Server = function (config) {
this.config = config;
this.bitcoind = new Bitcoind(config.bitcoind);
this.insight = new Insight(config.insight);
this.express = express();
this.db = new MongoDB();
Expand All @@ -38,7 +36,7 @@ Server.prototype.start = function () {

// Set up routes, connect databases.
that.db.connect(that.config.mongoURL);
routes.create(that.express, that.db, that.bitcoind, that.websocket, that.insight);
routes.create(that.express, that.db, that.websocket, that.insight);

if(that.config.httpsPort || that.config.sslKey || that.config.sslCert) {
var httpsServer = https.createServer({
Expand Down
57 changes: 0 additions & 57 deletions lib/coinpunk/server/bitcoind.js

This file was deleted.

18 changes: 18 additions & 0 deletions lib/coinpunk/server/insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ Insight.prototype.sendRawTransaction = function(rawtx, callback) {
});
};

Insight.prototype.getTransactions = function(rawtx, callback) {
var self = this;
var url = this.url.href + '/tx/';

if (!rawtx || !rawtx.length) return callback(undefined,[]);

var all = [];
async.eachSeries(rawtx,function(tx, cb) {
request(url + tx, function(err,res, body) {
if (!err && res.statusCode == 200) {
all.push(JSON.parse(body));
}
return cb(err);
});
}, function(err) {
return callback(err,all);
});
};

Insight.prototype.request = function(path, callback) {
var u = this.url.href + path;
Expand Down
1 change: 0 additions & 1 deletion node_modules/redis-mock/.gitattributes

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/redis-mock/.npmignore

This file was deleted.

9 changes: 0 additions & 9 deletions node_modules/redis-mock/.travis.yml

This file was deleted.

13 changes: 0 additions & 13 deletions node_modules/redis-mock/Makefile

This file was deleted.

114 changes: 0 additions & 114 deletions node_modules/redis-mock/README.md

This file was deleted.

Loading

0 comments on commit 7f188bf

Please sign in to comment.