Skip to content

Commit

Permalink
[FAB-6314] Channel Client
Browse files Browse the repository at this point in the history
Change-Id: Iaa9bd6dd64c854124c040205f0f3c37cdcd308e7
Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask committed Sep 28, 2017
1 parent dd185dd commit f1c390e
Show file tree
Hide file tree
Showing 50 changed files with 2,159 additions and 472 deletions.
2 changes: 2 additions & 0 deletions api/apiconfig/configprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Config interface {
PeersConfig(org string) ([]PeerConfig, error)
PeerConfig(org string, name string) (*PeerConfig, error)
NetworkConfig() (*NetworkConfig, error)
ChannelConfig(name string) (*ChannelConfig, error)
ChannelPeers(name string) ([]ChannelPeer, error)
IsTLSEnabled() bool
SetTLSCACertPool(*x509.CertPool)
TLSCACertPool(tlsCertificate string) (*x509.CertPool, error)
Expand Down
256 changes: 142 additions & 114 deletions api/apiconfig/mocks/mockconfig.gen.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions api/apiconfig/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ type PeerChannelConfig struct {
EventSource bool
}

type ChannelPeer struct {
PeerChannelConfig
PeerConfig
}

type OrganizationConfig struct {
MspID string
CryptoPath string
Peers []string
CertificateAuthorities []string
AdminPrivateKey TLSConfig
Expand Down
46 changes: 24 additions & 22 deletions api/apifabca/mocks/mockfabriccaclient.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions api/apifabclient/credentialmgr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package apifabclient

import "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"

// SigningIdentity is the identity object that encapsulates the user's private key for signing
// and the user's enrollment certificate (identity)
type SigningIdentity struct {
MspID string
EnrollmentCert []byte
PrivateKey bccsp.Key
}

// CredentialManager retrieves user's signing identity
type CredentialManager interface {
GetSigningIdentity(name string) (*SigningIdentity, error)
}
17 changes: 17 additions & 0 deletions api/apifabclient/discoveryprovider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package apifabclient

// DiscoveryProvider is used to discover peers on the network
type DiscoveryProvider interface {
NewDiscoveryService(channel Channel) (DiscoveryService, error)
}

// DiscoveryService is used to discover eligible peers on specific channel
type DiscoveryService interface {
GetPeers(chaincodeID string) ([]Peer, error)
}
3 changes: 1 addition & 2 deletions api/apifabclient/fabricclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ type FabricClient interface {
SignChannelConfig(config []byte) (*common.ConfigSignature, error)
CreateChannel(request CreateChannelRequest) (txn.TransactionID, error)
QueryChannelInfo(name string, peers []Peer) (Channel, error)
SetStateStore(stateStore KeyValueStore)
StateStore() KeyValueStore
SetCryptoSuite(cryptoSuite bccsp.BCCSP)
SigningManager() SigningManager
CryptoSuite() bccsp.BCCSP
SaveUserToStateStore(user User, skipPersistence bool) error
LoadUserFromStateStore(name string) (User, error)
Expand Down
14 changes: 14 additions & 0 deletions api/apifabclient/signingmgr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package apifabclient

import "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"

// SigningManager signs object with provided key
type SigningManager interface {
Sign([]byte, bccsp.Key) ([]byte, error)
}
14 changes: 8 additions & 6 deletions api/apitxn/mocks/mockapitxn.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions api/apitxn/txn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package apitxn

import "time"

// QueryRequest contains the parameters for query
type QueryRequest struct {
ChaincodeID string
Fcn string
Args [][]byte
}

// QueryOpts allows the user to specify more advanced options
type QueryOpts struct {
Notifier chan QueryResponse // async
ProposalProcessors []ProposalProcessor // targets
Timeout time.Duration
}

// QueryResponse contains result of asynchronous call
type QueryResponse struct {
Response []byte
Error error
}

// ExecuteTxResponse contains result of asynchronous call
type ExecuteTxResponse struct {
Response TransactionID
Error error
}

// ExecuteTxRequest contains the parameters to execute transaction
type ExecuteTxRequest struct {
ChaincodeID string
Fcn string
Args [][]byte
TransientMap map[string][]byte
}

// ExecuteTxOpts allows the user to specify more advanced options
type ExecuteTxOpts struct {
Notifier chan ExecuteTxResponse // async
TxFilter ExecuteTxFilter
Timeout time.Duration
}

// ExecuteTxFilter allows the user to inspect/modify response before commit
type ExecuteTxFilter interface {
// process transaction proposal response (there will be no commit if an error is returned)
ProcessTxProposalResponse(txProposalResponse []*TransactionProposalResponse) ([]*TransactionProposalResponse, error)
}

// Registration is a handle that is returned from a successful Register Chaincode Event.
// This handle should be used in Unregister in order to unregister the event.
type Registration interface {
}

// CCEvent contains the data for a chaincocde event
type CCEvent struct {
TxID string
ChaincodeID string
EventName string
Payload []byte
}

// ChannelClient ...
/*
* A channel client instance provides a handler to interact with peers on specified channel.
* An application that requires interaction with multiple channels should create a separate
* instance of the channel client for each channel. Channel client supports non-admin functions only.
*
* Each Client instance maintains {@link Channel} instance representing channel and the associated
* private ledgers.
*
*/
type ChannelClient interface {

// Query chaincode
Query(request QueryRequest) ([]byte, error)

// QueryWithOpts allows the user to provide options for query (sync vs async, etc.)
QueryWithOpts(request QueryRequest, opt QueryOpts) ([]byte, error)

// ExecuteTx execute transaction
ExecuteTx(request ExecuteTxRequest) (TransactionID, error)

// ExecuteTxWithOpts allows the user to provide options for transaction execution (sync vs async, etc.)
ExecuteTxWithOpts(request ExecuteTxRequest, opt ExecuteTxOpts) (TransactionID, error)

// RegisterChaincodeEvent registers chain code event
// @param {chan bool} channel which receives event details when the event is complete
// @returns {object} object handle that should be used to unregister
RegisterChaincodeEvent(notify chan<- *CCEvent, chainCodeID string, eventID string) Registration

// UnregisterChaincodeEvent unregisters chain code event
UnregisterChaincodeEvent(registration Registration) error

// Close releases channel client resources (disconnects event hub etc.)
Close() error
}
2 changes: 2 additions & 0 deletions def/fabapi/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type SDK interface {
CryptoSuiteProvider() bccsp.BCCSP
StateStoreProvider() fab.KeyValueStore
ConfigProvider() apiconfig.Config
DiscoveryProvider() fab.DiscoveryProvider
SigningManager() fab.SigningManager
}

// Org represents the organization context
Expand Down
14 changes: 14 additions & 0 deletions def/fabapi/context/defprovider/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (

"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
fabca "github.com/hyperledger/fabric-sdk-go/api/apifabca"
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
fabricCAClient "github.com/hyperledger/fabric-sdk-go/pkg/fabric-ca-client"
credentialMgr "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/credentialmgr"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
)

// OrgClientFactory represents the default org provider factory.
Expand All @@ -32,3 +35,14 @@ func (f *OrgClientFactory) NewMSPClient(orgName string, config apiconfig.Config)

return mspClient, nil
}

// NewCredentialManager returns a new default implmentation of the credential manager
func (f *OrgClientFactory) NewCredentialManager(orgName string, config apiconfig.Config, cryptoProvider bccsp.BCCSP) (fab.CredentialManager, error) {

credentialMgr, err := credentialMgr.NewCredentialManager(orgName, config, cryptoProvider)
if err != nil {
return nil, fmt.Errorf("NewCredentialManager returned error: %v", err)
}

return credentialMgr, nil
}
Loading

0 comments on commit f1c390e

Please sign in to comment.