Skip to content

Commit a51533a

Browse files
authored
Merge pull request #2378 from bsnowden3/input-w-tx-endpoint
Transaction endpoint w/ inputs and outputs
2 parents a6a8572 + 68db0f4 commit a51533a

File tree

1 file changed

+37
-0
lines changed
  • packages/bitcore-node/src/routes/api

1 file changed

+37
-0
lines changed

packages/bitcore-node/src/routes/api/tx.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { CSP } from '../../types/namespaces/ChainStateProvider';
44
import { ChainStateProvider } from '../../providers/chain-state';
55
import logger from '../../logger';
66
import { CacheTimes } from '../middleware';
7+
import { ITransaction } from '../../models/transaction';
8+
import { ICoin } from '../../models/coin';
9+
710
const router = Router({ mergeParams: true });
811

912
router.get('/', function(req, res) {
@@ -57,6 +60,40 @@ router.get('/:txId', async (req, res) => {
5760
}
5861
});
5962

63+
// Get transaction with input and outputs, assigned to key coins
64+
router.get('/:txId/populated', async (req, res) => {
65+
let { chain, network, txId } = req.params;
66+
let txid = txId;
67+
if (typeof txid !== 'string' || !chain || !network) {
68+
return res.status(400).send('Missing required param');
69+
}
70+
71+
try {
72+
let tx: ITransaction & { blockHeight: number, coins?: Array<ICoin> };
73+
let coins: any;
74+
let tip: any;
75+
76+
[tx, coins, tip] = await Promise.all([ChainStateProvider.getTransaction({ chain, network, txId }), ChainStateProvider.getCoinsForTx({ chain, network, txid }),
77+
ChainStateProvider.getLocalTip({ chain, network })]);
78+
79+
if (!tx) {
80+
return res.status(404).send(`The requested txid ${txid} could not be found.`);
81+
} else {
82+
if (tx && tip && tip.height - tx.blockHeight > 100) {
83+
SetCache(res, CacheTimes.Month);
84+
}
85+
86+
if (!coins) {
87+
res.status(404).send(`The requested coins for txid ${txid} could not be found.`);
88+
}
89+
tx.coins = coins;
90+
return res.send(tx);
91+
}
92+
} catch (err) {
93+
return res.status(500).send(err);
94+
}
95+
});
96+
6097
router.get('/:txId/authhead', async (req, res) => {
6198
let { chain, network, txId } = req.params;
6299
if (typeof txId !== 'string' || !chain || !network) {

0 commit comments

Comments
 (0)