import { Request , Response , NextFunction } from 'express' ; import { BaseChannel , PluginCodec } from 'lisk-framework' ; interface DPoSAccountJSON { dpos : { delegate : { username : string ; totalVotesReceived : string ; } ; } ; } export const getForgers = ( channel , codec ) => async ( _req , res , next ) : Promise < void > => { let forgersFrameworkInfo ; try { forgersFrameworkInfo = await channel . invoke ( 'app:getForgers' ) ; } catch ( err ) { next ( err ) ; return ; } try { const forgerAccounts = await channel . invoke < string [ ] > ( 'app:getAccounts' , { address : forgersFrameworkInfo . map ( info => info . address ) , } ) ; const data = [ ] ; for ( let i = 0 ; i < forgerAccounts . length ; i += 1 ) { const account = codec . decodeAccount < DPoSAccountJSON > ( forgerAccounts [ i ] ) ; data . push ( { username : account . dpos . delegate . username , totalVotesReceived : account . dpos . delegate . totalVotesReceived , ... forgersFrameworkInfo [ i ] , } ) ; } res . status ( 200 ) . json ( { data , meta : { count : forgerAccounts . length } } ) ; } catch ( err ) { next ( err ) ; } } ;