Drop old http
This commit is contained in:
parent
8c3a9e95cc
commit
5fc6780225
2
.gitignore
vendored
2
.gitignore
vendored
@ -41,3 +41,5 @@ db/testnet/blocks
|
|||||||
|
|
||||||
README.html
|
README.html
|
||||||
public
|
public
|
||||||
|
|
||||||
|
blocks
|
||||||
|
|||||||
@ -4,6 +4,9 @@ BitcoreNode:
|
|||||||
host: localhost
|
host: localhost
|
||||||
port: 8333
|
port: 8333
|
||||||
Reporter: none # none, simple, matrix
|
Reporter: none # none, simple, matrix
|
||||||
|
BitcoreHTTP:
|
||||||
|
host: localhost
|
||||||
|
port: 8080
|
||||||
LevelUp: ./db
|
LevelUp: ./db
|
||||||
RPC:
|
RPC:
|
||||||
user: user
|
user: user
|
||||||
|
|||||||
@ -1,206 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var _ = require('lodash');
|
|
||||||
var Address = require('../models/Address');
|
|
||||||
var common = require('./common');
|
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
var tDb = require('../../lib/TransactionDb').default();
|
|
||||||
|
|
||||||
var getAddr = function(req, res, next) {
|
|
||||||
var a;
|
|
||||||
try {
|
|
||||||
var addr = req.param('addr');
|
|
||||||
a = new Address(addr);
|
|
||||||
} catch (e) {
|
|
||||||
common.handleErrors({
|
|
||||||
message: 'Invalid address:' + e.message,
|
|
||||||
code: 1
|
|
||||||
}, res, next);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
|
|
||||||
var getAddrs = function(req, res, next) {
|
|
||||||
var as = [];
|
|
||||||
try {
|
|
||||||
var addrStrs = req.param('addrs');
|
|
||||||
var s = addrStrs.split(',');
|
|
||||||
if (s.length === 0) return as;
|
|
||||||
for (var i = 0; i < s.length; i++) {
|
|
||||||
var a = new Address(s[i]);
|
|
||||||
as.push(a);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
common.handleErrors({
|
|
||||||
message: 'Invalid address:' + e.message,
|
|
||||||
code: 1
|
|
||||||
}, res, next);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return as;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.show = function(req, res, next) {
|
|
||||||
var a = getAddr(req, res, next);
|
|
||||||
|
|
||||||
if (a) {
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) {
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
} else {
|
|
||||||
return res.jsonp(a.getObj());
|
|
||||||
}
|
|
||||||
}, {txLimit: req.query.noTxList?0:-1, ignoreCache: req.param('noCache')});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.utxo = function(req, res, next) {
|
|
||||||
var a = getAddr(req, res, next);
|
|
||||||
if (a) {
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err)
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
else {
|
|
||||||
return res.jsonp(a.unspent);
|
|
||||||
}
|
|
||||||
}, {onlyUnspent:1, ignoreCache: req.param('noCache')});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.multiutxo = function(req, res, next) {
|
|
||||||
var as = getAddrs(req, res, next);
|
|
||||||
if (as) {
|
|
||||||
var utxos = [];
|
|
||||||
async.each(as, function(a, callback) {
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) callback(err);
|
|
||||||
utxos = utxos.concat(a.unspent);
|
|
||||||
callback();
|
|
||||||
}, {onlyUnspent:1, ignoreCache: req.param('noCache')});
|
|
||||||
}, function(err) { // finished callback
|
|
||||||
if (err) return common.handleErrors(err, res);
|
|
||||||
res.jsonp(utxos);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.multitxs = function(req, res, next) {
|
|
||||||
|
|
||||||
function processTxs(txs, from, to, cb) {
|
|
||||||
txs = _.uniq(_.flatten(txs), 'txid');
|
|
||||||
var nbTxs = txs.length;
|
|
||||||
var paginated = !_.isUndefined(from) || !_.isUndefined(to);
|
|
||||||
|
|
||||||
if (paginated) {
|
|
||||||
txs.sort(function(a, b) {
|
|
||||||
return (b.ts || b.ts) - (a.ts || a.ts);
|
|
||||||
});
|
|
||||||
var start = Math.max(from || 0, 0);
|
|
||||||
var end = Math.min(to || txs.length, txs.length);
|
|
||||||
txs = txs.slice(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
var txIndex = {};
|
|
||||||
_.each(txs, function (tx) { txIndex[tx.txid] = tx; });
|
|
||||||
|
|
||||||
async.each(txs, function (tx, callback) {
|
|
||||||
tDb.fromIdWithInfo(tx.txid, function(err, tx) {
|
|
||||||
if (err) console.log(err);
|
|
||||||
if (tx && tx.info) {
|
|
||||||
txIndex[tx.txid].info = tx.info;
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}, function (err) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
var transactions = _.pluck(txs, 'info');
|
|
||||||
if (paginated) {
|
|
||||||
transactions = {
|
|
||||||
totalItems: nbTxs,
|
|
||||||
from: +from,
|
|
||||||
to: +to,
|
|
||||||
items: transactions,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return cb(null, transactions);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var from = req.param('from');
|
|
||||||
var to = req.param('to');
|
|
||||||
|
|
||||||
var as = getAddrs(req, res, next);
|
|
||||||
if (as) {
|
|
||||||
var txs = [];
|
|
||||||
async.eachLimit(as, 10, function(a, callback) {
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) callback(err);
|
|
||||||
txs.push(a.transactions);
|
|
||||||
callback();
|
|
||||||
}, {ignoreCache: req.param('noCache'), includeTxInfo: true});
|
|
||||||
}, function(err) { // finished callback
|
|
||||||
if (err) return common.handleErrors(err, res);
|
|
||||||
processTxs(txs, from, to, function (err, transactions) {
|
|
||||||
if (err) return common.handleErrors(err, res);
|
|
||||||
res.jsonp(transactions);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.balance = function(req, res, next) {
|
|
||||||
var a = getAddr(req, res, next);
|
|
||||||
if (a)
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) {
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
} else {
|
|
||||||
return res.jsonp(a.balanceSat);
|
|
||||||
}
|
|
||||||
}, {ignoreCache: req.param('noCache')});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.totalReceived = function(req, res, next) {
|
|
||||||
var a = getAddr(req, res, next);
|
|
||||||
if (a)
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) {
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
} else {
|
|
||||||
return res.jsonp(a.totalReceivedSat);
|
|
||||||
}
|
|
||||||
}, {ignoreCache: req.param('noCache')});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.totalSent = function(req, res, next) {
|
|
||||||
var a = getAddr(req, res, next);
|
|
||||||
if (a)
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) {
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
} else {
|
|
||||||
return res.jsonp(a.totalSentSat);
|
|
||||||
}
|
|
||||||
}, {ignoreCache: req.param('noCache')});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.unconfirmedBalance = function(req, res, next) {
|
|
||||||
var a = getAddr(req, res, next);
|
|
||||||
if (a)
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err) {
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
} else {
|
|
||||||
return res.jsonp(a.unconfirmedBalanceSat);
|
|
||||||
}
|
|
||||||
}, {ignoreCache: req.param('noCache')});
|
|
||||||
};
|
|
||||||
@ -1,176 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
var common = require('./common'),
|
|
||||||
async = require('async'),
|
|
||||||
BlockDb = require('../../lib/BlockDb'),
|
|
||||||
TransactionDb = require('../../lib/TransactionDb');
|
|
||||||
|
|
||||||
var bdb = new BlockDb();
|
|
||||||
var tdb = new TransactionDb();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find block by hash ...
|
|
||||||
*/
|
|
||||||
exports.block = function(req, res, next, hash) {
|
|
||||||
bdb.fromHashWithInfo(hash, function(err, block) {
|
|
||||||
if (err || !block)
|
|
||||||
return common.handleErrors(err, res, next);
|
|
||||||
else {
|
|
||||||
tdb.getPoolInfo(block.info.tx[0], function(info) {
|
|
||||||
block.info.poolInfo = info;
|
|
||||||
req.block = block.info;
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show block
|
|
||||||
*/
|
|
||||||
exports.show = function(req, res) {
|
|
||||||
if (req.block) {
|
|
||||||
res.jsonp(req.block);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show block by Height
|
|
||||||
*/
|
|
||||||
exports.blockindex = function(req, res, next, height) {
|
|
||||||
bdb.blockIndex(height, function(err, hashStr) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
res.status(400).send('Bad Request'); // TODO
|
|
||||||
} else {
|
|
||||||
res.jsonp(hashStr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var getBlock = function(blockhash, cb) {
|
|
||||||
bdb.fromHashWithInfo(blockhash, function(err, block) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
if (!block.info) {
|
|
||||||
console.log('Could not get %s from RPC. Orphan? Error?', blockhash); //TODO
|
|
||||||
// Probably orphan
|
|
||||||
block.info = {
|
|
||||||
hash: blockhash,
|
|
||||||
isOrphan: 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
tdb.getPoolInfo(block.info.tx[0], function(info) {
|
|
||||||
block.info.poolInfo = info;
|
|
||||||
return cb(err, block.info);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of blocks by date
|
|
||||||
*/
|
|
||||||
|
|
||||||
var DFLT_LIMIT=200;
|
|
||||||
// in testnet, this number is much bigger, we dont support
|
|
||||||
// exploring blocks by date.
|
|
||||||
|
|
||||||
exports.list = function(req, res) {
|
|
||||||
var isToday = false;
|
|
||||||
|
|
||||||
//helper to convert timestamps to yyyy-mm-dd format
|
|
||||||
var formatTimestamp = function(date) {
|
|
||||||
var yyyy = date.getUTCFullYear().toString();
|
|
||||||
var mm = (date.getUTCMonth() + 1).toString(); // getMonth() is zero-based
|
|
||||||
var dd = date.getUTCDate().toString();
|
|
||||||
|
|
||||||
return yyyy + '-' + (mm[1] ? mm : '0' + mm[0]) + '-' + (dd[1] ? dd : '0' + dd[0]); //padding
|
|
||||||
};
|
|
||||||
|
|
||||||
var dateStr;
|
|
||||||
var todayStr = formatTimestamp(new Date());
|
|
||||||
|
|
||||||
if (req.query.blockDate) {
|
|
||||||
// TODO: Validate format yyyy-mm-dd
|
|
||||||
dateStr = req.query.blockDate;
|
|
||||||
isToday = dateStr === todayStr;
|
|
||||||
} else {
|
|
||||||
dateStr = todayStr;
|
|
||||||
isToday = true;
|
|
||||||
}
|
|
||||||
var gte = Math.round((new Date(dateStr)).getTime() / 1000);
|
|
||||||
|
|
||||||
//pagination
|
|
||||||
var lte = parseInt(req.query.startTimestamp) || gte + 86400;
|
|
||||||
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
|
|
||||||
var next = lte ? formatTimestamp(new Date(lte * 1000)) :null;
|
|
||||||
var limit = parseInt(req.query.limit || DFLT_LIMIT) + 1;
|
|
||||||
var more;
|
|
||||||
|
|
||||||
bdb.getBlocksByDate(gte, lte, limit, function(err, blockList) {
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
res.status(500).send(err);
|
|
||||||
} else {
|
|
||||||
var l = blockList.length;
|
|
||||||
|
|
||||||
if (l===limit) {
|
|
||||||
more = true;
|
|
||||||
blockList.pop;
|
|
||||||
}
|
|
||||||
|
|
||||||
var moreTs=lte;
|
|
||||||
async.mapSeries(blockList,
|
|
||||||
function(b, cb) {
|
|
||||||
getBlock(b.hash, function(err, info) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
if (b.ts < moreTs) moreTs = b.ts;
|
|
||||||
return cb(err, {
|
|
||||||
height: info.height,
|
|
||||||
size: info.size,
|
|
||||||
hash: b.hash,
|
|
||||||
time: b.ts || info.time,
|
|
||||||
txlength: info.tx.length,
|
|
||||||
poolInfo: info.poolInfo
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, function(err, allblocks) {
|
|
||||||
|
|
||||||
// sort blocks by height
|
|
||||||
allblocks.sort(
|
|
||||||
function compare(a,b) {
|
|
||||||
if (a.height < b.height) return 1;
|
|
||||||
if (a.height > b.height) return -1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
res.jsonp({
|
|
||||||
blocks: allblocks,
|
|
||||||
length: allblocks.length,
|
|
||||||
pagination: {
|
|
||||||
next: next,
|
|
||||||
prev: prev,
|
|
||||||
currentTs: lte - 1,
|
|
||||||
current: dateStr,
|
|
||||||
isToday: isToday,
|
|
||||||
more: more,
|
|
||||||
moreTs: moreTs,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
exports.handleErrors = function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
if (err.code) {
|
|
||||||
res.status(400).send(err.message + '. Code:' + err.code);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.status(503).send(err.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.status(404).send('Not found');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var config = require('../../config/config');
|
|
||||||
|
|
||||||
// Set the initial vars
|
|
||||||
var timestamp = +new Date(),
|
|
||||||
delay = config.currencyRefresh * 60000,
|
|
||||||
bitstampRate = 0;
|
|
||||||
|
|
||||||
exports.index = function(req, res) {
|
|
||||||
|
|
||||||
var _xhr = function() {
|
|
||||||
if (typeof XMLHttpRequest !== 'undefined' && XMLHttpRequest !== null) {
|
|
||||||
return new XMLHttpRequest();
|
|
||||||
} else if (typeof require !== 'undefined' && require !== null) {
|
|
||||||
var XMLhttprequest = require('xmlhttprequest').XMLHttpRequest;
|
|
||||||
return new XMLhttprequest();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var _request = function(url, cb) {
|
|
||||||
var request;
|
|
||||||
request = _xhr();
|
|
||||||
request.open('GET', url, true);
|
|
||||||
request.onreadystatechange = function() {
|
|
||||||
if (request.readyState === 4) {
|
|
||||||
if (request.status === 200) {
|
|
||||||
return cb(false, request.responseText);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cb(true, {
|
|
||||||
status: request.status,
|
|
||||||
message: 'Request error'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return request.send(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Init
|
|
||||||
var currentTime = +new Date();
|
|
||||||
if (bitstampRate === 0 || currentTime >= (timestamp + delay)) {
|
|
||||||
timestamp = currentTime;
|
|
||||||
|
|
||||||
_request('https://www.bitstamp.net/api/ticker/', function(err, data) {
|
|
||||||
if (!err) bitstampRate = parseFloat(JSON.parse(data).last);
|
|
||||||
|
|
||||||
res.jsonp({
|
|
||||||
status: 200,
|
|
||||||
data: { bitstamp: bitstampRate }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.jsonp({
|
|
||||||
status: 200,
|
|
||||||
data: { bitstamp: bitstampRate }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var config = require('../../config/config');
|
|
||||||
|
|
||||||
var _getVersion = function() {
|
|
||||||
var pjson = require('../../package.json');
|
|
||||||
return pjson.version;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.render = function(req, res) {
|
|
||||||
|
|
||||||
if (config.publicPath) {
|
|
||||||
return res.sendfile(config.publicPath + '/index.html');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var version = _getVersion();
|
|
||||||
res.send('bitcore-node API v' + version);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.version = function(req, res) {
|
|
||||||
var version = _getVersion();
|
|
||||||
res.json({
|
|
||||||
version: version
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var common = require('./common');
|
|
||||||
var Rpc = require('../../lib/Rpc');
|
|
||||||
|
|
||||||
|
|
||||||
exports.verify = function(req, res) {
|
|
||||||
var address = req.param('address'),
|
|
||||||
signature = req.param('signature'),
|
|
||||||
message = req.param('message');
|
|
||||||
|
|
||||||
if(typeof(address) == 'undefined'
|
|
||||||
|| typeof(signature) == 'undefined'
|
|
||||||
|| typeof(message) == 'undefined') {
|
|
||||||
return common.handleErrors({
|
|
||||||
message: 'Missing parameters (expected "address", "signature" and "message")',
|
|
||||||
code: 1
|
|
||||||
}, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rpc.verifyMessage(address, signature, message, function(err, result) {
|
|
||||||
if (err) {
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
}
|
|
||||||
res.json({'result' : result});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var Status = require('../models/Status'),
|
|
||||||
common = require('./common');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status
|
|
||||||
*/
|
|
||||||
exports.show = function(req, res) {
|
|
||||||
|
|
||||||
if (! req.query.q) {
|
|
||||||
res.status(400).send('Bad Request');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var option = req.query.q;
|
|
||||||
var statusObject = new Status();
|
|
||||||
|
|
||||||
var returnJsonp = function (err) {
|
|
||||||
if (err || ! statusObject)
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
else {
|
|
||||||
res.jsonp(statusObject);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
switch(option) {
|
|
||||||
case 'getInfo':
|
|
||||||
statusObject.getInfo(returnJsonp);
|
|
||||||
break;
|
|
||||||
case 'getDifficulty':
|
|
||||||
statusObject.getDifficulty(returnJsonp);
|
|
||||||
break;
|
|
||||||
case 'getTxOutSetInfo':
|
|
||||||
statusObject.getTxOutSetInfo(returnJsonp);
|
|
||||||
break;
|
|
||||||
case 'getLastBlockHash':
|
|
||||||
statusObject.getLastBlockHash(returnJsonp);
|
|
||||||
break;
|
|
||||||
case 'getBestBlockHash':
|
|
||||||
statusObject.getBestBlockHash(returnJsonp);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res.status(400).send('Bad Request');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.sync = function(req, res) {
|
|
||||||
if (req.historicSync)
|
|
||||||
res.jsonp(req.historicSync.info());
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.peer = function(req, res) {
|
|
||||||
if (req.peerSync) {
|
|
||||||
var info = req.peerSync.info();
|
|
||||||
res.jsonp(info);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,166 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
var Address = require('../models/Address');
|
|
||||||
var async = require('async');
|
|
||||||
var common = require('./common');
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Rpc = require('../../lib/Rpc');
|
|
||||||
|
|
||||||
var tDb = require('../../lib/TransactionDb').default();
|
|
||||||
var bdb = require('../../lib/BlockDb').default();
|
|
||||||
|
|
||||||
exports.send = function(req, res) {
|
|
||||||
Rpc.sendRawTransaction(req.body.rawtx, function(err, txid) {
|
|
||||||
if (err) {
|
|
||||||
var message;
|
|
||||||
if(err.code == -25) {
|
|
||||||
message = util.format(
|
|
||||||
'Generic error %s (code %s)',
|
|
||||||
err.message, err.code);
|
|
||||||
} else if(err.code == -26) {
|
|
||||||
message = util.format(
|
|
||||||
'Transaction rejected by network (code %s). Reason: %s',
|
|
||||||
err.code, err.message);
|
|
||||||
} else {
|
|
||||||
message = util.format('%s (code %s)', err.message, err.code);
|
|
||||||
}
|
|
||||||
return res.status(400).send(message);
|
|
||||||
}
|
|
||||||
res.json({'txid' : txid});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find transaction by hash ...
|
|
||||||
*/
|
|
||||||
exports.transaction = function(req, res, next, txid) {
|
|
||||||
|
|
||||||
tDb.fromIdWithInfo(txid, function(err, tx) {
|
|
||||||
if (err || ! tx)
|
|
||||||
return common.handleErrors(err, res);
|
|
||||||
else {
|
|
||||||
req.transaction = tx.info;
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show transaction
|
|
||||||
*/
|
|
||||||
exports.show = function(req, res) {
|
|
||||||
|
|
||||||
if (req.transaction) {
|
|
||||||
res.jsonp(req.transaction);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var getTransaction = function(txid, cb) {
|
|
||||||
|
|
||||||
tDb.fromIdWithInfo(txid, function(err, tx) {
|
|
||||||
if (err) console.log(err);
|
|
||||||
|
|
||||||
if (!tx || !tx.info) {
|
|
||||||
console.log('[transactions.js.48]:: TXid %s not found in RPC. CHECK THIS.', txid);
|
|
||||||
return ({ txid: txid });
|
|
||||||
}
|
|
||||||
|
|
||||||
return cb(null, tx.info);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of transaction
|
|
||||||
*/
|
|
||||||
exports.list = function(req, res, next) {
|
|
||||||
var bId = req.query.block;
|
|
||||||
var addrStr = req.query.address;
|
|
||||||
var page = req.query.pageNum;
|
|
||||||
var pageLength = 10;
|
|
||||||
var pagesTotal = 1;
|
|
||||||
var txLength;
|
|
||||||
var txs;
|
|
||||||
|
|
||||||
if (bId) {
|
|
||||||
bdb.fromHashWithInfo(bId, function(err, block) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
return res.status(500).send('Internal Server Error');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! block) {
|
|
||||||
return res.status(404).send('Not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
txLength = block.info.tx.length;
|
|
||||||
|
|
||||||
if (page) {
|
|
||||||
var spliceInit = page * pageLength;
|
|
||||||
txs = block.info.tx.splice(spliceInit, pageLength);
|
|
||||||
pagesTotal = Math.ceil(txLength / pageLength);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
txs = block.info.tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
async.mapSeries(txs, getTransaction, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
res.status(404).send('TX not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
res.jsonp({
|
|
||||||
pagesTotal: pagesTotal,
|
|
||||||
txs: results
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (addrStr) {
|
|
||||||
var a = new Address(addrStr);
|
|
||||||
|
|
||||||
a.update(function(err) {
|
|
||||||
if (err && !a.totalReceivedSat) {
|
|
||||||
console.log(err);
|
|
||||||
res.status(404).send('Invalid address');
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
txLength = a.transactions.length;
|
|
||||||
|
|
||||||
if (page) {
|
|
||||||
var spliceInit = page * pageLength;
|
|
||||||
txs = a.transactions.splice(spliceInit, pageLength);
|
|
||||||
pagesTotal = Math.ceil(txLength / pageLength);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
txs = a.transactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
async.mapSeries(txs, getTransaction, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
res.status(404).send('TX not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
res.jsonp({
|
|
||||||
pagesTotal: pagesTotal,
|
|
||||||
txs: results
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.jsonp({
|
|
||||||
txs: []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
var express = require('express');
|
|
||||||
var config = require('./config');
|
|
||||||
var path = require('path');
|
|
||||||
var logger = require('../lib/logger').logger;
|
|
||||||
|
|
||||||
module.exports = function(app, historicSync, peerSync) {
|
|
||||||
|
|
||||||
|
|
||||||
//custom middleware
|
|
||||||
var setHistoric = function(req, res, next) {
|
|
||||||
req.historicSync = historicSync;
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
|
|
||||||
var setPeer = function(req, res, next) {
|
|
||||||
req.peerSync = peerSync;
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
|
|
||||||
app.set('showStackError', true);
|
|
||||||
app.set('json spaces', 0);
|
|
||||||
|
|
||||||
app.enable('jsonp callback');
|
|
||||||
app.use(config.apiPrefix + '/sync', setHistoric);
|
|
||||||
app.use(config.apiPrefix + '/peer', setPeer);
|
|
||||||
app.use(express.logger('dev'));
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.urlencoded());
|
|
||||||
app.use(express.methodOverride());
|
|
||||||
app.use(express.compress());
|
|
||||||
|
|
||||||
if (config.enableEmailstore) {
|
|
||||||
var allowCopayCrossDomain = function(req, res, next) {
|
|
||||||
if ('OPTIONS' == req.method) {
|
|
||||||
res.send(200);
|
|
||||||
res.end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
app.use(allowCopayCrossDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.publicPath) {
|
|
||||||
var staticPath = path.normalize(config.rootPath + '/../' + config.publicPath);
|
|
||||||
//IMPORTANT: for html5mode, this line must to be before app.router
|
|
||||||
app.use(express.static(staticPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
|
||||||
app.locals.config = config;
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
//routes should be at the last
|
|
||||||
app.use(app.router);
|
|
||||||
|
|
||||||
//Assume 404 since no middleware responded
|
|
||||||
app.use(function(req, res) {
|
|
||||||
res.status(404).jsonp({
|
|
||||||
status: 404,
|
|
||||||
url: req.originalUrl,
|
|
||||||
error: 'Not found'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var logger = require('../lib/logger').logger;
|
|
||||||
|
|
||||||
module.exports = function(app) {
|
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type,Authorization');
|
|
||||||
res.setHeader('Access-Control-Expose-Headers', 'X-Email-Needs-Validation,X-Quota-Per-Item,X-Quota-Items-Limit,X-RateLimit-Limit,X-RateLimit-Remaining');
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -1,211 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
|
||||||
var async = require('async');
|
|
||||||
var bitcore = require('bitcore');
|
|
||||||
var BitcoreAddress = bitcore.Address;
|
|
||||||
var BitcoreTransaction = bitcore.Transaction;
|
|
||||||
var BitcoreUtil = bitcore.util;
|
|
||||||
var Parser = bitcore.BinaryParser;
|
|
||||||
var Buffer = bitcore.Buffer;
|
|
||||||
var TransactionDb = imports.TransactionDb || require('../../lib/TransactionDb').default();
|
|
||||||
var BlockDb = imports.BlockDb || require('../../lib/BlockDb').default();
|
|
||||||
var config = require('../../config/config');
|
|
||||||
var CONCURRENCY = 5;
|
|
||||||
|
|
||||||
function Address(addrStr) {
|
|
||||||
this.balanceSat = 0;
|
|
||||||
this.totalReceivedSat = 0;
|
|
||||||
this.totalSentSat = 0;
|
|
||||||
|
|
||||||
this.unconfirmedBalanceSat = 0;
|
|
||||||
|
|
||||||
this.txApperances = 0;
|
|
||||||
this.unconfirmedTxApperances= 0;
|
|
||||||
this.seen = {};
|
|
||||||
|
|
||||||
// TODO store only txids? +index? +all?
|
|
||||||
this.transactions = [];
|
|
||||||
this.unspent = [];
|
|
||||||
|
|
||||||
var a = new BitcoreAddress(addrStr);
|
|
||||||
a.validate();
|
|
||||||
this.addrStr = addrStr;
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'totalSent', {
|
|
||||||
get: function() {
|
|
||||||
return parseFloat(this.totalSentSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
},
|
|
||||||
set: function(i) {
|
|
||||||
this.totalSentSat = i * BitcoreUtil.COIN;
|
|
||||||
},
|
|
||||||
enumerable: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'balance', {
|
|
||||||
get: function() {
|
|
||||||
return parseFloat(this.balanceSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
},
|
|
||||||
set: function(i) {
|
|
||||||
this.balance = i * BitcoreUtil.COIN;
|
|
||||||
},
|
|
||||||
enumerable: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'totalReceived', {
|
|
||||||
get: function() {
|
|
||||||
return parseFloat(this.totalReceivedSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
},
|
|
||||||
set: function(i) {
|
|
||||||
this.totalReceived = i * BitcoreUtil.COIN;
|
|
||||||
},
|
|
||||||
enumerable: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Object.defineProperty(this, 'unconfirmedBalance', {
|
|
||||||
get: function() {
|
|
||||||
return parseFloat(this.unconfirmedBalanceSat) / parseFloat(BitcoreUtil.COIN);
|
|
||||||
},
|
|
||||||
set: function(i) {
|
|
||||||
this.unconfirmedBalanceSat = i * BitcoreUtil.COIN;
|
|
||||||
},
|
|
||||||
enumerable: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Address.prototype.getObj = function() {
|
|
||||||
// Normalize json address
|
|
||||||
return {
|
|
||||||
'addrStr': this.addrStr,
|
|
||||||
'balance': this.balance,
|
|
||||||
'balanceSat': this.balanceSat,
|
|
||||||
'totalReceived': this.totalReceived,
|
|
||||||
'totalReceivedSat': this.totalReceivedSat,
|
|
||||||
'totalSent': this.totalSent,
|
|
||||||
'totalSentSat': this.totalSentSat,
|
|
||||||
'unconfirmedBalance': this.unconfirmedBalance,
|
|
||||||
'unconfirmedBalanceSat': this.unconfirmedBalanceSat,
|
|
||||||
'unconfirmedTxApperances': this.unconfirmedTxApperances,
|
|
||||||
'txApperances': this.txApperances,
|
|
||||||
'transactions': this.transactions
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Address.prototype._addTxItem = function(txItem, txList, includeInfo) {
|
|
||||||
function addTx(data) {
|
|
||||||
if (!txList) return;
|
|
||||||
if (includeInfo) {
|
|
||||||
txList.push(data);
|
|
||||||
} else {
|
|
||||||
txList.push(data.txid);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var add=0, addSpend=0;
|
|
||||||
var v = txItem.value_sat;
|
|
||||||
var seen = this.seen;
|
|
||||||
|
|
||||||
// Founding tx
|
|
||||||
if (!seen[txItem.txid]) {
|
|
||||||
seen[txItem.txid] = 1;
|
|
||||||
add = 1;
|
|
||||||
|
|
||||||
addTx({ txid: txItem.txid, ts: txItem.ts });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spent tx
|
|
||||||
if (txItem.spentTxId && !seen[txItem.spentTxId] ) {
|
|
||||||
addTx({ txid: txItem.spentTxId, ts: txItem.spentTs });
|
|
||||||
seen[txItem.spentTxId]=1;
|
|
||||||
addSpend=1;
|
|
||||||
}
|
|
||||||
if (txItem.isConfirmed) {
|
|
||||||
this.txApperances += add;
|
|
||||||
this.totalReceivedSat += v;
|
|
||||||
if (! txItem.spentTxId ) {
|
|
||||||
//unspent
|
|
||||||
this.balanceSat += v;
|
|
||||||
}
|
|
||||||
else if(!txItem.spentIsConfirmed) {
|
|
||||||
// unspent
|
|
||||||
this.balanceSat += v;
|
|
||||||
this.unconfirmedBalanceSat -= v;
|
|
||||||
this.unconfirmedTxApperances += addSpend;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// spent
|
|
||||||
this.totalSentSat += v;
|
|
||||||
this.txApperances += addSpend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.unconfirmedBalanceSat += v;
|
|
||||||
this.unconfirmedTxApperances += add;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// opts are
|
|
||||||
// .onlyUnspent
|
|
||||||
// .txLimit (=0 -> no txs, => -1 no limit)
|
|
||||||
// .includeTxInfo
|
|
||||||
//
|
|
||||||
Address.prototype.update = function(next, opts) {
|
|
||||||
var self = this;
|
|
||||||
if (!self.addrStr) return next();
|
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
if (! ('ignoreCache' in opts) )
|
|
||||||
opts.ignoreCache = config.ignoreCache;
|
|
||||||
|
|
||||||
// should collect txList from address?
|
|
||||||
var txList = opts.txLimit === 0 ? null: [];
|
|
||||||
|
|
||||||
var tDb = TransactionDb;
|
|
||||||
var bDb = BlockDb;
|
|
||||||
tDb.fromAddr(self.addrStr, opts, function(err,txOut){
|
|
||||||
if (err) return next(err);
|
|
||||||
|
|
||||||
bDb.fillConfirmations(txOut, function(err) {
|
|
||||||
if (err) return next(err);
|
|
||||||
|
|
||||||
tDb.cacheConfirmations(txOut, function(err) {
|
|
||||||
// console.log('[Address.js.161:txOut:]',txOut); //TODO
|
|
||||||
if (err) return next(err);
|
|
||||||
if (opts.onlyUnspent) {
|
|
||||||
txOut = txOut.filter(function(x){
|
|
||||||
return !x.spentTxId;
|
|
||||||
});
|
|
||||||
tDb.fillScriptPubKey(txOut, function() {
|
|
||||||
self.unspent = txOut.map(function(x){
|
|
||||||
return {
|
|
||||||
address: self.addrStr,
|
|
||||||
txid: x.txid,
|
|
||||||
vout: x.index,
|
|
||||||
ts: x.ts,
|
|
||||||
scriptPubKey: x.scriptPubKey,
|
|
||||||
amount: x.value_sat / BitcoreUtil.COIN,
|
|
||||||
confirmations: x.isConfirmedCached ? (config.safeConfirmations) : x.confirmations,
|
|
||||||
confirmationsFromCache: !!x.isConfirmedCached,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
txOut.forEach(function(txItem){
|
|
||||||
self._addTxItem(txItem, txList, opts.includeTxInfo);
|
|
||||||
});
|
|
||||||
if (txList)
|
|
||||||
self.transactions = txList;
|
|
||||||
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = require('soop')(Address);
|
|
||||||
|
|
||||||
@ -1,105 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
//var imports = require('soop').imports();
|
|
||||||
|
|
||||||
var async = require('async');
|
|
||||||
var bitcore = require('bitcore');
|
|
||||||
var RpcClient = bitcore.RpcClient;
|
|
||||||
var config = require('../../config/config');
|
|
||||||
var rpc = new RpcClient(config.bitcoind);
|
|
||||||
var bDb = require('../../lib/BlockDb').default();
|
|
||||||
|
|
||||||
function Status() {}
|
|
||||||
|
|
||||||
Status.prototype.getInfo = function(next) {
|
|
||||||
var that = this;
|
|
||||||
async.series([
|
|
||||||
function (cb) {
|
|
||||||
rpc.getInfo(function(err, info){
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
that.info = info.result;
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
], function (err) {
|
|
||||||
return next(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Status.prototype.getDifficulty = function(next) {
|
|
||||||
var that = this;
|
|
||||||
async.series([
|
|
||||||
function (cb) {
|
|
||||||
rpc.getDifficulty(function(err, df){
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
that.difficulty = df.result;
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function (err) {
|
|
||||||
return next(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Status.prototype.getTxOutSetInfo = function(next) {
|
|
||||||
var that = this;
|
|
||||||
async.series([
|
|
||||||
function (cb) {
|
|
||||||
rpc.getTxOutSetInfo(function(err, txout){
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
that.txoutsetinfo = txout.result;
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function (err) {
|
|
||||||
return next(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Status.prototype.getBestBlockHash = function(next) {
|
|
||||||
var that = this;
|
|
||||||
async.series([
|
|
||||||
function (cb) {
|
|
||||||
rpc.getBestBlockHash(function(err, bbh){
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
that.bestblockhash = bbh.result;
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
], function (err) {
|
|
||||||
return next(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Status.prototype.getLastBlockHash = function(next) {
|
|
||||||
var that = this;
|
|
||||||
bDb.getTip(function(err,tip) {
|
|
||||||
that.syncTipHash = tip;
|
|
||||||
async.waterfall(
|
|
||||||
[
|
|
||||||
function(callback){
|
|
||||||
rpc.getBlockCount(function(err, bc){
|
|
||||||
if (err) return callback(err);
|
|
||||||
callback(null, bc.result);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(bc, callback){
|
|
||||||
rpc.getBlockHash(bc, function(err, bh){
|
|
||||||
if (err) return callback(err);
|
|
||||||
callback(null, bh.result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
],
|
|
||||||
function (err, result) {
|
|
||||||
that.lastblockhash = result;
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = require('soop')(Status);
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
var config = require('./config');
|
|
||||||
|
|
||||||
module.exports = function(app) {
|
|
||||||
|
|
||||||
var apiPrefix = config.apiPrefix;
|
|
||||||
|
|
||||||
//Block routes
|
|
||||||
var blocks = require('../app/controllers/blocks');
|
|
||||||
app.get(apiPrefix + '/blocks', blocks.list);
|
|
||||||
|
|
||||||
|
|
||||||
app.get(apiPrefix + '/block/:blockHash', blocks.show);
|
|
||||||
app.param('blockHash', blocks.block);
|
|
||||||
|
|
||||||
app.get(apiPrefix + '/block-index/:height', blocks.blockindex);
|
|
||||||
app.param('height', blocks.blockindex);
|
|
||||||
|
|
||||||
// Transaction routes
|
|
||||||
var transactions = require('../app/controllers/transactions');
|
|
||||||
app.get(apiPrefix + '/tx/:txid', transactions.show);
|
|
||||||
app.param('txid', transactions.transaction);
|
|
||||||
app.get(apiPrefix + '/txs', transactions.list);
|
|
||||||
app.post(apiPrefix + '/tx/send', transactions.send);
|
|
||||||
|
|
||||||
// Address routes
|
|
||||||
var addresses = require('../app/controllers/addresses');
|
|
||||||
app.get(apiPrefix + '/addr/:addr', addresses.show);
|
|
||||||
app.get(apiPrefix + '/addr/:addr/utxo', addresses.utxo);
|
|
||||||
app.get(apiPrefix + '/addrs/:addrs/utxo', addresses.multiutxo);
|
|
||||||
app.post(apiPrefix + '/addrs/utxo', addresses.multiutxo);
|
|
||||||
app.get(apiPrefix + '/addrs/:addrs/txs', addresses.multitxs);
|
|
||||||
app.post(apiPrefix + '/addrs/txs', addresses.multitxs);
|
|
||||||
|
|
||||||
// Address property routes
|
|
||||||
app.get(apiPrefix + '/addr/:addr/balance', addresses.balance);
|
|
||||||
app.get(apiPrefix + '/addr/:addr/totalReceived', addresses.totalReceived);
|
|
||||||
app.get(apiPrefix + '/addr/:addr/totalSent', addresses.totalSent);
|
|
||||||
app.get(apiPrefix + '/addr/:addr/unconfirmedBalance', addresses.unconfirmedBalance);
|
|
||||||
|
|
||||||
// Status route
|
|
||||||
var st = require('../app/controllers/status');
|
|
||||||
app.get(apiPrefix + '/status', st.show);
|
|
||||||
|
|
||||||
app.get(apiPrefix + '/sync', st.sync);
|
|
||||||
app.get(apiPrefix + '/peer', st.peer);
|
|
||||||
|
|
||||||
// Currency
|
|
||||||
var currency = require('../app/controllers/currency');
|
|
||||||
app.get(apiPrefix + '/currency', currency.index);
|
|
||||||
|
|
||||||
// Address routes
|
|
||||||
var messages = require('../app/controllers/messages');
|
|
||||||
app.get(apiPrefix + '/messages/verify', messages.verify);
|
|
||||||
app.post(apiPrefix + '/messages/verify', messages.verify);
|
|
||||||
|
|
||||||
//Home route
|
|
||||||
var index = require('../app/controllers/index');
|
|
||||||
app.get(apiPrefix + '/version', index.version);
|
|
||||||
app.get('*', index.render);
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue
Block a user