import { Blockchain , BlockBody , BlockHeader } from '@uniqys/blockchain' ; import { Protocol , Message } from '@uniqys/protocol' ; export class Responder { constructor ( private readonly blockchain ) { } public async getConsentedHeader ( msg , _ ) { const header = await this . blockchain . headerOf ( msg . height ) ; const consensus = await this . blockchain . consensusOf ( msg . height ) ; const validatorSet = await this . blockchain . validatorSetOf ( msg . height ) ; return new Message . ConsentedHeader ( header , consensus , validatorSet ) ; } public async getHeaders ( msg , _ ) { const i = msg . from ; const last = Math . min ( await this . blockchain . height , i + msg . count - 1 ) ; const headers = [ ] ; for ( let i = msg . from ; i <= last ; i ++ ) { headers . push ( await this . blockchain . headerOf ( i ) ) ; } return new Message . Headers ( headers ) ; } public async getBodies ( msg , _ ) { const i = msg . from ; const last = Math . min ( await this . blockchain . height , i + msg . count - 1 ) ; const bodies = [ ] ; for ( let i = msg . from ; i <= last ; i ++ ) { bodies . push ( await this . blockchain . bodyOf ( i ) ) ; } return new Message . Bodies ( bodies ) ; } }