tx by address wired up
This commit is contained in:
parent
697388f1ce
commit
46842c9cc5
@ -9,36 +9,14 @@ const TTL = config.api.request_ttl;
|
|||||||
module.exports = function AddressAPI(router) {
|
module.exports = function AddressAPI(router) {
|
||||||
router.get('/addr/:addr', (req, res) => {
|
router.get('/addr/:addr', (req, res) => {
|
||||||
const addr = req.params.addr || '';
|
const addr = req.params.addr || '';
|
||||||
/*
|
|
||||||
db.txs.getTxByAddress(addr, 0, 999999999, (error, txs) => {
|
db.txs.getTxByAddress(addr, 0, 999999999, (error, txs) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
logger.log('err',
|
logger.log('error',
|
||||||
`getTxByBlock ${error}`);
|
`getTxByBlock ${error}`);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(txs.count());
|
|
||||||
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
// Get Bcoin data
|
|
||||||
return request(`${API_URL}/tx/address/${addr}`,
|
|
||||||
{ timeout: TTL },
|
|
||||||
(error, bcoinRes, bcoinTxs) => {
|
|
||||||
if (error) {
|
|
||||||
logger.log('error',
|
|
||||||
`${error}`);
|
|
||||||
return res.status(404).send({});
|
|
||||||
}
|
|
||||||
let txs = {};
|
|
||||||
try {
|
|
||||||
txs = JSON.parse(bcoinTxs);
|
|
||||||
} catch (e) {
|
|
||||||
logger.log('error',
|
|
||||||
`${e}`);
|
|
||||||
return res.status(404).send({});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sum the matching outputs for every tx
|
// Sum the matching outputs for every tx
|
||||||
const totalReceived = txs.reduce((total, tx) => total + tx.outputs.reduce((sum, output) => {
|
const totalReceived = txs.reduce((total, tx) => total + tx.outputs.reduce((sum, output) => {
|
||||||
if (output.address === req.params.addr) {
|
if (output.address === req.params.addr) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user