forked from trustnote-org/trustnote-pow-miner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2, Added comments 3, Update package to 1.0.9
- Loading branch information
Showing
8 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Demos for TrustNote Pow-Miner | ||
|
||
## Install | ||
``` | ||
$ npm install https://github.com/trustnote/trustnote-pow-common.git#dev -save | ||
$ npm install trustnote-pow-miner -save | ||
``` | ||
|
||
|
||
## Get Started | ||
|
||
#### start mining | ||
``` | ||
$ node pow_start_mining.js | ||
``` | ||
|
||
|
||
#### stop mining | ||
``` | ||
$ node pow_stop_mining.js | ||
``` | ||
|
||
|
||
|
||
#### difficulty | ||
convert difficult from 256 hex string to uint32 | ||
``` | ||
$ node pow_difficulty.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "trustnote-pow-miner-demo", | ||
"description": "Demo of TrustNote PoW Miner", | ||
"author": "Trustnote", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"repository": { | ||
"url": "https://github.com/trustnote/trustnote-pow-miner.git", | ||
"type": "git" | ||
}, | ||
"browser": { | ||
"request": "browser-request", | ||
"secp256k1": "secp256k1/js" | ||
}, | ||
"dependencies": { | ||
"bitcore-lib": "^0.13.14", | ||
"bitcore-mnemonic": "~1.0.0", | ||
"json-rpc2": "^1.0.2", | ||
"trustnote-pow-common": "git+https://github.com/trustnote/trustnote-pow-common.git#dev", | ||
"trustnote-pow-miner": ">=1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const _trustnote_pow_miner = require( 'trustnote-pow-miner' ); | ||
|
||
|
||
let sDifficulty256Hex = "00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; | ||
let nDifficultyU32 = _trustnote_pow_miner.difficulty256HexToUInt32( sDifficulty256Hex ); | ||
|
||
|
||
console.log( `CONVERT DIFFICULT FROM 256 HEX STRING TO UINT32` ); | ||
console.log( `sDifficulty256Hex\t: ${ sDifficulty256Hex }` ); | ||
console.log( `nDifficultyU32 \t: ${ nDifficultyU32 }` ); | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const _pow = require( 'trustnote-pow-common/pow.js' ); | ||
const _event_bus = require( 'trustnote-pow-common/event_bus.js' ); | ||
const _trustnote_pow_miner = require( 'trustnote-pow-miner' ); | ||
|
||
|
||
// | ||
// * @param {number} oInput.currentRoundIndex | ||
// * @param {string} oInput.currentFirstTrustMEBall | ||
// * @param {string} oInput.currentDifficulty | ||
// * @param {string} oInput.currentPubSeed | ||
// * @param {string} oInput.superNodeAuthor | ||
// | ||
let nDifficulty = _trustnote_pow_miner.difficulty256HexToUInt32( "00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); | ||
let oMiningInput = { | ||
roundIndex : 111, | ||
firstTrustMEBall : 'rjywtuZ8A70vgIsZ7L4lBR3gz62Nl3vZr2t7I4lzsMU=', | ||
difficulty : nDifficulty, | ||
publicSeed : 'public key', | ||
superNodeAuthor : 'xing.supernode.trustnote.org', | ||
}; | ||
|
||
|
||
_event_bus.on | ||
( | ||
'pow_mined_gift', | ||
( objSolution ) => | ||
{ | ||
console.log( `############################################################` ); | ||
console.log( objSolution ); | ||
|
||
if ( 'object' === typeof objSolution ) | ||
{ | ||
console.log( `will check proof of work` ); | ||
_pow.checkProofOfWork( oMiningInput, objSolution.hash, objSolution.nonce, function( err, objResult ) | ||
{ | ||
console.log( `_pow.checkProofOfWork, err : ${ err }, objResult : `, objResult ); | ||
if ( null === err && | ||
'object' === typeof objResult && | ||
'number' === typeof objResult.code && 0 === objResult.code ) | ||
{ | ||
console.log( `PoW is correct.` ); | ||
} | ||
else | ||
{ | ||
console.error( `PoW is invalid : `, err ); | ||
} | ||
}); | ||
} | ||
else | ||
{ | ||
console.error( `invalid objSolution` ); | ||
} | ||
} | ||
); | ||
_pow.startMiningWithInputs | ||
( | ||
oMiningInput, | ||
function( err ) | ||
{ | ||
if ( err ) | ||
{ | ||
console.log( `failed to start calculation, `, err ); | ||
return; | ||
} | ||
|
||
console.log( `start calculation successfully.` ); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const _trustnote_pow_miner = require( 'trustnote-pow-miner' ); | ||
|
||
|
||
_trustnote_pow_miner.stopMining(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters