-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-8941]- extract matching logic from queryconfig
Extract Matching logic out of query configblock Change-Id: I6e5a748bbc63751053c6a41c9d8d999d0e40f7bd Signed-off-by: Pavan Kappara <pavan.kappara@securekey.com>
- Loading branch information
Pavan Kappara
committed
Mar 16, 2018
1 parent
ec23384
commit 6763ec7
Showing
4 changed files
with
85 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package channel | ||
|
||
import ( | ||
"github.com/golang/protobuf/proto" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// TransactionProposalResponseVerifier struct is for verifying TransactionProposalResponse and matches config blocks | ||
type TransactionProposalResponseVerifier struct { | ||
MinResponses int | ||
} | ||
|
||
// Verify checks transaction proposal response (empty) | ||
func (tprv *TransactionProposalResponseVerifier) Verify(response *fab.TransactionProposalResponse) error { | ||
return nil | ||
} | ||
|
||
// Match verifies and matches transaction proposal responses | ||
func (tprv *TransactionProposalResponseVerifier) Match(transactionProposalResponses []*fab.TransactionProposalResponse) error { | ||
if tprv.MinResponses <= 0 { | ||
return errors.New("minimum Responses has to be greater than zero") | ||
} | ||
|
||
if len(transactionProposalResponses) < tprv.MinResponses { | ||
return errors.Errorf("required minimum %d endorsments got %d", tprv.MinResponses, len(transactionProposalResponses)) | ||
} | ||
|
||
block, err := createCommonBlock(transactionProposalResponses[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if block.Data == nil || block.Data.Data == nil { | ||
return errors.New("config block data is nil") | ||
} | ||
|
||
if len(block.Data.Data) != 1 { | ||
return errors.New("config block must contain one transaction") | ||
} | ||
|
||
// Compare block data from remaining responses | ||
for _, tpr := range transactionProposalResponses[1:] { | ||
b, err := createCommonBlock(tpr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !proto.Equal(block.Data, b.Data) { | ||
return errors.New("payloads for config block do not match") | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters