pow/pow.js
function startMiningWithInputs( oInput, pfnCallback )
{
	console.log( `>***< will start mining with inputs : ${ JSON.stringify( oInput ) }` );

	if ( _bBrowser && ! _bWallet )
	{
		throw new Error( 'I am not be able to run in a Web Browser.' );
	}
	if ( 'object' !== typeof oInput )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput' );
	}
	if ( 'number' !== typeof oInput.roundIndex )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.roundIndex' );
	}
	if ( 'string' !== typeof oInput.firstTrustMEBall || 44 !== oInput.firstTrustMEBall.length )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.firstTrustMEBall' );
	}
	if ( 'number' !== typeof oInput.bits || oInput.bits < 0 )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.bits' );
	}
	if ( 'string' !== typeof oInput.publicSeed || 0 === oInput.publicSeed.length )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.publicSeed' );
	}
	if ( 'string' !== typeof oInput.superNodeAuthor || 0 === oInput.superNodeAuthor.length )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.superNodeAuthor' );
	}
	if ( 'function' !== typeof pfnCallback )
	{
		throw new Error( `call startMiningWithInputs with invalid pfnCallback.` );
	}
	if ( _bDebugModel && ! _bUnitTestEnv )
	{
		return _startMiningWithInputs_debug( oInput, pfnCallback );
	}

	/**
	 *	start here
	 */
	let _oOptions	=
		{
			bufInputHeader	: _createMiningInputBufferFromObject( oInput ),
			bits		: oInput.bits,
			calcTimes	: ( 'number' === typeof oInput.calcTimes ? oInput.calcTimes : 30 ),
			maxLoop		: ( 'number' === typeof oInput.maxLoop ? oInput.maxLoop : 1000000 ),
		};
	console.log( `))) stopMining.` );
	_pow_miner.stopMining();

	console.log( `))) startMining with options : `, _oOptions );
	_pow_miner.startMining( _oOptions, function( err, oData )
	{
		let objSolution	= null;

		if ( null === err )
		{
			console.log( `))) startMining, callback data( ${ typeof oData } ) : `, oData );
			if ( oData && 'object' === typeof oData )
			{
				if ( oData.hasOwnProperty( 'win' ) && oData.win )
				{
					console.log( `pow-solution :: WINNER WINNER, CHICKEN DINNER!`, oData );
					objSolution	= {
						round		: oInput.roundIndex,
						selfBits	: oInput.bits,
						publicSeed	: oInput.publicSeed,
						nonce		: oData.nonce,
						hash		: oData.hashHex
					};
				}
				else if ( oData.hasOwnProperty( 'gameOver' ) && oData.gameOver )
				{
					err = `pow-solution :: game over!`;
				}
				else
				{
					err = `pow-solution :: unknown error!`;
				}
			}
			else
			{
				err = `pow-solution :: invalid data!`;
			}
		}

		//	...
		_event_bus.emit( 'pow_mined_gift', err, objSolution );

	});

	pfnCallback( null );
	return true;
}
function startMiningWithInputs( oInput, pfnCallback )
{
	console.log( `>***< will start mining with inputs : ${ JSON.stringify( oInput ) }` );

	if ( _bBrowser && ! _bWallet )
	{
		throw new Error( 'I am not be able to run in a Web Browser.' );
	}
	if ( 'object' !== typeof oInput )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput' );
	}
	if ( 'number' !== typeof oInput.roundIndex )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.roundIndex' );
	}
	if ( 'string' !== typeof oInput.firstTrustMEBall || 44 !== oInput.firstTrustMEBall.length )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.firstTrustMEBall' );
	}
	if ( 'number' !== typeof oInput.bits || oInput.bits < 0 )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.bits' );
	}
	if ( 'string' !== typeof oInput.publicSeed || 0 === oInput.publicSeed.length )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.publicSeed' );
	}
	if ( 'string' !== typeof oInput.superNodeAuthor || 0 === oInput.superNodeAuthor.length )
	{
		throw new Error( 'call startMiningWithInputs with invalid oInput.superNodeAuthor' );
	}
	if ( 'function' !== typeof pfnCallback )
	{
		throw new Error( `call startMiningWithInputs with invalid pfnCallback.` );
	}
	if ( _bDebugModel && ! _bUnitTestEnv )
	{
		return _startMiningWithInputs_debug( oInput, pfnCallback );
	}

	/**
	 *	start here
	 */
	let _oOptions	=
		{
			bufInputHeader	: _createMiningInputBufferFromObject( oInput ),
			bits		: oInput.bits,
			calcTimes	: ( 'number' === typeof oInput.calcTimes ? oInput.calcTimes : 30 ),
			maxLoop		: ( 'number' === typeof oInput.maxLoop ? oInput.maxLoop : 1000000 ),
		};
	console.log( `))) stopMining.` );
	_pow_miner.stopMining();

	console.log( `))) startMining with options : `, _oOptions );
	_pow_miner.startMining( _oOptions, function( err, oData )
	{
		let objSolution	= null;

		if ( null === err )
		{
			console.log( `))) startMining, callback data( ${ typeof oData } ) : `, oData );
			if ( oData && 'object' === typeof oData )
			{
				if ( oData.hasOwnProperty( 'win' ) && oData.win )
				{
					console.log( `pow-solution :: WINNER WINNER, CHICKEN DINNER!`, oData );
					objSolution	= {
						round		: oInput.roundIndex,
						selfBits	: oInput.bits,
						publicSeed	: oInput.publicSeed,
						nonce		: oData.nonce,
						hash		: oData.hashHex
					};
				}
				else if ( oData.hasOwnProperty( 'gameOver' ) && oData.gameOver )
				{
					err = `pow-solution :: game over!`;
				}
				else
				{
					err = `pow-solution :: unknown error!`;
				}
			}
			else
			{
				err = `pow-solution :: invalid data!`;
			}
		}

		//	...
		_event_bus.emit( 'pow_mined_gift', err, objSolution );

	});

	pfnCallback( null );
	return true;
}
function startMiningWithInputs ( oInput , pfnCallback ) { console . log ( ` ${ JSON . stringify ( oInput ) } ` ) ; if ( _bBrowser && ! _bWallet ) { throw new Error ( 'I am not be able to run in a Web Browser.' ) ; } if ( 'object' !== typeof oInput ) { throw new Error ( 'call startMiningWithInputs with invalid oInput' ) ; } if ( 'number' !== typeof oInput . roundIndex ) { throw new Error ( 'call startMiningWithInputs with invalid oInput.roundIndex' ) ; } if ( 'string' !== typeof oInput . firstTrustMEBall || 44 !== oInput . firstTrustMEBall . length ) { throw new Error ( 'call startMiningWithInputs with invalid oInput.firstTrustMEBall' ) ; } if ( 'number' !== typeof oInput . bits || oInput . bits < 0 ) { throw new Error ( 'call startMiningWithInputs with invalid oInput.bits' ) ; } if ( 'string' !== typeof oInput . publicSeed || 0 === oInput . publicSeed . length ) { throw new Error ( 'call startMiningWithInputs with invalid oInput.publicSeed' ) ; } if ( 'string' !== typeof oInput . superNodeAuthor || 0 === oInput . superNodeAuthor . length ) { throw new Error ( 'call startMiningWithInputs with invalid oInput.superNodeAuthor' ) ; } if ( 'function' !== typeof pfnCallback ) { throw new Error ( ` ` ) ; } if ( _bDebugModel && ! _bUnitTestEnv ) { return _startMiningWithInputs_debug ( oInput , pfnCallback ) ; } /**
	 *	start here
	 */ let _oOptions = { bufInputHeader : _createMiningInputBufferFromObject ( oInput ) , bits : oInput . bits , calcTimes : ( 'number' === typeof oInput . calcTimes ? oInput . calcTimes : 30 ) , maxLoop : ( 'number' === typeof oInput . maxLoop ? oInput . maxLoop : 1000000 ) , } ; console . log ( ` ` ) ; _pow_miner . stopMining ( ) ; console . log ( ` ` , _oOptions ) ; _pow_miner . startMining ( _oOptions , function ( err , oData ) { let objSolution = null ; if ( null === err ) { console . log ( ` ${ typeof oData } ` , oData ) ; if ( oData && 'object' === typeof oData ) { if ( oData . hasOwnProperty ( 'win' ) && oData . win ) { console . log ( ` ` , oData ) ; objSolution = { round : oInput . roundIndex , selfBits : oInput . bits , publicSeed : oInput . publicSeed , nonce : oData . nonce , hash : oData . hashHex } ; } else if ( oData . hasOwnProperty ( 'gameOver' ) && oData . gameOver ) { err = ` ` ; } else { err = ` ` ; } } else { err = ` ` ; } } //	... _event_bus . emit ( 'pow_mined_gift' , err , objSolution ) ; } ) ; pfnCallback ( null ) ; return true ; }
start calculation with inputs

@param	{object}	oInput
@param	{number}	oInput.roundIndex
@param	{string}	oInput.firstTrustMEBall
@param	{string}	oInput.bits
@param	{string}	oInput.publicSeed
@param	{string}	oInput.superNodeAuthor
@param	{function}	pfnCallback( err )	will be called immediately while we start mining
@return	{boolean}

@events

'pow_mined_gift'

will post solution object through event bus while mining successfully

[parameters]
err		- null if no error, otherwise a string contains error description,
objSolution	- solution object
{
round		: oInput.roundIndex,
bits		: oInput.bits,
publicSeed	: oInput.publicSeed,
nonce		: oData.nonce,
hash		: oData.hashHex
};
start calculation with inputs