-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I3d3c69e3a18e0c03e2a018534394d696333d7c37 Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
- Loading branch information
Showing
9 changed files
with
689 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,74 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ledger | ||
|
||
import "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" | ||
|
||
const ( | ||
minTargets = 1 | ||
maxTargets = 1 | ||
) | ||
|
||
// ClientOption describes a functional parameter for the New constructor | ||
type ClientOption func(*Client) error | ||
|
||
// WithDefaultTargetFilter option to configure new | ||
func WithDefaultTargetFilter(filter TargetFilter) ClientOption { | ||
return func(rmc *Client) error { | ||
rmc.filter = filter | ||
return nil | ||
} | ||
} | ||
|
||
//RequestOption func for each Opts argument | ||
type RequestOption func(opts *Opts) error | ||
|
||
// TargetFilter allows for filtering target peers | ||
type TargetFilter interface { | ||
// Accept returns true if peer should be included in the list of target peers | ||
Accept(peer fab.Peer) bool | ||
} | ||
|
||
//Opts contains options for operations performed by LedgerClient | ||
type Opts struct { | ||
Targets []fab.Peer // target peers | ||
TargetFilter TargetFilter // target filter | ||
MaxTargets int // maximum number of targets to select | ||
MinTargets int // min number of targets that have to respond with no error (or agree on result) | ||
} | ||
|
||
//WithTargets encapsulates fab.Peer targets to ledger RequestOption | ||
func WithTargets(targets ...fab.Peer) RequestOption { | ||
return func(opts *Opts) error { | ||
opts.Targets = targets | ||
return nil | ||
} | ||
} | ||
|
||
//WithTargetFilter encapsulates TargetFilter targets to ledger RequestOption | ||
func WithTargetFilter(targetFilter TargetFilter) RequestOption { | ||
return func(opts *Opts) error { | ||
opts.TargetFilter = targetFilter | ||
return nil | ||
} | ||
} | ||
|
||
//WithMaxTargets encapsulates max targets to ledger RequestOption | ||
func WithMaxTargets(maxTargets int) RequestOption { | ||
return func(opts *Opts) error { | ||
opts.MaxTargets = maxTargets | ||
return nil | ||
} | ||
} | ||
|
||
//WithMinTargets encapsulates min targets to ledger RequestOption | ||
func WithMinTargets(minTargets int) RequestOption { | ||
return func(opts *Opts) error { | ||
opts.MinTargets = minTargets | ||
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
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
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
Oops, something went wrong.