mirror of
https://github.com/cryptonote-social/csminer.git
synced 2024-09-17 16:57:38 +03:00
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
// Copyright 2020 cryptonote.social. All rights reserved. Use of this source code is governed by
|
|
// the license found in the LICENSE file.
|
|
|
|
// Package rx provides Go access to various randomx library methods.
|
|
package rx
|
|
|
|
// #cgo CFLAGS: -std=c11 -D_GNU_SOURCE -m64 -O3 -I${SRCDIR}/../../rxlib/
|
|
// #cgo LDFLAGS: -L${SRCDIR}/../../rxlib/ -Wl,-rpath,$ORIGIN ${SRCDIR}/../../rxlib/rxlib.cpp.o -lrandomx -lstdc++ -lm
|
|
/*
|
|
#include <stdlib.h>
|
|
#include "rxlib.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"github.com/cryptonote-social/csminer/crylog"
|
|
// "encoding/hex"
|
|
"unsafe"
|
|
)
|
|
|
|
// Call this every time the seed hash provided by the daemon changes before performing any hashing.
|
|
// return values:
|
|
// 1: success
|
|
// 2: success, but no huge pages.
|
|
// -1: unexpected failure
|
|
func InitRX(seedHash []byte, threads int, initThreads int) int {
|
|
if len(seedHash) == 0 {
|
|
crylog.Error("Bad seed hash:", seedHash)
|
|
return -1
|
|
}
|
|
i := C.init_rxlib(
|
|
(*C.char)(unsafe.Pointer(&seedHash[0])),
|
|
(C.uint32_t)(len(seedHash)),
|
|
(C.int)(threads),
|
|
(C.int)(initThreads))
|
|
return int(i)
|
|
}
|
|
|
|
func HashUntil(blob []byte, difficulty uint64, thread int, hash []byte, nonce []byte, stopper *uint32) int64 {
|
|
res := C.rx_hash_until(
|
|
(*C.char)(unsafe.Pointer(&blob[0])),
|
|
(C.uint32_t)(len(blob)),
|
|
(C.uint64_t)(difficulty),
|
|
(C.int)(thread),
|
|
(*C.char)(unsafe.Pointer(&hash[0])),
|
|
(*C.char)(unsafe.Pointer(&nonce[0])),
|
|
(*C.uint32_t)(unsafe.Pointer(stopper)))
|
|
return int64(res)
|
|
}
|
|
|
|
// only call when all existing threads are stopped
|
|
func AddThread() int {
|
|
res := C.rx_add_thread()
|
|
return int(res)
|
|
}
|
|
|
|
// only call when all existing threads are stopped
|
|
func RemoveThread() int {
|
|
res := C.rx_remove_thread()
|
|
return int(res)
|
|
}
|