// needProof: whether proof needed
// ptype: proof type if needProof==true
// If the child node is to be proved, then the index is a non-negative number and must not be
// greater than 15, which is used to indicate that the value of the corresponding index of
// ChildHashs is the target value to be prooved.
whether proof needed
ptype: proof type if needProof==true
If the child node is to be proved, then the index is a non-negative number and must not be
greater than 15, which is used to indicate that the value of the corresponding index of
ChildHashs is the target value to be prooved.
// needProof : whether proof needed // ptype : proof type if needProof == true // If the child node is to be proved then the index is a non - negative number and must not be // greater than 15 which is used to indicate that the value of the corresponding index of // ChildHashs is the target value to be prooved .
func (h *NodeHasher) MakeProof(needProof bool, ptype ProofType, index int) (nodeHash []byte, nodeProof *NodeProof, err error) {
	headerHash, err := h.Header.HashValue()
	if err != nil {
		return nil, nil, err
	}
	valueHash := common.NilHashSlice
	if h.ValueHash != nil {
		valueHash = h.ValueHash[:]
	}
	left := common.HashPair(headerHash, valueHash)
	var childProof *common.MerkleProofs
	if h.Header.HasChildren() {
		var right []byte
		if !needProof {
			right, err = common.MerkleHashComplete(h.ChildHashs, -1, nil)
		} else {
			childProof = common.NewMerkleProofs()
			right, err = common.MerkleHashComplete(h.ChildHashs, index, childProof)
		}
		if err != nil {
			return nil, nil, err
		}
		left = common.HashPair(left, right)
	}
	if needProof {
		nodeProof = NewNodeProof(ptype, h.Header, h.ValueHash, childProof)
	} else {
		nodeProof = nil
	}
	return left, nodeProof, nil
}
func ( h * NodeHasher ) MakeProof ( needProof bool , ptype ProofType , index int ) ( nodeHash [ ] byte , nodeProof * NodeProof , err error ) { headerHash , err := h . Header . HashValue ( ) if err != nil { return nil , nil , err } valueHash := common . NilHashSlice if h . ValueHash != nil { valueHash = h . ValueHash [ : ] } left := common . HashPair ( headerHash , valueHash ) var childProof * common . MerkleProofs if h . Header . HasChildren ( ) { var right [ ] byte if ! needProof { right , err = common . MerkleHashComplete ( h . ChildHashs , - 1 , nil ) } else { childProof = common . NewMerkleProofs ( ) right , err = common . MerkleHashComplete ( h . ChildHashs , index , childProof ) } if err != nil { return nil , nil , err } left = common . HashPair ( left , right ) } if needProof { nodeProof = NewNodeProof ( ptype , h . Header , h . ValueHash , childProof ) } else { nodeProof = nil } return left , nodeProof , nil }
whether proof needed
ptype: proof type if needProof==true
If the child node is to be proved, then the index is a non-negative number and must not be
greater than 15, which is used to indicate that the value of the corresponding index of
ChildHashs is the target value to be prooved.
whether proof needed ptype : proof type if needProof == true If the child node is to be proved then the index is a non - negative number and must not be greater than 15 which is used to indicate that the value of the corresponding index of ChildHashs is the target value to be prooved .