feat: ensure format consistency and add badges to README

This commit is contained in:
Marvin 2018-02-13 01:13:17 +01:00
commit d6121571a2
7 changed files with 28 additions and 14 deletions

9
.editorconfig Normal file
View file

@ -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

View file

@ -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.

View file

@ -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",

View file

@ -16,4 +16,4 @@ export default [
commonjs() // so Rollup can convert `ms` to an ES module
]
},
]
]

View file

@ -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
}

View file

@ -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 <uint8_t*> (&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);
}
}
}

View file

@ -9,4 +9,4 @@ async function test () {
assert.deepEqual(work, '81df2c0600000000')
}
test()
test()