import { BigNumber , serializeObject , SignatureProvider } from '@pigi/core-utils' ; import { doRangesSpanRange } from '@pigi/core-db' ; import { Aggregator , BlockManager , StateManager , BlockTransaction , BlockTransactionCommitment , Transaction , TransactionResult , } from '../../types' ; export class DefaultAggregator implements Aggregator { public constructor ( private readonly stateManager , private readonly blockManager , private readonly publicKey , private readonly signatureProvider ) { } public async ingestTransaction ( transaction ) { const blockNumber = await this . blockManager . getNextBlockNumber ( ) ; const { stateUpdate , validRanges , } = await this . stateManager . executeTransaction ( transaction , blockNumber , '' ) ; if ( ! doRangesSpanRange ( validRanges , transaction . range ) ) { throw Error ( `Cannot ingest Transaction that is not valid across its entire range. 
        Valid Ranges: ${ JSON . stringify ( validRanges ) }. 
        Transaction: ${ JSON . stringify ( transaction ) }.` ) ; } await this . blockManager . addPendingStateUpdate ( stateUpdate ) ; const blockTransaction = { blockNumber , transaction , } ; const serializedTransaction = serializeObject ( blockTransaction ) ; return { blockTransaction , witness : await this . signatureProvider . sign ( serializedTransaction ) , } ; } public async getPublicKey ( ) { return this . publicKey ; } }