import { Request , Response , NextFunction } from 'express' ; import { BaseChannel , PluginCodec } from 'lisk-framework' ; import { isNumberString } from '@liskhq/lisk-validator' ; export const getNodeInfo = ( channel ) => async ( _req , res , next ) : Promise < void > => { try { const nodeStatusAndInfo = await channel . invoke ( 'app:getNodeInfo' ) ; res . status ( 200 ) . send ( { data : nodeStatusAndInfo , meta : { } } ) ; } catch ( err ) { next ( err ) ; } } ; export const getTransactions = ( channel , codec ) => async ( req , res , next ) : Promise < void > => { const { limit , offset } = req . query ; if ( limit && ! isNumberString ( limit ) ) { res . status ( 400 ) . send ( { errors : [ { message : 'The limit query parameter should be a number.' } ] , } ) ; return ; } const limitNumber = Number ( limit ) || 10 ; if ( offset && ! isNumberString ( offset ) ) { res . status ( 400 ) . send ( { errors : [ { message : 'The offset query parameter should be a number.' } ] , } ) ; return ; } const offsetNumber = Number ( offset ) || 0 ; let transactionsInPool ; try { transactionsInPool = await channel . invoke < ReadonlyArray < Buffer > > ( 'app:getTransactionsFromPool' ) ; } catch ( err ) { next ( err ) ; return ; } const totalTransactionsInPool = transactionsInPool . length ; transactionsInPool = transactionsInPool . slice ( offsetNumber || 0 , Math . min ( limitNumber + offsetNumber , transactionsInPool . length ) ) ; const decodedTransactions = [ ] ; for ( const transaction of transactionsInPool ) { decodedTransactions . push ( codec . decodeTransaction ( transaction ) ) ; } res . status ( 200 ) . json ( { data : decodedTransactions , meta : { limit : limitNumber , offset : offsetNumber , total : totalTransactionsInPool } , } ) ; } ;