Rename from Insight to bitcore-node
This commit is contained in:
parent
1d13343bbe
commit
dbb1e015f7
|
@ -19,7 +19,7 @@ module.exports = function(grunt) {
|
|||
tasks: ['markdown']
|
||||
},
|
||||
js: {
|
||||
files: ['Gruntfile.js', 'insight.js', 'app/**/*.js'],
|
||||
files: ['Gruntfile.js', 'index.js', 'app/**/*.js'],
|
||||
options: {
|
||||
livereload: true,
|
||||
},
|
||||
|
@ -31,7 +31,7 @@ module.exports = function(grunt) {
|
|||
},
|
||||
jshint: {
|
||||
all: {
|
||||
src: ['Gruntfile.js', 'insight.js', 'app/**/*.js', 'lib/*.js', 'config/*.js'],
|
||||
src: ['Gruntfile.js', 'index.js', 'app/**/*.js', 'lib/*.js', 'config/*.js'],
|
||||
options: {
|
||||
jshintrc: true
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ module.exports = function(grunt) {
|
|||
},
|
||||
nodemon: {
|
||||
dev: {
|
||||
script: 'insight.js',
|
||||
script: 'index.js',
|
||||
options: {
|
||||
args: [],
|
||||
ignore: ['test/**/*', 'util/**/*', 'dev-util/**/*'],
|
||||
|
|
77
README.md
77
README.md
|
@ -1,23 +1,10 @@
|
|||
# *insight API*
|
||||
|
||||
*insight API* is an open-source bitcoin blockchain REST
|
||||
and websocket API. Insight API runs in NodeJS and uses LevelDB for storage.
|
||||
|
||||
This is a backend-only service. If you're looking for the web frontend application,
|
||||
take a look at https://github.com/bitpay/insight.
|
||||
|
||||
*Insight API* allows to develop bitcoin-related applications (such as wallets) that
|
||||
require certain information from the blockchain that bitcoind does not provide.
|
||||
|
||||
A blockchain explorer front-end has been developed on top of *Insight API*. It can
|
||||
be downloaded at [Github Insight Repository](https://github.com/bitpay/insight).
|
||||
|
||||
# bitcore-node
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* **bitcoind** - Download and Install [Bitcoin](http://bitcoin.org/en/download)
|
||||
|
||||
*insight API* needs a *trusted* bitcoind node to run. *insight API* will connect to the node
|
||||
`bitcore-node` needs a *trusted* bitcoind node to run. It will connect to the node
|
||||
through the RPC API, bitcoin peer-to-peer protocol, and will even read its raw block .dat files for syncing.
|
||||
|
||||
Configure bitcoind to listen to RPC calls and set `txindex` to true.
|
||||
|
@ -25,7 +12,7 @@ The easiest way to do this is by copying `./etc/bitcoind/bitcoin.conf` to your
|
|||
bitcoin data directory (usually `~/.bitcoin` on Linux, `%appdata%\Bitcoin\` on Windows,
|
||||
or `~/Library/Application Support/Bitcoin` on Mac OS X).
|
||||
|
||||
bitcoind must be running and must have finished downloading the blockchain **before** running *insight API*.
|
||||
bitcoind must be running and must have finished downloading the blockchain **before** running `bitcore-node`.
|
||||
|
||||
|
||||
* **Node.js v0.10.x** - Download and Install [Node.js](http://www.nodejs.org/download/).
|
||||
|
@ -35,9 +22,9 @@ bitcoind must be running and must have finished downloading the blockchain **bef
|
|||
## Quick Install
|
||||
Check the Prerequisites section above before installing.
|
||||
|
||||
To install Insight API, clone the main repository:
|
||||
To install `bitcore-node`, clone the main repository:
|
||||
|
||||
$ git clone https://github.com/bitpay/insight-api && cd insight-api
|
||||
$ git clone https://github.com/bitpay/bitcore-node && cd bitcore-node
|
||||
|
||||
Install dependencies:
|
||||
|
||||
|
@ -45,7 +32,7 @@ bitcoind must be running and must have finished downloading the blockchain **bef
|
|||
|
||||
Run the main application:
|
||||
|
||||
$ node insight.js
|
||||
$ node index.js
|
||||
|
||||
Then open a browser and go to:
|
||||
|
||||
|
@ -68,11 +55,11 @@ BITCOIND_P2P_PORT # P2P bitcoind Port
|
|||
BITCOIND_USER # RPC username
|
||||
BITCOIND_PASS # RPC password
|
||||
BITCOIND_DATADIR # bitcoind datadir. 'testnet3' will be appended automatically if testnet is used. NEED to finish with '/'. e.g: `/vol/data/`
|
||||
INSIGHT_NETWORK [= 'livenet' | 'testnet']
|
||||
INSIGHT_PORT # insight api port
|
||||
INSIGHT_DB # Path where to store insight's internal DB. (defaults to $HOME/.insight)
|
||||
INSIGHT_SAFE_CONFIRMATIONS=6 # Nr. of confirmation needed to start caching transaction information
|
||||
INSIGHT_IGNORE_CACHE # True to ignore cache of spents in transaction, with more than INSIGHT_SAFE_CONFIRMATIONS confirmations. This is useful for tracking double spents for old transactions.
|
||||
BLOCKCHAIN_API_NETWORK [= 'livenet' | 'testnet']
|
||||
BLOCKCHAIN_API_PORT # blockchain api port
|
||||
BLOCKCHAIN_API_DB # Path where to store bitcore-node's internal DB. (defaults to $HOME/.bitcore-node)
|
||||
BLOCKCHAIN_API_SAFE_CONFIRMATIONS=6 # Nr. of confirmation needed to start caching transaction information
|
||||
BLOCKCHAIN_API_IGNORE_CACHE # True to ignore cache of spents in transaction, with more than BLOCKCHAIN_API_SAFE_CONFIRMATIONS confirmations. This is useful for tracking double spents for old transactions.
|
||||
LOGGER_LEVEL # defaults to 'info', can be 'debug','verbose','error', etc.
|
||||
ENABLE_HTTPS # if "true" it will server using SSL/HTTPS
|
||||
```
|
||||
|
@ -80,13 +67,13 @@ ENABLE_HTTPS # if "true" it will server using SSL/HTTPS
|
|||
Make sure that bitcoind is configured to [accept incoming connections using 'rpcallowip'](https://en.bitcoin.it/wiki/Running_Bitcoin).
|
||||
|
||||
In case the network is changed (testnet to livenet or vice versa) levelDB database needs to be deleted. This can be performed running:
|
||||
```util/sync.js -D``` and waiting for *insight* to synchronize again. Once the database is deleted, the sync.js process can be safely interrupted (CTRL+C) and continued from the synchronization process embedded in main app.
|
||||
```util/sync.js -D``` and waiting for `bitcore-node` to synchronize again. Once the database is deleted, the sync.js process can be safely interrupted (CTRL+C) and continued from the synchronization process embedded in main app.
|
||||
|
||||
## Synchronization
|
||||
|
||||
The initial synchronization process scans the blockchain from the paired bitcoind server to update addresses and balances. *insight-api* needs exactly one trusted bitcoind node to run. This node must have finished downloading the blockchain before running *insight-api*.
|
||||
The initial synchronization process scans the blockchain from the paired bitcoind server to update addresses and balances. `bitcore-node` needs exactly one trusted bitcoind node to run. This node must have finished downloading the blockchain before running `bitcore-node`.
|
||||
|
||||
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 at the `/api/sync` endpoint.
|
||||
While `bitcore-node` 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 at the `/api/sync` endpoint.
|
||||
|
||||
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
|
||||
|
@ -96,13 +83,13 @@ non-standard location is used, it needs to be defined (see the Configuration sec
|
|||
As of June 2014, using `.dat` files the sync process takes 9 hrs.
|
||||
for livenet and 30 mins. for testnet.
|
||||
|
||||
While synchronizing the blockchain, *insight-api* listens for new blocks and
|
||||
transactions relayed by the bitcoind node. Those are also stored on *insight-api*'s database.
|
||||
In case *insight-api* is shutdown for a period of time, restarting it will trigger
|
||||
While synchronizing the blockchain, `bitcore-node` listens for new blocks and
|
||||
transactions relayed by the bitcoind node. Those are also stored on `bitcore-node`'s database.
|
||||
In case `bitcore-node` 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.
|
||||
|
||||
If bitcoind is shutdown, *insight-api* needs to be stopped and restarted
|
||||
If bitcoind is shutdown, `bitcore-node` needs to be stopped and restarted
|
||||
once bitcoind is restarted.
|
||||
|
||||
### Syncing old blockchain data manually
|
||||
|
@ -114,24 +101,22 @@ once bitcoind is restarted.
|
|||
Check util/sync.js --help for options, particulary -D to erase the current DB.
|
||||
|
||||
*NOTE*: there is no need to run this manually since the historic synchronization
|
||||
is built in into the web application. Running *insight-api* normally will trigger
|
||||
is built in into the web application. Running `bitcore-node` normally will trigger
|
||||
the historic sync automatically.
|
||||
|
||||
|
||||
### DB storage requirement
|
||||
|
||||
To store the blockchain and address related information, *insight-api* uses LevelDB.
|
||||
To store the blockchain and address related information, LevelDB is used.
|
||||
Two DBs are created: txs and blocks. By default these are stored on
|
||||
|
||||
``~/.insight/``
|
||||
|
||||
Please note that some older versions of Insight-API store that on `<insight's root>/db`.
|
||||
``~/.bitcore-node/``
|
||||
|
||||
This can be changed at config/config.js. As of June 2014, storing the livenet blockchain takes ~35GB of disk space (2GB for the testnet).
|
||||
|
||||
## Development
|
||||
|
||||
To run insight locally for development with grunt:
|
||||
To run `bitcore-node` locally for development with grunt:
|
||||
|
||||
```$ NODE_ENV=development grunt```
|
||||
|
||||
|
@ -140,12 +125,10 @@ To run the tests
|
|||
```$ grunt test```
|
||||
|
||||
|
||||
Contributions and suggestions are welcome at [insight-api github repository](https://github.com/bitpay/insight-api).
|
||||
|
||||
## Caching schema
|
||||
|
||||
Since v0.2 a new cache schema has been introduced. Only information from transactions with
|
||||
INSIGHT_SAFE_CONFIRMATIONS settings will be cached (by default SAFE_CONFIRMATIONS=6). There
|
||||
BLOCKCHAIN_API_SAFE_CONFIRMATIONS settings will be cached (by default SAFE_CONFIRMATIONS=6). There
|
||||
are 3 different caches:
|
||||
* Number of confirmations
|
||||
* Transaction output spent/unspent status
|
||||
|
@ -153,12 +136,12 @@ are 3 different caches:
|
|||
|
||||
Cache data is only populated on request, i.e., only after accessing the required data for
|
||||
the first time, the information is cached, there is not pre-caching procedure. To ignore
|
||||
cache by default, use INSIGHT_IGNORE_CACHE. Also, address related calls support `?noCache=1`
|
||||
cache by default, use BLOCKCHAIN_API_IGNORE_CACHE. Also, address related calls support `?noCache=1`
|
||||
to ignore the cache in a particular API request.
|
||||
|
||||
## API
|
||||
|
||||
By default, insight provides a REST API at `/api`, but this prefix is configurable from the var `apiPrefix` in the `config.js` file.
|
||||
By default, `bitcore-node` provides a REST API at `/api`, but this prefix is configurable from the var `apiPrefix` in the `config.js` file.
|
||||
|
||||
The end-points are:
|
||||
|
||||
|
@ -214,7 +197,7 @@ Sample return:
|
|||
}
|
||||
]
|
||||
```
|
||||
Please note that in case confirmations are cached (which happens by default when the number of confirmations is bigger that INSIGHT_SAFE_CONFIRMATIONS) the response will include the pair confirmationsFromCache:true, and confirmations will equal INSIGHT_SAFE_CONFIRMATIONS. See noCache and INSIGHT_IGNORE_CACHE options for details.
|
||||
Please note that in case confirmations are cached (which happens by default when the number of confirmations is bigger that BLOCKCHAIN_API_SAFE_CONFIRMATIONS) the response will include the pair confirmationsFromCache:true, and confirmations will equal BLOCKCHAIN_API_SAFE_CONFIRMATIONS. See noCache and BLOCKCHAIN_API_IGNORE_CACHE options for details.
|
||||
|
||||
|
||||
|
||||
|
@ -349,7 +332,7 @@ Where "xxx" can be:
|
|||
## Web Socket API
|
||||
The web socket API is served using [socket.io](http://socket.io).
|
||||
|
||||
The following are the events published by insight:
|
||||
The following are the events published:
|
||||
|
||||
'tx': new transaction received from network. This event is published in the 'inv' room. Data will be a app/models/Transaction object.
|
||||
Sample output:
|
||||
|
@ -392,18 +375,18 @@ Sample output:
|
|||
|
||||
### Example Usage
|
||||
|
||||
The following html page connects to the socket.io insight API and listens for new transactions.
|
||||
The following html page connects to the socket.io API and listens for new transactions.
|
||||
|
||||
html
|
||||
```
|
||||
<html>
|
||||
<body>
|
||||
<script src="http://<insight-server>:<port>/socket.io/socket.io.js"></script>
|
||||
<script src="http://<bitcore-node-server>:<port>/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
eventToListenTo = 'tx'
|
||||
room = 'inv'
|
||||
|
||||
var socket = io("http://<insight-server>:<port>/");
|
||||
var socket = io("http://<bitcore-node-server>:<port>/");
|
||||
socket.on('connect', function() {
|
||||
// Join the room.
|
||||
socket.emit('subscribe', room);
|
||||
|
|
|
@ -14,7 +14,7 @@ exports.render = function(req, res) {
|
|||
}
|
||||
else {
|
||||
var version = _getVersion();
|
||||
res.send('insight API v' + version);
|
||||
res.send('bitcore-node API v' + version);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ function getUserHome() {
|
|||
return process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
|
||||
}
|
||||
|
||||
var home = process.env.INSIGHT_DB || (getUserHome() + '/.insight');
|
||||
var home = process.env.BLOCKCHAIN_API_DB || (getUserHome() + '/.bitcore-node');
|
||||
|
||||
if (process.env.INSIGHT_NETWORK === 'livenet') {
|
||||
if (process.env.BLOCKCHAIN_API_NETWORK === 'livenet') {
|
||||
env = 'livenet';
|
||||
db = home;
|
||||
port = '3000';
|
||||
|
@ -34,7 +34,7 @@ if (process.env.INSIGHT_NETWORK === 'livenet') {
|
|||
b_port = '18332';
|
||||
p2p_port = '18333';
|
||||
}
|
||||
port = parseInt(process.env.INSIGHT_PORT) || port;
|
||||
port = parseInt(process.env.BLOCKCHAIN_API_PORT) || port;
|
||||
|
||||
|
||||
switch (process.env.NODE_ENV) {
|
||||
|
@ -49,7 +49,7 @@ switch (process.env.NODE_ENV) {
|
|||
break;
|
||||
}
|
||||
|
||||
var network = process.env.INSIGHT_NETWORK || 'testnet';
|
||||
var network = process.env.BLOCKCHAIN_API_NETWORK || 'testnet';
|
||||
|
||||
var dataDir = process.env.BITCOIND_DATADIR;
|
||||
var isWin = /^win/.test(process.platform);
|
||||
|
@ -62,8 +62,8 @@ if (!dataDir) {
|
|||
}
|
||||
dataDir += network === 'testnet' ? 'testnet3' : '';
|
||||
|
||||
var safeConfirmations = process.env.INSIGHT_SAFE_CONFIRMATIONS || 6;
|
||||
var ignoreCache = process.env.INSIGHT_IGNORE_CACHE || 0;
|
||||
var safeConfirmations = process.env.BLOCKCHAIN_API_SAFE_CONFIRMATIONS || 6;
|
||||
var ignoreCache = process.env.BLOCKCHAIN_API_IGNORE_CACHE || 0;
|
||||
|
||||
|
||||
var bitcoindConf = {
|
||||
|
@ -91,8 +91,7 @@ module.exports = {
|
|||
enableHTTPS: enableHTTPS,
|
||||
version: version,
|
||||
root: rootPath,
|
||||
publicPath: process.env.INSIGHT_PUBLIC_PATH || false,
|
||||
appName: 'Insight ' + env,
|
||||
publicPath: process.env.BLOCKCHAIN_API_PUBLIC_PATH || false,
|
||||
apiPrefix: '/api',
|
||||
port: port,
|
||||
leveldb: db,
|
||||
|
@ -103,7 +102,7 @@ module.exports = {
|
|||
poolMatchFile: rootPath + '/etc/minersPoolStrings.json',
|
||||
|
||||
keys: {
|
||||
segmentio: process.env.INSIGHT_SEGMENTIO_KEY
|
||||
segmentio: process.env.BLOCKCHAIN_API_SEGMENTIO_KEY
|
||||
},
|
||||
safeConfirmations: safeConfirmations, // PLEASE NOTE THAT *FULL RESYNC* IS NEEDED TO CHANGE safeConfirmations
|
||||
ignoreCache: ignoreCache,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
20
index.js
20
index.js
|
@ -20,20 +20,14 @@ program
|
|||
|
||||
// text title
|
||||
console.log(
|
||||
'\n\
|
||||
____ _ __ __ ___ _ \n\
|
||||
/ _/___ _____(_)___ _/ /_ / /_ / | ____ (_)\n\
|
||||
/ // __ \\/ ___/ / __ `/ __ \\/ __/ / /\| \| / __ \\/ / \n\
|
||||
_/ // / / (__ ) / /_/ / / / / /_ / ___ |/ /_/ / / \n\
|
||||
/___/_/ /_/____/_/\\__, /_/ /_/\\__/ /_/ |_/ .___/_/ \n\
|
||||
/____/ /_/ \n\
|
||||
'bitcore-node
|
||||
\n\t\t\t\t\t\tv%s\n', config.version);
|
||||
program.on('--help', function() {
|
||||
logger.info('\n# Configuration:\n\
|
||||
\tINSIGHT_NETWORK (Network): %s\n\
|
||||
\tINSIGHT_DB (Database Path): %s\n\
|
||||
\tINSIGHT_SAFE_CONFIRMATIONS (Safe Confirmations): %s\n\
|
||||
\tINSIGHT_IGNORE_CACHE (Ignore Cache): %s\n\
|
||||
\tBLOCKCHAIN_API_NETWORK (Network): %s\n\
|
||||
\tBLOCKCHAIN_API_DB (Database Path): %s\n\
|
||||
\tBLOCKCHAIN_API_SAFE_CONFIRMATIONS (Safe Confirmations): %s\n\
|
||||
\tBLOCKCHAIN_API_IGNORE_CACHE (Ignore Cache): %s\n\
|
||||
# Bicoind Connection configuration:\n\
|
||||
\tRPC Username: %s\t\tBITCOIND_USER\n\
|
||||
\tRPC Password: %s\tBITCOIND_PASS\n\
|
||||
|
@ -44,7 +38,7 @@ program.on('--help', function() {
|
|||
\tBITCOIND_DATADIR: %s\n\
|
||||
\t%s\n\
|
||||
\nChange setting by assigning the enviroment variables above. Example:\n\
|
||||
$ INSIGHT_NETWORK="testnet" BITCOIND_HOST="123.123.123.123" ./insight.js\
|
||||
$ BLOCKCHAIN_API_NETWORK="testnet" BITCOIND_HOST="123.123.123.123" ./index.js\
|
||||
\n\n',
|
||||
config.network, config.leveldb, config.safeConfirmations, config.ignoreCache ? 'yes' : 'no',
|
||||
config.bitcoind.user,
|
||||
|
@ -133,7 +127,7 @@ require('./config/routes')(expressApp);
|
|||
|
||||
//Start the app by listening on <port>
|
||||
server.listen(config.port, function() {
|
||||
logger.info('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
||||
logger.info('bitcoin-node API listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
||||
});
|
||||
|
||||
//expose app
|
||||
|
|
|
@ -17,13 +17,9 @@ var info = logger.info;
|
|||
var error = logger.error;
|
||||
var PERCENTAGE_TO_START_FROM_RPC = 0.96;
|
||||
|
||||
// TODO TODO TODO
|
||||
//var PERCENTAGE_TO_START_FROM_RPC = 0.98;
|
||||
var BAD_GEN_ERROR = 'Bad genesis block. Network mismatch between bitcore-node and bitcoind? bitcore-node is configured for:';
|
||||
var BAD_GEN_ERROR_DB = 'Bad genesis block. Network mismatch between bitcore-node and levelDB? bitcore-node is configured for:';
|
||||
|
||||
// var Deserialize = require('bitcore/Deserialize');
|
||||
var BAD_GEN_ERROR = 'Bad genesis block. Network mismatch between Insight and bitcoind? Insight is configured for:';
|
||||
|
||||
var BAD_GEN_ERROR_DB = 'Bad genesis block. Network mismatch between Insight and levelDB? Insight is configured for:';
|
||||
function HistoricSync(opts) {
|
||||
opts = opts || {};
|
||||
this.shouldBroadcast = opts.shouldBroadcastSync;
|
||||
|
@ -239,7 +235,7 @@ HistoricSync.prototype.updateStartBlock = function(opts, next) {
|
|||
else {
|
||||
oldtip = tip;
|
||||
if (!tip)
|
||||
throw new Error('Previous blockchain tip was not found on bitcoind. Please reset Insight DB. Tip was:'+tip)
|
||||
throw new Error('Previous blockchain tip was not found on bitcoind. Please reset bitcore-node DB. Tip was:'+tip)
|
||||
tip = blockInfo.previousblockhash;
|
||||
info('Previous TIP is now orphan. Back to:' + tip);
|
||||
ret = true;
|
||||
|
@ -352,7 +348,7 @@ HistoricSync.prototype.setupSyncStatus = function() {
|
|||
HistoricSync.prototype.checkDBVersion = function(cb) {
|
||||
this.sync.txDb.checkVersion02(function(isOk){
|
||||
if (!isOk) {
|
||||
console.log('\n#############################\n\n ## Insight API DB is older that v0.2. Please resync using:\n $ util/sync.js -D\n More information at Insight API\'s Readme.md');
|
||||
console.log('\n#############################\n\n ## bitcore-node API DB is older that v0.2. Please resync using:\n $ util/sync.js -D\n More information at bitcore-node API\'s Readme.md');
|
||||
process.exit(1);
|
||||
}
|
||||
// Add more test here in future changes.
|
||||
|
|
10
package.json
10
package.json
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name": "bitcored",
|
||||
"description": "An open-source bitcoin blockchain API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the bitcoin network and build your own services with it.",
|
||||
"name": "bitcore-node",
|
||||
"description": "Full node with extended capabilities using bitcore and Bitcoin Core",
|
||||
"version": "0.0.1",
|
||||
"author": "BitPay <dev@bitpay.com>",
|
||||
"repository": "git://github.com/bitpay/bitcored.git",
|
||||
"repository": "git://github.com/bitpay/bitcore-node.git",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Matias Alejo Garcia",
|
||||
|
@ -31,9 +31,9 @@
|
|||
}
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/bitpay/bitcored/issues"
|
||||
"url": "https://github.com/bitpay/bitcore-node/issues"
|
||||
},
|
||||
"homepage": "https://github.com/bitpay/bitcored",
|
||||
"homepage": "https://github.com/bitpay/bitcore-node",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
var levelup = require('levelup');
|
||||
var bitcore = require('bitcore');
|
||||
var _ = require('lodash');
|
||||
|
||||
var home = process.env['HOME'];
|
||||
var db = new levelup(process.argv[2] || (home + '/.insight/testnet/emailstore'));
|
||||
var newDb = new levelup(process.argv[3] || (home + '/.insight/testnet/emailstore.migrated'));
|
||||
|
||||
var transformStoredValue = function(key) {
|
||||
var oldKey = key.substr('credentials-store-'.length);
|
||||
return 'emailstore-' + bitcore.util.twoSha256(oldKey).toString('hex');
|
||||
};
|
||||
|
||||
var transformPending = function(key) {
|
||||
var oldKey = key.substr('validation-code-'.length);
|
||||
return 'pending-' + oldKey;
|
||||
};
|
||||
|
||||
var transformPassphrase = function(key) {
|
||||
var oldKey = key.substr('map-email-'.length);
|
||||
return 'email-to-passphrase-' + bitcore.util.twoSha256(oldKey).toString('hex');
|
||||
};
|
||||
|
||||
var transformValidated = function(key) {
|
||||
var oldKey = key.substr('validated-email-'.length);
|
||||
return 'validated-' + bitcore.util.twoSha256(oldKey).toString('hex');
|
||||
};
|
||||
|
||||
var checks = {
|
||||
'credentials-store-': transformStoredValue,
|
||||
'validation-code-': transformPending,
|
||||
'map-email-': transformPassphrase,
|
||||
'validated-email': transformValidated
|
||||
};
|
||||
|
||||
db.createReadStream()
|
||||
.on('data', function(data) {
|
||||
console.log('- Analizing key: ' + data.key);
|
||||
_.each(checks, function(checkFunction, checkName) {
|
||||
|
||||
if (data.key.indexOf(checkName) === 0) {
|
||||
db.get('migration-' + data.key, function(err, value) {
|
||||
if ((err && err.notFound) || data.value !== value) {
|
||||
|
||||
var newKey = checkFunction(data.key);
|
||||
if (data.value !== value) {
|
||||
console.log(' - ' + newKey + ' outdated, migrating...')
|
||||
} else {
|
||||
console.log(' - ' + data.key + ' not migrated, migrating to ' + newKey);
|
||||
}
|
||||
|
||||
newDb.put(newKey, data.value, function(err) {
|
||||
if (err) {
|
||||
console.log(' - Error migrating ' + data.key + '!', err);
|
||||
} else {
|
||||
db.put('migration-' + data.key, data.value, function() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue