import { Tx , TxInfos } from '../../state/txs' ; import { State } from '../../state' ; import { format_txinfos } from '../../utils/format_txinfos' ; export const getTransaction = ( state , tx_hash ) : Tx => { if ( tx_hash ) { return state . txs [ tx_hash ] ; } } ; export const getTransactionById = ( state , tx_id ) : Tx => Object . keys ( state . txs ) . map ( ( key ) : Tx => state . txs [ key ] ) . filter ( ( elem ) => elem . id === tx_id ) [ 0 ] ; export const getTransactions = ( state , tx_infos ? ) : Tx [ ] => { if ( ! tx_infos ) { return Object . keys ( state . txs ) . map ( ( key ) => state . txs [ key ] ) ; } else { tx_infos = format_txinfos ( tx_infos ) ; return Object . keys ( state . txs ) . map ( ( key ) => state . txs [ key ] ) . filter ( ( elem ) => ! tx_infos . from || tx_infos . from === elem . infos . from ) . filter ( ( elem ) => ! tx_infos . to || tx_infos . to === elem . infos . to ) . filter ( ( elem ) => ! tx_infos . input || tx_infos . input === elem . infos . input ) . filter ( ( elem ) => ! tx_infos . hash || tx_infos . hash === elem . infos . hash ) . filter ( ( elem ) => ! tx_infos . nonce || tx_infos . nonce === elem . infos . nonce ) . filter ( ( elem ) => ! tx_infos . blockHash || tx_infos . blockHash === elem . infos . blockHash ) . filter ( ( elem ) => ! tx_infos . blockNumber || tx_infos . blockNumber === elem . infos . blockNumber ) . filter ( ( elem ) => ! tx_infos . transactionIndex || tx_infos . transactionIndex === elem . infos . transactionIndex ) . filter ( ( elem ) => ! tx_infos . value || tx_infos . value === elem . infos . value ) . filter ( ( elem ) => ! tx_infos . gasPrice || tx_infos . gasPrice === elem . infos . gasPrice ) . filter ( ( elem ) => ! tx_infos . gas || tx_infos . gas === elem . infos . gas ) . filter ( ( elem ) => ! tx_infos . input || tx_infos . input === elem . infos . input ) . filter ( ( elem ) => ! tx_infos . r || tx_infos . r === elem . infos . r ) . filter ( ( elem ) => ! tx_infos . v || tx_infos . v === elem . infos . v ) . filter ( ( elem ) => ! tx_infos . s || tx_infos . s === elem . infos . s ) ; } } ;