Wondering what’s next for npm?Check out our public roadmap! »

trustnote-pow-miner

1.0.11 • Public • Published

TrustNote Pow-Miner

Install

$ npm install trustnote-pow-miner

Supported Platforms

MacOS, Linux, Windows

Documentation

.startMining( oOptions, pfnCallback )

start mining

  • oOptions
name type optional comment
.bufInputHeader Buffer no 140 bytes Buffer object
.difficulty Number no number
.calcTimes Number yes default value : 30, compute times per loop
.maxLoop Number yes default value : 10000000, max loop
  • pfnCallback( err, oSolution )

oSolution is a plain object :

{ win : true, hashHex : sActualHashHex, nonce : uActualNonce }
{ win : false, gameOver : true, hashHex : null, nonce : 0 }

const _miner = require( 'trustnote-pow-miner' );
 
/**
 *
 */
let bufInput = new Buffer( 140 );
let nDifficulty = _miner.difficulty256HexToUInt32( "0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
let oOptions =
    {
        bufInputHeader : bufInput,
        difficulty : nDifficulty,
        calcTimes : 30,
        maxLoop : 1000000,
    };
_miner.startMining( oOptions, function( err, oData )
{
    if ( null === err )
    {
        if ( oData )
        {
            if ( oData.win )
            {
                console.log( `WINNER WINNER, CHICKEN DINNER!`, oData );
            }
            else if ( oData.gameOver )
            {
                console.log( `GAME OVER!` );
            }
        }
        else
        {
            console.log( `INVALID DATA!` );
        }
    }
    else
    {
        console.log( `OCCURRED ERROR : `, err );
    }
});
 



.stopMining()

stop mining

const _miner = require( 'trustnote-pow-miner' );
 
_miner.stop();
console.log( `The KILL signals were sent to all workers.` );



.checkProofOfWork( bufInputHeader, uDifficulty, uActualNonce, sActualHashHex, pfnCallback )

check proof of work

const _miner = require( 'trustnote-pow-miner' );
 
 
checkProofOfWork( bufInputHeader, uDifficulty, uActualNonce, sActualHashHex, pfnCallback )
 

Install

npm i trustnote-pow-miner

DownloadsWeekly Downloads

104

Version

1.0.11

License

MIT

Unpacked Size

4.65 MB

Total Files

159

Last publish

Collaborators

  • avatar