コード例 #1
0
func (m *CPPMerkleTree) CurrentRoot() ([]byte, error) {
	hash := make([]byte, m.nodeSize)
	success := C.CurrentRoot(m.peer, C.BYTE_SLICE(&hash))
	if !success {
		return nil, errors.New("failed to get current root")
	}
	return hash, nil
}
コード例 #2
0
// CurrentRoot returns the current root of the tree.
func (m *CPPMerkleTree) CurrentRoot() ([]byte, error) {
	hash := make([]byte, m.nodeSize)
	size := C.CurrentRoot(m.peer, unsafe.Pointer(&hash[0]), C.size_t(len(hash)))
	if got, want := size, m.nodeSize; got != want {
		return nil, fmt.Errorf("failed to get current root, got %d bytes, expected %d", got, want)
	}
	return hash, nil
}