github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/protos/ledger/rwset/kvrwset/helper.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kvrwset
    18  
    19  import (
    20  	"bytes"
    21  )
    22  
    23  // SetRawReads sets the 'readsInfo' field to raw KVReads performed by the query
    24  func (rqi *RangeQueryInfo) SetRawReads(kvReads []*KVRead) {
    25  	rqi.ReadsInfo = &RangeQueryInfo_RawReads{&QueryReads{kvReads}}
    26  }
    27  
    28  // SetMerkelSummary sets the 'readsInfo' field to merkle summary of the raw KVReads of query results
    29  func (rqi *RangeQueryInfo) SetMerkelSummary(merkleSummary *QueryReadsMerkleSummary) {
    30  	rqi.ReadsInfo = &RangeQueryInfo_ReadsMerkleHashes{merkleSummary}
    31  }
    32  
    33  // Equal verifies whether the give MerkleSummary is equals to this
    34  func (ms *QueryReadsMerkleSummary) Equal(anotherMS *QueryReadsMerkleSummary) bool {
    35  	if anotherMS == nil {
    36  		return false
    37  	}
    38  	if ms.MaxDegree != anotherMS.MaxDegree ||
    39  		ms.MaxLevel != anotherMS.MaxLevel ||
    40  		len(ms.MaxLevelHashes) != len(anotherMS.MaxLevelHashes) {
    41  		return false
    42  	}
    43  	for i := 0; i < len(ms.MaxLevelHashes); i++ {
    44  		if !bytes.Equal(ms.MaxLevelHashes[i], anotherMS.MaxLevelHashes[i]) {
    45  			return false
    46  		}
    47  	}
    48  	return true
    49  }