-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from pk910/contract-miner
Implement nickminer algorithm for `pow` module
- Loading branch information
Showing
31 changed files
with
1,206 additions
and
132 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
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
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
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,25 @@ | ||
|
||
import { PoWWorker } from "./PoWWorker"; | ||
import { getNickMiner, getNickMinerReadyPromise } from "../../../libs/nickminer_wasm.cjs"; | ||
import { PoWHashAlgo } from "../types/PoWMinerSrc"; | ||
|
||
(() => { | ||
getNickMinerReadyPromise().then(() => { | ||
let nickMiner = getNickMiner(); | ||
nickMiner.miner_init(); | ||
|
||
new PoWWorker({ | ||
hashFn: (nonce, preimg, params) => { | ||
if(params.a !== PoWHashAlgo.NICKMINER) | ||
return null; | ||
return nickMiner.miner_run(nonce); | ||
}, | ||
configFn: (preimg, params) => { | ||
if(params.a !== PoWHashAlgo.NICKMINER) | ||
return null; | ||
nickMiner.miner_set_config(params.i, params.r, params.v, params.s, params.c, preimg); | ||
} | ||
}); | ||
|
||
}) | ||
})(); |
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
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,3 @@ | ||
|
||
build | ||
secp256k1 |
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,47 @@ | ||
|
||
import { encode } from "base32768"; | ||
import fs from "fs"; | ||
|
||
const base32768Module = fs.readFileSync("node_modules/base32768/src/index.js", { encoding: "utf8" }).replace(/^export .*$/m, ""); | ||
const base32768WASM = encode(fs.readFileSync("build/nickminer.wasm")); | ||
|
||
const wasmWrappperJS = fs.readFileSync("build/nickminer.js", { encoding: "utf8" }); | ||
let lines = wasmWrappperJS.replace(/import\.meta/g, "wasmMeta").split("\n"); | ||
// filter out the "export default Module" line | ||
lines = lines.filter(line => !line.startsWith("export default Module")); | ||
const customWASMWrappperJS = lines.join("\n"); | ||
|
||
// -------------------------------------------------------------------------- | ||
// Output the composited webworker JS | ||
|
||
// first, include the warning about this file being automatically generated | ||
console.log(` | ||
// THIS FILE IS GENERATED AUTOMATICALLY | ||
// Don't edit this file by hand. | ||
// Edit the build located in the faucet-wasm folder. | ||
var nickMinerPromise, nickMiner; | ||
module.exports = { | ||
getNickMiner: function() { return nickMiner; }, | ||
getNickMinerReadyPromise: function() { return nickMinerPromise; } | ||
}; | ||
function getWasmBinary() { | ||
${base32768Module} | ||
const base32768WASM = "${base32768WASM}"; | ||
return decode(base32768WASM); | ||
} | ||
(function() { | ||
var wasmMeta = {}; | ||
if(typeof self === "undefined") { | ||
var self = {location:{href:""}}; | ||
} | ||
${customWASMWrappperJS} | ||
nickMinerPromise = Module(); | ||
})(); | ||
`); |
Oops, something went wrong.