import { BigNumber } from '@pigi/core-utils' ; import { Mutex } from 'async-mutex' ; import { BlockDB , BlockManager , CommitmentContract , } from '../../types/block-production' ; import { StateUpdate } from '../../types' ; /**
 * Simple BlockManager implementation.
 */ export class DefaultBlockManager implements BlockManager { private readonly blockSubmissionMutex : Mutex ; param blockdb param commitmentContract constructor ( private blockdb , private commitmentContract ) { this . blockSubmissionMutex = new Mutex ( ) ; } returns public async getNextBlockNumber ( ) { return this . blockdb . getNextBlockNumber ( ) ; } param stateUpdate returns public async addPendingStateUpdate ( stateUpdate ) { await this . blockdb . addPendingStateUpdate ( stateUpdate ) ; } returns public async getPendingStateUpdates ( ) { return this . blockdb . getPendingStateUpdates ( ) ; } returns public async submitNextBlock ( ) { await this . blockSubmissionMutex . runExclusive ( async ( ) => { if ( ( await this . getPendingStateUpdates ( ) ) . length === 0 ) { return ; } const blockNumber = await this . getNextBlockNumber ( ) ; await this . blockdb . finalizeNextBlock ( ) ; const root = await this . blockdb . getMerkleRoot ( blockNumber ) ; await this . commitmentContract . submitBlock ( root ) ; } ) ; } }