Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit dafbe28

Browse files
author
Firas Qutishat
committed
[FAB-4629] SDK Go - Change folder structure
Change-Id: I80435054e61226cb1efea65ca9a8460cb4473e83 Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
1 parent 4cb70e8 commit dafbe28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2091
-1235
lines changed

api/channel.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package api
8+
9+
import (
10+
"github.com/hyperledger/fabric/msp"
11+
"github.com/hyperledger/fabric/protos/common"
12+
pb "github.com/hyperledger/fabric/protos/peer"
13+
)
14+
15+
// Channel ...
16+
/**
17+
* Channel representing a Channel with which the client SDK interacts.
18+
*
19+
* The Channel object captures settings for a channel, which is created by
20+
* the orderers to isolate transactions delivery to peers participating on channel.
21+
* A channel must be initialized after it has been configured with the list of peers
22+
* and orderers. The initialization sends a get configuration block request to the
23+
* primary orderer to retrieve the configuration settings for this channel.
24+
*/
25+
type Channel interface {
26+
GetName() string
27+
Initialize(data []byte) error
28+
IsSecurityEnabled() bool
29+
GetTCertBatchSize() int
30+
SetTCertBatchSize(batchSize int)
31+
AddPeer(peer Peer) error
32+
RemovePeer(peer Peer)
33+
GetPeers() []Peer
34+
GetAnchorPeers() []OrgAnchorPeer
35+
SetPrimaryPeer(peer Peer) error
36+
GetPrimaryPeer() Peer
37+
AddOrderer(orderer Orderer) error
38+
RemoveOrderer(orderer Orderer)
39+
GetOrderers() []Orderer
40+
SetMSPManager(mspManager msp.MSPManager)
41+
GetMSPManager() msp.MSPManager
42+
GetGenesisBlock(request *GenesisBlockRequest) (*common.Block, error)
43+
JoinChannel(request *JoinChannelRequest) ([]*TransactionProposalResponse, error)
44+
UpdateChannel() bool
45+
IsReadonly() bool
46+
QueryInfo() (*common.BlockchainInfo, error)
47+
QueryBlock(blockNumber int) (*common.Block, error)
48+
QueryBlockByHash(blockHash []byte) (*common.Block, error)
49+
QueryTransaction(transactionID string) (*pb.ProcessedTransaction, error)
50+
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
51+
QueryByChaincode(chaincodeName string, args []string, targets []Peer) ([][]byte, error)
52+
CreateTransactionProposal(chaincodeName string, channelID string, args []string, sign bool, transientData map[string][]byte) (*TransactionProposal, error)
53+
SendTransactionProposal(proposal *TransactionProposal, retry int, targets []Peer) ([]*TransactionProposalResponse, error)
54+
CreateTransaction(resps []*TransactionProposalResponse) (*Transaction, error)
55+
SendTransaction(tx *Transaction) ([]*TransactionResponse, error)
56+
SendInstantiateProposal(chaincodeName string, channelID string, args []string, chaincodePath string, chaincodeVersion string, targets []Peer) ([]*TransactionProposalResponse, string, error)
57+
GetOrganizationUnits() ([]string, error)
58+
QueryExtensionInterface() ChannelExtension
59+
LoadConfigUpdateEnvelope(data []byte) error
60+
}
61+
62+
// The ChannelExtension interface allows extensions of the SDK to add functionality to Channel overloads.
63+
type ChannelExtension interface {
64+
GetClientContext() FabricClient
65+
66+
SignPayload(payload []byte) (*SignedEnvelope, error)
67+
BroadcastEnvelope(envelope *SignedEnvelope) ([]*TransactionResponse, error)
68+
69+
// TODO: This should go somewhere else - see TransactionProposal.GetBytes(). - deprecated
70+
GetProposalBytes(tp *TransactionProposal) ([]byte, error)
71+
}
72+
73+
// OrgAnchorPeer contains information about an anchor peer on this channel
74+
type OrgAnchorPeer struct {
75+
Org string
76+
Host string
77+
Port int32
78+
}
79+
80+
// GenesisBlockRequest ...
81+
type GenesisBlockRequest struct {
82+
TxID string
83+
Nonce []byte
84+
}
85+
86+
// The TransactionProposal object to be send to the endorsers
87+
type TransactionProposal struct {
88+
TransactionID string
89+
90+
SignedProposal *pb.SignedProposal
91+
Proposal *pb.Proposal
92+
}
93+
94+
// TransactionProposalResponse ...
95+
/**
96+
* The TransactionProposalResponse result object returned from endorsers.
97+
*/
98+
type TransactionProposalResponse struct {
99+
Endorser string
100+
Err error
101+
Status int32
102+
103+
Proposal *TransactionProposal
104+
ProposalResponse *pb.ProposalResponse
105+
}
106+
107+
// JoinChannelRequest allows a set of peers to transact on a channel on the network
108+
type JoinChannelRequest struct {
109+
Targets []Peer
110+
GenesisBlock *common.Block
111+
TxID string
112+
Nonce []byte
113+
}
114+
115+
// The Transaction object created from an endorsed proposal
116+
type Transaction struct {
117+
Proposal *TransactionProposal
118+
Transaction *pb.Transaction
119+
}
120+
121+
// TransactionResponse ...
122+
/**
123+
* The TransactionProposalResponse result object returned from orderers.
124+
*/
125+
type TransactionResponse struct {
126+
Orderer string
127+
Err error
128+
}

api/config.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package api
8+
9+
import (
10+
"crypto/x509"
11+
12+
bccspFactory "github.com/hyperledger/fabric/bccsp/factory"
13+
"github.com/spf13/viper"
14+
)
15+
16+
// Config ...
17+
type Config interface {
18+
GetServerURL() string
19+
GetServerCertFiles() []string
20+
GetFabricCAClientKeyFile() string
21+
GetFabricCAClientCertFile() string
22+
GetFabricCATLSEnabledFlag() bool
23+
GetFabricClientViper() *viper.Viper
24+
GetPeersConfig() ([]PeerConfig, error)
25+
IsTLSEnabled() bool
26+
GetTLSCACertPool(tlsCertificate string) (*x509.CertPool, error)
27+
GetTLSCACertPoolFromRoots(ordererRootCAs [][]byte) (*x509.CertPool, error)
28+
IsSecurityEnabled() bool
29+
TcertBatchSize() int
30+
GetSecurityAlgorithm() string
31+
GetSecurityLevel() int
32+
GetOrdererHost() string
33+
GetOrdererPort() string
34+
GetOrdererTLSServerHostOverride() string
35+
GetOrdererTLSCertificate() string
36+
GetFabricCAID() string
37+
GetFabricCAName() string
38+
GetKeyStorePath() string
39+
GetFabricCAHomeDir() string
40+
GetFabricCAMspDir() string
41+
GetCryptoConfigPath() string
42+
GetCSPConfig() *bccspFactory.FactoryOpts
43+
}
44+
45+
// PeerConfig A set of configurations required to connect to a Fabric peer
46+
type PeerConfig struct {
47+
Host string
48+
Port int
49+
EventHost string
50+
EventPort int
51+
Primary bool
52+
TLS struct {
53+
Certificate string
54+
ServerHostOverride string
55+
}
56+
}

api/event.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package api
8+
9+
import (
10+
common "github.com/hyperledger/fabric/protos/common"
11+
ehpb "github.com/hyperledger/fabric/protos/peer"
12+
pb "github.com/hyperledger/fabric/protos/peer"
13+
)
14+
15+
// EventHub ...
16+
type EventHub interface {
17+
SetPeerAddr(peerURL string, certificate string, serverHostOverride string)
18+
IsConnected() bool
19+
Connect() error
20+
Disconnect()
21+
RegisterChaincodeEvent(ccid string, eventname string, callback func(*ChaincodeEvent)) *ChainCodeCBE
22+
UnregisterChaincodeEvent(cbe *ChainCodeCBE)
23+
RegisterTxEvent(txID string, callback func(string, pb.TxValidationCode, error))
24+
UnregisterTxEvent(txID string)
25+
RegisterBlockEvent(callback func(*common.Block))
26+
UnregisterBlockEvent(callback func(*common.Block))
27+
}
28+
29+
//EventsClient holds the stream and adapter for consumer to work with
30+
type EventsClient interface {
31+
RegisterAsync(ies []*ehpb.Interest) error
32+
UnregisterAsync(ies []*ehpb.Interest) error
33+
Unregister(ies []*ehpb.Interest) error
34+
Recv() (*ehpb.Event, error)
35+
Start() error
36+
Stop() error
37+
}
38+
39+
// The EventHubExt interface allows extensions of the SDK to add functionality to EventHub overloads.
40+
type EventHubExt interface {
41+
SetInterests(block bool)
42+
}
43+
44+
// ChainCodeCBE ...
45+
/**
46+
* The ChainCodeCBE is used internal to the EventHub to hold chaincode
47+
* event registration callbacks.
48+
*/
49+
type ChainCodeCBE struct {
50+
// chaincode id
51+
CCID string
52+
// event name regex filter
53+
EventNameFilter string
54+
// callback function to invoke on successful filter match
55+
CallbackFunc func(*ChaincodeEvent)
56+
}
57+
58+
// ChaincodeEvent contains the current event data for the event handler
59+
type ChaincodeEvent struct {
60+
ChaincodeID string
61+
TxID string
62+
EventName string
63+
Payload []byte
64+
ChannelID string
65+
}

api/fabricclient.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package api
8+
9+
import (
10+
"github.com/hyperledger/fabric/bccsp"
11+
"github.com/hyperledger/fabric/protos/common"
12+
pb "github.com/hyperledger/fabric/protos/peer"
13+
)
14+
15+
// FabricClient ...
16+
/*
17+
* Main interaction handler with end user. A client instance provides a handler to interact
18+
* with a network of peers, orderers and optionally member services. An application using the
19+
* SDK may need to interact with multiple networks, each through a separate instance of the Client.
20+
*
21+
* Each client when initially created should be initialized with configuration data from the
22+
* consensus service, which includes a list of trusted roots, orderer certificates and IP addresses,
23+
* and a list of peer certificates and IP addresses that it can access. This must be done out of band
24+
* as part of bootstrapping the application environment. It is also the responsibility of the application
25+
* to maintain the configuration of a client as the SDK does not persist this object.
26+
*
27+
* Each Client instance can maintain several {@link Channel} instances representing channels and the associated
28+
* private ledgers.
29+
*
30+
*
31+
*/
32+
type FabricClient interface {
33+
NewChannel(name string) (Channel, error)
34+
GetChannel(name string) Channel
35+
ExtractChannelConfig(configEnvelope []byte) ([]byte, error)
36+
SignChannelConfig(config []byte) (*common.ConfigSignature, error)
37+
CreateChannel(request *CreateChannelRequest) error
38+
QueryChannelInfo(name string, peers []Peer) (Channel, error)
39+
SetStateStore(stateStore KeyValueStore)
40+
GetStateStore() KeyValueStore
41+
SetCryptoSuite(cryptoSuite bccsp.BCCSP)
42+
GetCryptoSuite() bccsp.BCCSP
43+
SaveUserToStateStore(user User, skipPersistence bool) error
44+
LoadUserFromStateStore(name string) (User, error)
45+
InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*TransactionProposalResponse, string, error)
46+
QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error)
47+
QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error)
48+
GetIdentity() ([]byte, error)
49+
GetUserContext() User
50+
SetUserContext(user User)
51+
GetConfig() Config
52+
}
53+
54+
// CreateChannelRequest requests channel creation on the network
55+
type CreateChannelRequest struct {
56+
// required - The name of the new channel
57+
Name string
58+
// required - The Orderer to send the update request
59+
Orderer Orderer
60+
// optional - the envelope object containing all
61+
// required settings and signatures to initialize this channel.
62+
// This envelope would have been created by the command
63+
// line tool "configtx"
64+
Envelope []byte
65+
// optional - ConfigUpdate object built by the
66+
// buildChannelConfig() method of this package
67+
Config []byte
68+
// optional - the list of collected signatures
69+
// required by the channel create policy when using the `config` parameter.
70+
// see signChannelConfig() method of this package
71+
Signatures []*common.ConfigSignature
72+
// optional - transaction ID
73+
// required when using the `config` parameter
74+
TxID string
75+
// optional - nonce
76+
// required when using the `config` parameter
77+
Nonce []byte
78+
}

fabric-client/keyvaluestore/keyvaluestore.go renamed to api/keyvaluestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package keyvaluestore
7+
package api
88

99
// KeyValueStore ...
1010
/**

0 commit comments

Comments
 (0)