-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathmerkle_tree.go
More file actions
42 lines (33 loc) · 1.06 KB
/
merkle_tree.go
File metadata and controls
42 lines (33 loc) · 1.06 KB
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
package merkle_tree
/*
#cgo linux LDFLAGS: ${SRCDIR}/lib/libmerkle_tree.a -ldl -lrt -lm -lssl -lcrypto -Wl,--allow-multiple-definition
#cgo darwin LDFLAGS: ${SRCDIR}/lib/libmerkle_tree.dylib
#include "lib/merkle_tree.h"
*/
import "C"
import "unsafe"
import "fmt"
func VerifyMerkleTreeBatch(batchBuffer []byte, merkleRootBuffer [32]byte) (isVerified bool, err error) {
// Here we define the return value on failure
isVerified = false
err = nil
if len(batchBuffer) == 0 {
return isVerified, err
}
// This will catch any go panic
defer func() {
rec := recover()
if rec != nil {
err = fmt.Errorf("panic was caught while verifying merkle tree batch: %s", rec)
}
}()
batchPtr := (*C.uchar)(unsafe.Pointer(&batchBuffer[0]))
merkleRootPtr := (*C.uchar)(unsafe.Pointer(&merkleRootBuffer[0]))
r := (C.int32_t)(C.verify_merkle_tree_batch_ffi(batchPtr, (C.uint)(len(batchBuffer)), merkleRootPtr))
if r == -1 {
err = fmt.Errorf("panic happened on FFI while verifying merkle tree batch")
return isVerified, err
}
isVerified = (r == 1)
return isVerified, err
}