-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-4629] SDK Go - Change folder structure
Change-Id: I80435054e61226cb1efea65ca9a8460cb4473e83 Signed-off-by: Firas Qutishat <[email protected]>
- Loading branch information
Showing
61 changed files
with
2,091 additions
and
1,235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/msp" | ||
"github.com/hyperledger/fabric/protos/common" | ||
pb "github.com/hyperledger/fabric/protos/peer" | ||
) | ||
|
||
// Channel ... | ||
/** | ||
* Channel representing a Channel with which the client SDK interacts. | ||
* | ||
* The Channel object captures settings for a channel, which is created by | ||
* the orderers to isolate transactions delivery to peers participating on channel. | ||
* A channel must be initialized after it has been configured with the list of peers | ||
* and orderers. The initialization sends a get configuration block request to the | ||
* primary orderer to retrieve the configuration settings for this channel. | ||
*/ | ||
type Channel interface { | ||
GetName() string | ||
Initialize(data []byte) error | ||
IsSecurityEnabled() bool | ||
GetTCertBatchSize() int | ||
SetTCertBatchSize(batchSize int) | ||
AddPeer(peer Peer) error | ||
RemovePeer(peer Peer) | ||
GetPeers() []Peer | ||
GetAnchorPeers() []OrgAnchorPeer | ||
SetPrimaryPeer(peer Peer) error | ||
GetPrimaryPeer() Peer | ||
AddOrderer(orderer Orderer) error | ||
RemoveOrderer(orderer Orderer) | ||
GetOrderers() []Orderer | ||
SetMSPManager(mspManager msp.MSPManager) | ||
GetMSPManager() msp.MSPManager | ||
GetGenesisBlock(request *GenesisBlockRequest) (*common.Block, error) | ||
JoinChannel(request *JoinChannelRequest) ([]*TransactionProposalResponse, error) | ||
UpdateChannel() bool | ||
IsReadonly() bool | ||
QueryInfo() (*common.BlockchainInfo, error) | ||
QueryBlock(blockNumber int) (*common.Block, error) | ||
QueryBlockByHash(blockHash []byte) (*common.Block, error) | ||
QueryTransaction(transactionID string) (*pb.ProcessedTransaction, error) | ||
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error) | ||
QueryByChaincode(chaincodeName string, args []string, targets []Peer) ([][]byte, error) | ||
CreateTransactionProposal(chaincodeName string, channelID string, args []string, sign bool, transientData map[string][]byte) (*TransactionProposal, error) | ||
SendTransactionProposal(proposal *TransactionProposal, retry int, targets []Peer) ([]*TransactionProposalResponse, error) | ||
CreateTransaction(resps []*TransactionProposalResponse) (*Transaction, error) | ||
SendTransaction(tx *Transaction) ([]*TransactionResponse, error) | ||
SendInstantiateProposal(chaincodeName string, channelID string, args []string, chaincodePath string, chaincodeVersion string, targets []Peer) ([]*TransactionProposalResponse, string, error) | ||
GetOrganizationUnits() ([]string, error) | ||
QueryExtensionInterface() ChannelExtension | ||
LoadConfigUpdateEnvelope(data []byte) error | ||
} | ||
|
||
// The ChannelExtension interface allows extensions of the SDK to add functionality to Channel overloads. | ||
type ChannelExtension interface { | ||
GetClientContext() FabricClient | ||
|
||
SignPayload(payload []byte) (*SignedEnvelope, error) | ||
BroadcastEnvelope(envelope *SignedEnvelope) ([]*TransactionResponse, error) | ||
|
||
// TODO: This should go somewhere else - see TransactionProposal.GetBytes(). - deprecated | ||
GetProposalBytes(tp *TransactionProposal) ([]byte, error) | ||
} | ||
|
||
// OrgAnchorPeer contains information about an anchor peer on this channel | ||
type OrgAnchorPeer struct { | ||
Org string | ||
Host string | ||
Port int32 | ||
} | ||
|
||
// GenesisBlockRequest ... | ||
type GenesisBlockRequest struct { | ||
TxID string | ||
Nonce []byte | ||
} | ||
|
||
// The TransactionProposal object to be send to the endorsers | ||
type TransactionProposal struct { | ||
TransactionID string | ||
|
||
SignedProposal *pb.SignedProposal | ||
Proposal *pb.Proposal | ||
} | ||
|
||
// TransactionProposalResponse ... | ||
/** | ||
* The TransactionProposalResponse result object returned from endorsers. | ||
*/ | ||
type TransactionProposalResponse struct { | ||
Endorser string | ||
Err error | ||
Status int32 | ||
|
||
Proposal *TransactionProposal | ||
ProposalResponse *pb.ProposalResponse | ||
} | ||
|
||
// JoinChannelRequest allows a set of peers to transact on a channel on the network | ||
type JoinChannelRequest struct { | ||
Targets []Peer | ||
GenesisBlock *common.Block | ||
TxID string | ||
Nonce []byte | ||
} | ||
|
||
// The Transaction object created from an endorsed proposal | ||
type Transaction struct { | ||
Proposal *TransactionProposal | ||
Transaction *pb.Transaction | ||
} | ||
|
||
// TransactionResponse ... | ||
/** | ||
* The TransactionProposalResponse result object returned from orderers. | ||
*/ | ||
type TransactionResponse struct { | ||
Orderer string | ||
Err error | ||
} |
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,56 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"crypto/x509" | ||
|
||
bccspFactory "github.com/hyperledger/fabric/bccsp/factory" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// Config ... | ||
type Config interface { | ||
GetServerURL() string | ||
GetServerCertFiles() []string | ||
GetFabricCAClientKeyFile() string | ||
GetFabricCAClientCertFile() string | ||
GetFabricCATLSEnabledFlag() bool | ||
GetFabricClientViper() *viper.Viper | ||
GetPeersConfig() ([]PeerConfig, error) | ||
IsTLSEnabled() bool | ||
GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error) | ||
GetTLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error) | ||
IsSecurityEnabled() bool | ||
TcertBatchSize() int | ||
GetSecurityAlgorithm() string | ||
GetSecurityLevel() int | ||
GetOrdererHost() string | ||
GetOrdererPort() string | ||
GetOrdererTLSServerHostOverride() string | ||
GetOrdererTLSCertificate() string | ||
GetFabricCAID() string | ||
GetFabricCAName() string | ||
GetKeyStorePath() string | ||
GetFabricCAHomeDir() string | ||
GetFabricCAMspDir() string | ||
GetCryptoConfigPath() string | ||
GetCSPConfig() *bccspFactory.FactoryOpts | ||
} | ||
|
||
// PeerConfig A set of configurations required to connect to a Fabric peer | ||
type PeerConfig struct { | ||
Host string | ||
Port int | ||
EventHost string | ||
EventPort int | ||
Primary bool | ||
TLS struct { | ||
Certificate string | ||
ServerHostOverride string | ||
} | ||
} |
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,65 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
common "github.com/hyperledger/fabric/protos/common" | ||
ehpb "github.com/hyperledger/fabric/protos/peer" | ||
pb "github.com/hyperledger/fabric/protos/peer" | ||
) | ||
|
||
// EventHub ... | ||
type EventHub interface { | ||
SetPeerAddr(peerURL string, certificate string, serverHostOverride string) | ||
IsConnected() bool | ||
Connect() error | ||
Disconnect() | ||
RegisterChaincodeEvent(ccid string, eventname string, callback func(*ChaincodeEvent)) *ChainCodeCBE | ||
UnregisterChaincodeEvent(cbe *ChainCodeCBE) | ||
RegisterTxEvent(txID string, callback func(string, pb.TxValidationCode, error)) | ||
UnregisterTxEvent(txID string) | ||
RegisterBlockEvent(callback func(*common.Block)) | ||
UnregisterBlockEvent(callback func(*common.Block)) | ||
} | ||
|
||
//EventsClient holds the stream and adapter for consumer to work with | ||
type EventsClient interface { | ||
RegisterAsync(ies []*ehpb.Interest) error | ||
UnregisterAsync(ies []*ehpb.Interest) error | ||
Unregister(ies []*ehpb.Interest) error | ||
Recv() (*ehpb.Event, error) | ||
Start() error | ||
Stop() error | ||
} | ||
|
||
// The EventHubExt interface allows extensions of the SDK to add functionality to EventHub overloads. | ||
type EventHubExt interface { | ||
SetInterests(block bool) | ||
} | ||
|
||
// ChainCodeCBE ... | ||
/** | ||
* The ChainCodeCBE is used internal to the EventHub to hold chaincode | ||
* event registration callbacks. | ||
*/ | ||
type ChainCodeCBE struct { | ||
// chaincode id | ||
CCID string | ||
// event name regex filter | ||
EventNameFilter string | ||
// callback function to invoke on successful filter match | ||
CallbackFunc func(*ChaincodeEvent) | ||
} | ||
|
||
// ChaincodeEvent contains the current event data for the event handler | ||
type ChaincodeEvent struct { | ||
ChaincodeID string | ||
TxID string | ||
EventName string | ||
Payload []byte | ||
ChannelID string | ||
} |
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,78 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/bccsp" | ||
"github.com/hyperledger/fabric/protos/common" | ||
pb "github.com/hyperledger/fabric/protos/peer" | ||
) | ||
|
||
// FabricClient ... | ||
/* | ||
* Main interaction handler with end user. A client instance provides a handler to interact | ||
* with a network of peers, orderers and optionally member services. An application using the | ||
* SDK may need to interact with multiple networks, each through a separate instance of the Client. | ||
* | ||
* Each client when initially created should be initialized with configuration data from the | ||
* consensus service, which includes a list of trusted roots, orderer certificates and IP addresses, | ||
* and a list of peer certificates and IP addresses that it can access. This must be done out of band | ||
* as part of bootstrapping the application environment. It is also the responsibility of the application | ||
* to maintain the configuration of a client as the SDK does not persist this object. | ||
* | ||
* Each Client instance can maintain several {@link Channel} instances representing channels and the associated | ||
* private ledgers. | ||
* | ||
* | ||
*/ | ||
type FabricClient interface { | ||
NewChannel(name string) (Channel, error) | ||
GetChannel(name string) Channel | ||
ExtractChannelConfig(configEnvelope []byte) ([]byte, error) | ||
SignChannelConfig(config []byte) (*common.ConfigSignature, error) | ||
CreateChannel(request *CreateChannelRequest) error | ||
QueryChannelInfo(name string, peers []Peer) (Channel, error) | ||
SetStateStore(stateStore KeyValueStore) | ||
GetStateStore() KeyValueStore | ||
SetCryptoSuite(cryptoSuite bccsp.BCCSP) | ||
GetCryptoSuite() bccsp.BCCSP | ||
SaveUserToStateStore(user User, skipPersistence bool) error | ||
LoadUserFromStateStore(name string) (User, error) | ||
InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*TransactionProposalResponse, string, error) | ||
QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error) | ||
QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error) | ||
GetIdentity() ([]byte, error) | ||
GetUserContext() User | ||
SetUserContext(user User) | ||
GetConfig() Config | ||
} | ||
|
||
// CreateChannelRequest requests channel creation on the network | ||
type CreateChannelRequest struct { | ||
// required - The name of the new channel | ||
Name string | ||
// required - The Orderer to send the update request | ||
Orderer Orderer | ||
// optional - the envelope object containing all | ||
// required settings and signatures to initialize this channel. | ||
// This envelope would have been created by the command | ||
// line tool "configtx" | ||
Envelope []byte | ||
// optional - ConfigUpdate object built by the | ||
// buildChannelConfig() method of this package | ||
Config []byte | ||
// optional - the list of collected signatures | ||
// required by the channel create policy when using the `config` parameter. | ||
// see signChannelConfig() method of this package | ||
Signatures []*common.ConfigSignature | ||
// optional - transaction ID | ||
// required when using the `config` parameter | ||
TxID string | ||
// optional - nonce | ||
// required when using the `config` parameter | ||
Nonce []byte | ||
} |
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.