Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add preliminary support for windows #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"variables": {
"hs_endian%": "<!(./scripts/get endian)",
"hs_cudahas%": "<!(./scripts/get cuda_has)",
"hs_cudalib%": "<!(./scripts/get cuda_lib)",
"hs_network%": "<!(./scripts/get network)",
"hs_oclhas%": "<!(./scripts/get ocl_has)",
"hs_os%": "<!(./scripts/get os)"
"hs_endian%": "<!(bash scripts/get endian)",
"hs_cudahas%": "<!(bash scripts/get cuda_has)",
"hs_cudalib%": "<!(bash scripts/get cuda_lib)",
"hs_network%": "<!(bash scripts/get network)",
"hs_oclhas%": "<!(bash scripts/get ocl_has)",
"hs_os%": "<!(bash scripts/get os)"
},
"targets": [{
"target_name": "hsminer",
Expand All @@ -16,7 +16,8 @@
"./src/header.c",
"./src/verify.cc",
"./src/opencl.c",
"./src/simple.cc",
"./src/simple_unix.cc",
"./src/simple_windows.cc",
"./src/utils.c"
],
"cflags": [
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
"author": "Christopher Jeffrey <[email protected]>",
"main": "./lib/hs-miner.js",
"bin": {
"hs-miner": "./bin/hs-miner",
"hs-mine": "./bin/hs-mine"
"hs-miner": "bash bin/hs-miner",
"hs-mine": "bash bin/hs-mine"
},
"scripts": {
"install": "./scripts/rebuild main",
"install-main": "./scripts/rebuild main",
"install-testnet": "./scripts/rebuild testnet",
"install-regtest": "./scripts/rebuild regtest",
"install-simnet": "./scripts/rebuild simnet",
"bench": "./bin/hs-bench",
"clean": "./scripts/clean",
"install": "bash scripts/rebuild main",
"install-main": "bash scripts/rebuild main",
"install-testnet": "bash scripts/rebuild testnet",
"install-regtest": "bash scripts/rebuild regtest",
"install-simnet": "bash scripts/rebuild simnet",
"bench": "bash bin/hs-bench",
"clean": "bash scripts/clean",
"lint": "eslint bin/* lib/*.js test/*.js || exit 0",
"test": "bmocha --reporter spec test/*-test.js"
},
Expand Down
8 changes: 4 additions & 4 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ cd ${dir}/..
set -ex

CXX=$(test -z "$CXX" && echo 'g++' || echo "$CXX")
ENDIAN=$(./scripts/get endian)
CUDA_HAS=$(./scripts/get cuda_has)
NVCC=$(./scripts/get nvcc)
NETWORK=$(./scripts/get network)
ENDIAN=$(bash scripts/get endian)
CUDA_HAS=$(bash scripts/get cuda_has)
NVCC=$(bash scripts/get nvcc)
NETWORK=$(bash scripts/get network)
DENDIAN=$(test "$ENDIAN" = "little" \
&& echo -DHS_LITTLE_ENDIAN \
|| echo -DHS_BIG_ENDIAN)
Expand Down
2 changes: 1 addition & 1 deletion scripts/rebuild
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ dir=$(dirname "$file")

cd ${dir}/..

HS_NETWORK=$1 CUDA_PREFIX=$2 ./scripts/build
HS_NETWORK=$1 CUDA_PREFIX=$2 bash scripts/build
5 changes: 2 additions & 3 deletions src/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,12 @@ hs_header_sub_encode(const hs_header_t *hdr, uint8_t *data) {

void
hs_header_sub_hash(const hs_header_t *hdr, uint8_t *hash) {
int size = hs_header_sub_size(hdr);
uint8_t sub[size];
uint8_t sub[160];
hs_header_sub_encode(hdr, sub);

hs_blake2b_ctx ctx;
assert(hs_blake2b_init(&ctx, 32) == 0);
hs_blake2b_update(&ctx, sub, size);
hs_blake2b_update(&ctx, sub, 160);
assert(hs_blake2b_final(&ctx, hash, 32) == 0);
}

Expand Down
3 changes: 2 additions & 1 deletion src/simple.cc → src/simple_unix.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <unistd.h>
#ifndef _WIN32
#include <stdio.h>
#include <stdbool.h>
#include <pthread.h>
Expand Down Expand Up @@ -119,3 +119,4 @@ hs_simple_run(
}
return final_rc;
}
#endif
66 changes: 66 additions & 0 deletions src/simple_windows.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifdef _WIN32
#include <stdio.h>
#include <stdbool.h>
#include "common.h"
#include "header.h"
#include "error.h"
#include "utils.h"

int32_t
hs_simple_run(
hs_options_t *options,
uint32_t *result,
uint8_t *extra_nonce,
bool *match
) {
uint32_t nonce = 0;
uint32_t range = 1;
size_t header_len = options->header_len;
hs_header_t header[HEADER_SIZE];

if (options->nonce)
nonce = options->nonce;

if (options->range)
range = options->range;

uint32_t max = nonce + range;

if (header_len != HEADER_SIZE)
return HS_EBADARGS;

hs_header_decode(options->header, header_len, header);

uint8_t hash[32];
memset(hash, 0xff, 32);

uint8_t target[32];
memcpy(target, options->target, 32);

// Cache padding
uint8_t pad32[32];
hs_header_padding(header, pad32, 32);

// Compute share data
uint8_t share[128];
hs_header_share_encode(header, share);

for (; nonce < max; nonce++) {
if (!options->running)
break;

// Insert nonce into share
memcpy(share, &nonce, 4);

hs_header_share_pow(share, pad32, hash);

if (memcmp(hash, target, 32) <= 0) {
*match = true;
*result = nonce;
return HS_SUCCESS;
}
}

return HS_ENOSOLUTION;
}
#endif
1 change: 0 additions & 1 deletion src/verify.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <unistd.h>
#include <stdbool.h>
#include "common.h"
#include "header.h"
Expand Down