-
Notifications
You must be signed in to change notification settings - Fork 44
/
cpu_helper_for_node.go
60 lines (53 loc) · 1.58 KB
/
cpu_helper_for_node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package plugins
/*
#cgo LDFLAGS: -L../../../solution -lcpuminer -lstdc++
#cgo CFLAGS: -I./
#include "../../../solution/verify.h"
*/
import "C"
import (
// "fmt"
// "time"
"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/core/types"
//"github.com/CortexFoundation/CortexTheseus/log"
"math/big"
"unsafe"
)
//func CuckooInit(threads uint32) {
// CuckooInitialize(0, "", "cuckaroo")
//}
//func CuckooInitialize(threads int, strDeviceIds string, algorithm string) error {
// var deviceNum int = 1
// var devices []uint32
// var selected int = 1
// devices = append(devices, 0)
// C.CuckooInitializeCPU((*C.uint32_t)(unsafe.Pointer(&devices[0])), C.uint32_t(threads), C.int(selected), 0)
// return nil
//}
//func CuckooFinalize() {
// log.Debug("CuckooFinalize")
// C.CuckooFinalizeCPU()
//}
//func CuckooVerify(hash *byte, nonce uint64, result types.BlockSolution, result_sha3 []byte, diff *big.Int) bool {
// sha3hash := common.BytesToHash(result_sha3)
// if sha3hash.Big().Cmp(diff) <= 0 {
// r := C.CuckooVerifyProof(
// (*C.uint8_t)(unsafe.Pointer(hash)),
// C.uint64_t(nonce),
// (*C.result_t)(unsafe.Pointer(&result[0])))
// return (r == 1)
// }
// return false
//}
func CuckooVerify_cuckaroo(hash *byte, nonce uint64, result types.BlockSolution, result_sha3 []byte, diff *big.Int) bool {
sha3hash := common.BytesToHash(result_sha3)
if sha3hash.Big().Cmp(diff) <= 0 {
r := C.CuckooVerifyProof_cuckaroo(
(*C.uint8_t)(unsafe.Pointer(hash)),
C.uint64_t(nonce),
(*C.result_t)(unsafe.Pointer(&result[0])))
return (r == 1)
}
return false
}