Skip to content

Commit 492abec

Browse files
committed
Merge pull request bitpay#2 from bitpay/insight-bitcore-api
Insight bitcore api -- This commit convert insight in an API (without front-end)
2 parents f3d1dac + 924d67c commit 492abec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+95
-2913
lines changed

.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.ctags

Lines changed: 0 additions & 11 deletions
This file was deleted.

.editorconfig

Lines changed: 0 additions & 21 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ npm-debug.log
2727
.nodemonignore
2828

2929
.DS_Store
30-
public/lib/*
3130
db/txs/*
3231
db/txs
3332
db/testnet/txs/*
@@ -37,10 +36,4 @@ db/blocks
3736
db/testnet/blocks/*
3837
db/testnet/blocks
3938

40-
public/js/angularjs-all.js
41-
public/js/main.js
42-
public/js/vendors.js
43-
44-
public/css/main.css
45-
4639
README.html

Gruntfile.js

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ module.exports = function(grunt) {
55
//Load NPM tasks
66
grunt.loadNpmTasks('grunt-contrib-watch');
77
grunt.loadNpmTasks('grunt-contrib-jshint');
8-
grunt.loadNpmTasks('grunt-contrib-uglify');
9-
grunt.loadNpmTasks('grunt-contrib-concat');
10-
grunt.loadNpmTasks('grunt-css');
118
grunt.loadNpmTasks('grunt-mocha-test');
129
grunt.loadNpmTasks('grunt-nodemon');
1310
grunt.loadNpmTasks('grunt-concurrent');
@@ -22,37 +19,12 @@ module.exports = function(grunt) {
2219
files: ['README.md'],
2320
tasks: ['markdown']
2421
},
25-
jade: {
26-
files: ['app/views/**'],
27-
options: {
28-
livereload: true,
29-
},
30-
},
3122
js: {
32-
files: ['Gruntfile.js', 'insight.js', 'app/**/*.js', 'public/js/**'],
23+
files: ['Gruntfile.js', 'insight.js', 'app/**/*.js'],
3324
tasks: ['jshint'],
3425
options: {
3526
livereload: true,
3627
},
37-
},
38-
assets: {
39-
files: ['public/src/**/*.js', 'public/**/*.css'],
40-
tasks: ['compile'],
41-
options: {
42-
livereload: true,
43-
},
44-
},
45-
html: {
46-
files: ['public/views/**'],
47-
options: {
48-
livereload: true,
49-
},
50-
},
51-
css: {
52-
files: ['public/css/**'],
53-
options: {
54-
livereload: true
55-
}
5628
},
5729
// we monitor only app/models/* because we have test for models only now
5830
// test: {
@@ -62,64 +34,12 @@ module.exports = function(grunt) {
6234
},
6335
jshint: {
6436
all: {
65-
src: ['Gruntfile.js', 'insight.js', 'app/**/*.js', 'public/src/js/**/*.js','lib/*.js'],
37+
src: ['Gruntfile.js', 'insight.js', 'app/**/*.js', 'lib/*.js', 'config/*.js'],
6638
options: {
6739
jshintrc: true
6840
}
6941
}
7042
},
71-
concat: {
72-
options: {
73-
process: function(src, filepath) {
74-
if (filepath.substr(filepath.length - 2) === 'js') {
75-
return '// Source: ' + filepath + '\n' +
76-
src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');
77-
} else {
78-
return src;
79-
}
80-
}
81-
},
82-
vendors: {
83-
src: ['public/lib/momentjs/min/moment.min.js', 'public/lib/qrcode-generator/js/qrcode.js', 'public/lib/zeroclipboard/ZeroClipboard.min.js'],
84-
dest: 'public/js/vendors.js'
85-
},
86-
angular: {
87-
src: ['public/lib/angular/angular.min.js', 'public/lib/angular-resource/angular-resource.min.js', 'public/lib/angular-route/angular-route.min.js', 'public/lib/angular-qrcode/qrcode.js', 'public/lib/angular-animate/angular-animate.min.js', 'public/lib/angular-bootstrap/ui-bootstrap.min.js', 'public/lib/angular-bootstrap/ui-bootstrap-tpls.min.js', 'public/lib/angular-ui-utils/ui-utils.min.js', 'public/lib/ngprogress/build/ngProgress.min.js'],
88-
dest: 'public/js/angularjs-all.js'
89-
},
90-
main: {
91-
src: ['public/src/js/app.js', 'public/src/js/controllers/*.js', 'public/src/js/services/*.js', 'public/src/js/directives.js', 'public/src/js/filters.js', 'public/src/js/config.js', 'public/src/js/init.js'],
92-
dest: 'public/js/main.js'
93-
},
94-
css: {
95-
src: ['public/src/css/**/*.css'],
96-
dest: 'public/css/main.css'
97-
}
98-
},
99-
uglify: {
100-
options: {
101-
banner: '/*! <%= pkg.name %> <%= pkg.version %> */\n',
102-
mangle: false
103-
},
104-
vendors: {
105-
src: 'public/js/vendors.js',
106-
dest: 'public/js/vendors.min.js'
107-
},
108-
angular: {
109-
src: 'public/js/angularjs-all.js',
110-
dest: 'public/js/angularjs-all.min.js'
111-
},
112-
main: {
113-
src: 'public/js/main.js',
114-
dest: 'public/js/main.min.js'
115-
}
116-
},
117-
cssmin: {
118-
css: {
119-
src: 'public/css/main.css',
120-
dest: 'public/css/main.min.css'
121-
}
122-
},
12343
mochaTest: {
12444
options: {
12545
reporter: 'spec',
@@ -131,7 +51,7 @@ module.exports = function(grunt) {
13151
script: 'insight.js',
13252
options: {
13353
args: [],
134-
ignore: ['public/**/*.html','public/**/*.css', 'public/**/*.js', 'test/**/*','util/**/*', ,'dev-util/**/*'],
54+
ignore: ['test/**/*', 'util/**/*', 'dev-util/**/*'],
13555
// nodeArgs: ['--debug'],
13656
delayTime: 1,
13757
env: {
@@ -170,10 +90,7 @@ module.exports = function(grunt) {
17090
grunt.option('force', true);
17191

17292
//Default task(s).
173-
grunt.registerTask('default', ['jshint', 'compile', 'concurrent']);
174-
175-
//Compile task (concat + minify)
176-
grunt.registerTask('compile', ['concat', 'uglify', 'cssmin']);
93+
grunt.registerTask('default', ['jshint', 'concurrent']);
17794

17895
//Test task.
17996
grunt.registerTask('test', ['env:test', 'mochaTest']);

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# *insight*
1+
# *insight API*
22

33
*insight* is an open-source bitcoin blockchain explorer with complete REST
4-
and websocket APIs. Insight runs in NodeJS, uses AngularJS for the
5-
front-end and LevelDB for storage.
4+
and websocket APIs. Insight runs in NodeJS and use LevelDB for storage.
65

76
Check some screenshots and more details at [insight's project homepage](http://insight.bitcore.io).
87

@@ -16,7 +15,7 @@ thru the RPC API, Peer-to-peer protocol and will even read its raw .dat files fo
1615

1716
Configure bitcoind to listen to RPC calls and set `txindex` to true.
1817
The easiest way to do this is by copying `./etc/bitcoind/bitcoin.conf` to your
19-
bitcoin data directory (usually `"~/.bitcoin"` on Linux, `"%appdata%\Bitcoin\"` on Windows,
18+
bitcoin data directory (usually `"~/.bitcoin"` on Linux, `"%appdata%\Bitcoin\"` on Windows,
2019
or `"~/Library/Application Support/Bitcoin"` on Mac OS X).
2120

2221
bitcoind must be running and must have finished downloading the blockchain **before** running *insight*.
@@ -36,7 +35,7 @@ bitcoind must be running and must have finished downloading the blockchain **bef
3635
Install dependencies:
3736

3837
$ npm install
39-
38+
4039
Run the main application:
4140

4241
$ node insight.js
@@ -48,7 +47,7 @@ bitcoind must be running and must have finished downloading the blockchain **bef
4847
Please note that the app will need to sync its internal database
4948
with the blockchain state, which may take some time. You can check
5049
sync progress from within the web interface.
51-
50+
5251

5352
## Configuration
5453

@@ -74,11 +73,11 @@ In case the network is changed (testnet to livenet or vice versa) levelDB databa
7473

7574
The initial synchronization process scans the blockchain from the paired bitcoind server to update addresses and balances. *insight* needs one (and only one) trusted bitcoind node to run. This node must have finished downloading the blockchain befure running *insight*.
7675

77-
While *insight* is synchronizing the website can be accessed (the sync process is embedded in the webserver), but there may be missing data or incorrect balances for addresses. The 'sync' status is shown on the top-right of all pages.
76+
While *insight* is synchronizing the website can be accessed (the sync process is embedded in the webserver), but there may be missing data or incorrect balances for addresses. The 'sync' status is shown on the top-right of all pages.
7877

7978
The blockchain can be read from bitcoind's raw `.dat` files or RPC interface. Reading the information from the `.dat` files is much faster so it's the recommended (and default) alternative. `.dat` files are scanned in the default location for each platform. In case a non-standard location is used, it needs to be defined (see the Configuration section). The synchronization type being used can be seen at the [Status page](http://localhost:3001/status). As of February 2014, using `.dat` files the sync process takes 7 hrs. for livenet and 20 mins. for testnet.
8079

81-
While synchronizing the blockchain, *insight* listens for new blocks and transactions relayed by the bitcoind node. Those are also stored on *insight*'s database. In case *insight* is shutdown for a period of time, restarting it will trigger a partial (historic) synchronization of the blockchain. Depending on the size of that synchronization task, a reverse RPC or forward `.dat` syncing strategy will be used.
80+
While synchronizing the blockchain, *insight* listens for new blocks and transactions relayed by the bitcoind node. Those are also stored on *insight*'s database. In case *insight* is shutdown for a period of time, restarting it will trigger a partial (historic) synchronization of the blockchain. Depending on the size of that synchronization task, a reverse RPC or forward `.dat` syncing strategy will be used.
8281
8382
If bitcoind is shutdown, *insight* needs to be stopped and restarted once bitcoind is restarted.
8483
@@ -95,9 +94,9 @@ If bitcoind is shutdown, *insight* needs to be stopped and restarted once bitcoi
9594
9695
### DB storage requirement
9796
98-
To store the blockchain and address related information, *insight* uses LevelDB. Two DBs are created: txs and blocks. By default these are stored on
99-
```<insight root>/db```
100-
97+
To store the blockchain and address related information, *insight* uses LevelDB. Two DBs are created: txs and blocks. By default these are stored on
98+
```<insight root>/db```
99+
101100
this can be changed on config/config.js. As of February 2014, storing the livenet blockchain takes ~30GB of disk space (2GB for the testnet).
102101
103102
## Development
@@ -106,10 +105,6 @@ To run insight locally for development with grunt:
106105
107106
```$ NODE_ENV=development grunt```
108107
109-
To compile and minify the web application's assets:
110-
111-
```$ grunt compile```
112-
113108
To run the tests
114109
115110
```$ grunt test```
@@ -120,7 +115,9 @@ Contributions and suggestions are welcomed at [insight github repository](https:
120115
121116
## API
122117
123-
A REST API is provided at /api. The entry points are:
118+
By default, insight provides a REST API at /api, but this prefix is configurable from the var `apiPrefix` in the `config.js` file.
119+
120+
The end-points are:
124121
125122
126123
### Block

app/controllers/addresses.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var getAddr = function(req, res, next) {
2323
exports.show = function(req, res, next) {
2424
var a = getAddr(req, res, next);
2525

26-
if (a)
26+
if (a)
2727
a.update(function(err) {
2828
if (err) {
2929
return common.handleErrors(err, res);
@@ -39,7 +39,7 @@ exports.show = function(req, res, next) {
3939
exports.utxo = function(req, res, next) {
4040
var a = getAddr(req, res, next);
4141

42-
if (a)
42+
if (a)
4343
a.getUtxo(function(err, utxo) {
4444
if (err)
4545
return common.handleErrors(err, res);

app/controllers/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
'use strict';
22

3+
var _getVersion = function() {
4+
var pjson = require('../../package.json');
5+
return pjson.version;
6+
};
7+
38
exports.render = function(req, res) {
4-
res.render('index');
9+
var version = _getVersion();
10+
res.send('insight API v' + version);
511
};
612

713
exports.version = function(req, res) {
8-
var pjson = require('../../package.json');
9-
res.json({version: pjson.version});
14+
var version = _getVersion();
15+
res.json({ version: version });
1016
};
1117

app/controllers/socket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports.broadcastTx = function(tx) {
2222
t = {
2323
txid: tx
2424
};
25-
}
25+
}
2626

2727
else {
2828
t = {

app/controllers/transactions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var getTransaction = function(txid, cb) {
4747
if (err) console.log(err);
4848

4949
if (!tx || !tx.info) {
50-
console.log('[transactions.js.48]:: TXid %s not found in RPC. CHECK THIS.', txid);
50+
console.log('[transactions.js.48]:: TXid %s not found in RPC. CHECK THIS.', txid);
5151
return ({ txid: txid });
5252
}
5353

0 commit comments

Comments
 (0)