@@ -4,6 +4,9 @@ import { CSP } from '../../types/namespaces/ChainStateProvider';
44import { ChainStateProvider } from '../../providers/chain-state' ;
55import logger from '../../logger' ;
66import { CacheTimes } from '../middleware' ;
7+ import { ITransaction } from '../../models/transaction' ;
8+ import { ICoin } from '../../models/coin' ;
9+
710const router = Router ( { mergeParams : true } ) ;
811
912router . 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+
6097router . get ( '/:txId/authhead' , async ( req , res ) => {
6198 let { chain, network, txId } = req . params ;
6299 if ( typeof txId !== 'string' || ! chain || ! network ) {
0 commit comments