const minutesBetweenBlocks = 2 ; interface Block { size : number ; } interface Transaction { tx_fee : number ; tx_hash : string ; tx_size : number ; } function getNumberOfBlocksToProcessSize ( txsTotalSize , blockSizeLimit = 350000 ) { if ( blockSizeLimit > txsTotalSize ) { return 1 ; } else { return Math . ceil ( txsTotalSize / blockSizeLimit ) ; } } function findTx ( txHash , mempool ) { return mempool . filter ( tx => { return tx . tx_hash === txHash ; } ) [ 0 ] ; } const getBlockSizeLimit = ( blocks ) => { return blocks [ 49 ] . size * 2 ; } ; export function minutesUntilMined ( txHash , mempool , blocks ) { const fullTx = findTx ( txHash , mempool ) ; if ( ! fullTx ) { throw Error ( `Transaction with hash ${ txHash } does not exist in supplied mempool` ) ; } const txPSortedMempool = [ ... mempool ] . sort ( ( a , b ) => a . tx_fee - b . tx_fee ) ; const fTxPSortedMempool = txPSortedMempool . filter ( tx => tx . tx_fee > fullTx . tx_fee ) ; const txsTotalSize = fTxPSortedMempool . map ( tx => tx . tx_size ) . reduce ( ( prev , next ) => prev + next ) ; const blockSizeLimit = getBlockSizeLimit ( blocks . sort ( ( a , b ) => a . size - b . size ) ) ; const numOfBlocks = getNumberOfBlocksToProcessSize ( txsTotalSize , blockSizeLimit ) ; return numOfBlocks * minutesBetweenBlocks ; }