diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..79621be --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 diff --git a/README.md b/README.md index e69de29..1e2db5c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,8 @@ +# nanocurrency-js + +[![Build Status](https://travis-ci.org/marvinroger/nanocurrency-js.svg?branch=master)](https://travis-ci.org/marvinroger/nanocurrency-js) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) + +--- + +A toolkit for the Nano cryptocurrency. diff --git a/package.json b/package.json index afe27e4..e8ed685 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nanocurrency", - "description": "Toolkit for the Nano cryptocurrency", + "description": "A toolkit for the Nano cryptocurrency.", "version": "0.0.0-development", "author": { "name": "Marvin ROGER", diff --git a/rollup.config.js b/rollup.config.js index d2a85ac..4e69d9f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -16,4 +16,4 @@ export default [ commonjs() // so Rollup can convert `ms` to an ES module ] }, -] \ No newline at end of file +] diff --git a/src/index.js b/src/index.js index dc01ebe..298cc03 100644 --- a/src/index.js +++ b/src/index.js @@ -20,6 +20,6 @@ export function generateWork (blockHash, workerNumber = 0, workerCount = 1) { if (instance === null) throw new Error('Nano is not initialized') const work = _generateWork(blockHash, workerNumber, workerCount) - + return work !== '0000000000000000' ? work : null } diff --git a/src/native/functions.cpp b/src/native/functions.cpp index b338801..b64eae5 100644 --- a/src/native/functions.cpp +++ b/src/native/functions.cpp @@ -10,8 +10,7 @@ const uint64_t WORK_THRESHOLD = 0xffffffc000000000; void hex_to_bytes(const std::string& hex, uint8_t* bytes) { int byte_index = 0; - for (unsigned int i = 0; i < hex.length(); i += 2) - { + for (unsigned int i = 0; i < hex.length(); i += 2) { std::string byte_string = hex.substr(i, 2); uint8_t byte = (uint8_t) strtol(byte_string.c_str(), NULL, 16); bytes[byte_index++] = byte; @@ -20,7 +19,7 @@ void hex_to_bytes(const std::string& hex, uint8_t* bytes) { uint64_t generate_work(uint8_t* block_hash, uint8_t worker_number, uint8_t worker_count) { const uint64_t interval = (MAX_UINT64 - MIN_UINT64) / worker_count; - + const uint64_t lower_bound = MIN_UINT64 + (worker_number * interval); const uint64_t upper_bound = (worker_number != worker_count - 1) ? lower_bound + interval : MAX_UINT64; @@ -36,14 +35,13 @@ uint64_t generate_work(uint8_t* block_hash, uint8_t worker_number, uint8_t worke blake2b_final(&hash, reinterpret_cast (&output), sizeof (output)); work++; } - + work--; return work; } -uint64_t swap_uint64(uint64_t val) -{ +uint64_t swap_uint64(uint64_t val) { val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL ); val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL ); return (val << 32) | (val >> 32); @@ -51,16 +49,15 @@ uint64_t swap_uint64(uint64_t val) extern "C" { EMSCRIPTEN_KEEPALIVE - char* emscripten_generate_work(char* block_hash_hex, uint8_t worker_number, uint8_t worker_count) - { + char* emscripten_generate_work(char* block_hash_hex, uint8_t worker_number, uint8_t worker_count) { std::string block_hash_hex_string(block_hash_hex); uint8_t block_hash_bytes[32]; hex_to_bytes(block_hash_hex_string, block_hash_bytes); - + uint64_t work = generate_work(block_hash_bytes, worker_number, worker_count); char work_hex[16 + 1]; sprintf(work_hex, "%016llx", swap_uint64(work)); return strdup(work_hex); } -} \ No newline at end of file +} diff --git a/test/test.js b/test/test.js index 4887212..5d6d69e 100644 --- a/test/test.js +++ b/test/test.js @@ -9,4 +9,4 @@ async function test () { assert.deepEqual(work, '81df2c0600000000') } -test() \ No newline at end of file +test()