func VerificationWitnessFromProto(vw *pb.VerificationWitness) (*VerificationWitness, error) {
	if vw.LastLevel > 255 {
		return nil, fmt.Errorf("LastLevel should be under 255")
	}
	witnesses := make([]chainhash.Hash, len(vw.WitnessHashes))
	for i := range witnesses {
		err := witnesses[i].SetBytes(vw.WitnessHashes[i])
		if err != nil {
			return nil, err
		}
	}
	out := &VerificationWitness{
		LastLevel: uint8(vw.LastLevel),
		Witnesses: witnesses,
	}
	err := out.Key.SetBytes(vw.Key)
	if err != nil {
		return nil, err
	}
	err = out.Value.SetBytes(vw.Value)
	if err != nil {
		return nil, err
	}
	err = out.WitnessBitfield.SetBytes(vw.WitnessBitfield)
	if err != nil {
		return nil, err
	}
	return out, nil
}
VerificationWitnessFromProto converts a protobuf representation of a verification witness.
package primitives
import (
	"fmt"
	"github.com/phoreproject/synapse/chainhash"
	"github.com/phoreproject/synapse/pb"
)
func CombineHashes(left *chainhash.Hash, right *chainhash.Hash) chainhash.Hash {
	return chainhash.HashH(append(left[:], right[:]...))
}
var EmptyTrees [256]chainhash.Hash
var EmptyTree = chainhash.Hash{}
func init() {
	EmptyTrees[0] = zeroHash
	for i := range EmptyTrees[1:] {
		EmptyTrees[i+1] = CombineHashes(&EmptyTrees[i], &EmptyTrees[i])
	}
	EmptyTree = EmptyTrees[255]
}
type UpdateWitness struct {
	Key             chainhash.Hash
	OldValue        chainhash.Hash
	NewValue        chainhash.Hash
	WitnessBitfield chainhash.Hash
	LastLevel       uint8
	Witnesses       []chainhash.Hash
}
func UpdateWitnessFromProto(uw *pb.UpdateWitness) (*UpdateWitness, error) {
	if uw.LastLevel > 255 {
		return nil, fmt.Errorf("expected LastLevel to be under 255")
	}
	witnesses := make([]chainhash.Hash, len(uw.WitnessHashes))
	for i := range witnesses {
		err := witnesses[i].SetBytes(uw.WitnessHashes[i])
		if err != nil {
			return nil, err
		}
	}
	out := &UpdateWitness{
		Witnesses: witnesses,
		LastLevel: uint8(uw.LastLevel),
	}
	err := out.Key.SetBytes(uw.Key)
	if err != nil {
		return nil, err
	}
	err = out.OldValue.SetBytes(uw.OldValue)
	if err != nil {
		return nil, err
	}
	err = out.NewValue.SetBytes(uw.NewValue)
	if err != nil {
		return nil, err
	}
	err = out.WitnessBitfield.SetBytes(uw.WitnessBitfield)
	if err != nil {
		return nil, err
	}
	return out, nil
}
func (uw *UpdateWitness) ToProto() *pb.UpdateWitness {
	out := &pb.UpdateWitness{
		Key: uw.Key[:],
		OldValue: uw.OldValue[:],
		NewValue: uw.NewValue[:],
		WitnessBitfield: uw.WitnessBitfield[:],
		LastLevel: uint32(uw.LastLevel),
		WitnessHashes: make([][]byte, len(uw.Witnesses)),
	}
	for i := range out.WitnessHashes {
		out.WitnessHashes[i] = uw.Witnesses[i][:]
	}
	return out
}
func (uw *UpdateWitness) Copy() UpdateWitness {
	newUw := *uw
	newUw.Witnesses = make([]chainhash.Hash, len(uw.Witnesses))
	for i := range newUw.Witnesses {
		copy(newUw.Witnesses[i][:], uw.Witnesses[i][:])
	}
	return newUw
}
type VerificationWitness struct {
	Key             chainhash.Hash
	Value           chainhash.Hash
	WitnessBitfield chainhash.Hash
	Witnesses       []chainhash.Hash
	LastLevel       uint8
}