-
Notifications
You must be signed in to change notification settings - Fork 0
/
batchmerkleproof.go
48 lines (40 loc) · 1.05 KB
/
batchmerkleproof.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
package ergo
/*
#include "ergo.h"
*/
import "C"
import (
"runtime"
"unsafe"
)
type BatchMerkleProof interface {
Valid(expectedRoot []byte) bool
}
type batchMerkleProof struct {
p C.BatchMerkleProofPtr
}
func newBatchMerkleProof(b *batchMerkleProof) BatchMerkleProof {
runtime.SetFinalizer(b, finalizeBatchMerkleProof)
return b
}
func NewBatchMerkleProof(json string) (BatchMerkleProof, error) {
jsonStr := C.CString(json)
defer C.free(unsafe.Pointer(jsonStr))
var p C.BatchMerkleProofPtr
errPtr := C.ergo_lib_batch_merkle_proof_from_json(jsonStr, &p)
err := newError(errPtr)
if err.isError() {
return nil, err.error()
}
b := &batchMerkleProof{p: p}
return newBatchMerkleProof(b), nil
}
func (b *batchMerkleProof) Valid(expectedRoot []byte) bool {
byteData := C.CBytes(expectedRoot)
defer C.free(unsafe.Pointer(byteData))
res := C.ergo_lib_batch_merkle_proof_valid(b.p, (*C.uchar)(byteData), C.uintptr_t(len(expectedRoot)))
return bool(res)
}
func finalizeBatchMerkleProof(b *batchMerkleProof) {
C.ergo_lib_batch_merkle_proof_delete(b.p)
}