Documentation ¶
Overview ¶
Package fabclient aims to facilitate the development of solutions that interact with Hyperledger Fabric thanks to the fabric-sdk-go.
Package fabclient enables the creation and update of a channel, for peers to join channels. It allows administrators to perform chaincode related operations on a peer. It uses the legacy chaincode lifecycle enabling to install, instantiate and upgrade a chaincode. Furthermore, package fabclient provides access to a channel on a Fabric network, allowing users to query/invoke chaincodes, register/unregister for chaincode events on specific channel and perform ledger queries.
It is a wrapper around the fabric-sdk-go. The client has been designed for being able to manage multiple channels and interact with multiple chaincodes.
Example ¶
client, err := NewClientFromConfigFile("./testdata/client/client-config.yaml") if err != nil { log.Fatal(err) } defer client.Close() channel := client.Config().Channels[0] chaincode := client.Config().Chaincodes[0] if err := client.SaveChannel(channel.Name, channel.ConfigPath); err != nil { log.Fatal(err) } if err := client.JoinChannel(channel.Name); err != nil { log.Fatal(err) } if err := client.InstallChaincode(chaincode); err != nil { log.Fatal(err) } if err := client.InstantiateOrUpgradeChaincode(channel.Name, chaincode); err != nil { log.Fatal(err) } storeRequest := &ChaincodeRequest{ ChaincodeID: chaincode.Name, Function: "store", Args: []string{"asset-test", `{"content": "this is a content test"}`}, } storeResult, err := client.Invoke(storeRequest, WithOrdererResponseTimeout(2*time.Second)) if err != nil { log.Fatal(err) } log.Printf("store txID: %s", storeResult.TransactionID) queryRequest := &ChaincodeRequest{ ChaincodeID: chaincode.Name, Function: "query", Args: []string{"asset-test"}, } queryResult, err := client.Query(queryRequest) if err != nil { log.Fatal(err) } log.Printf("query content: %s", string(queryResult.Payload))
Output:
Index ¶
- type Block
- type BlockData
- type BlockHeader
- type BlockMetadata
- type BlockchainInfo
- type Chaincode
- type ChaincodeCall
- type ChaincodeCollection
- type ChaincodeEvent
- type ChaincodeRequest
- type Channel
- type Client
- func (client *Client) Close()
- func (client *Client) Config() *Config
- func (client *Client) InstallChaincode(chaincode Chaincode) error
- func (client *Client) InstantiateOrUpgradeChaincode(channelID string, chaincode Chaincode) error
- func (client *Client) Invoke(request *ChaincodeRequest, opts ...Option) (*TransactionResponse, error)
- func (client *Client) IsChaincodeInstalled(chaincodeName string) bool
- func (client *Client) IsChaincodeInstantiated(channelID, chaincodeName, chaincodeVersion string) bool
- func (client *Client) JoinChannel(channelID string) error
- func (client *Client) Query(request *ChaincodeRequest, opts ...Option) (*TransactionResponse, error)
- func (client *Client) QueryBlock(blockNumber uint64, opts ...Option) (*Block, error)
- func (client *Client) QueryBlockByHash(blockHash []byte, opts ...Option) (*Block, error)
- func (client *Client) QueryBlockByTxID(txID string, opts ...Option) (*Block, error)
- func (client *Client) QueryInfo(opts ...Option) (*BlockchainInfo, error)
- func (client *Client) RegisterChaincodeEvent(chaincodeID, eventFilter string, opts ...Option) (<-chan *ChaincodeEvent, error)
- func (client *Client) SaveChannel(channelID, channelConfigPath string) error
- func (client *Client) UnregisterChaincodeEvent(eventFilter string, opts ...Option) error
- type Config
- type Identity
- type Option
- type TransactionResponse
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { Header *BlockHeader Data *BlockData Metadata *BlockMetadata }
Block is finalized block structure to be shared among the orderer and peer.
type BlockHeader ¶
BlockHeader is the element of the block which forms the blockchain.
type BlockMetadata ¶
type BlockMetadata struct {
Metadata [][]byte
}
BlockMetadata defines metadata of the block.
type BlockchainInfo ¶
BlockchainInfo contains information about the blockchain ledger such as height, current block hash, and previous block hash.
type Chaincode ¶
type Chaincode struct { Collections []ChaincodeCollection `json:"collections,omitempty" yaml:"collections,omitempty"` InitArgs []string `json:"initArgs,omitempty" yaml:"initArgs,omitempty"` Name string `json:"name" yaml:"name"` Path string `json:"path" yaml:"path"` Policy string `json:"policy,omitempty" yaml:"policy,omitempty"` Version string `json:"version" yaml:"version"` }
Chaincode describes info of a chaincode.
type ChaincodeCall ¶
ChaincodeCall contains the ID of the chaincode as well as an optional set of private data collections that may be accessed by the chaincode.
type ChaincodeCollection ¶
type ChaincodeCollection struct { BlockToLive uint64 `json:"blockToLive" yaml:"blockToLive"` MaxPeerCount int32 `json:"maxPeerCount" yaml:"maxPeerCount"` MemberOnlyRead bool `json:"memberOnlyRead" yaml:"memberOnlyRead"` Name string `json:"name" yaml:"name"` Policy string `json:"policy" yaml:"policy"` RequiredPeerCount int32 `json:"requiredPeerCount" yaml:"requiredPeerCount"` }
ChaincodeCollection defines the configuration of a collection.
type ChaincodeEvent ¶
type ChaincodeEvent struct { TxID string ChaincodeID string EventName string Payload []byte BlockNumber uint64 SourceURL string }
ChaincodeEvent contains the data for a chaincode event.
type ChaincodeRequest ¶
type ChaincodeRequest struct { ChaincodeID string Function string Args []string TransientMap map[string][]byte InvocationChain []*ChaincodeCall }
ChaincodeRequest contains the parameters to query and execute an invocation transaction.
type Channel ¶
type Channel struct { AnchorPeerConfigPath string `json:"anchorPeerConfigPath,omitempty" yaml:"anchorPeerConfigPath,omitempty"` ConfigPath string `json:"configPath" yaml:"configPath"` Name string `json:"name" yaml:"name"` }
Channel describes a channel configuration.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client API enables to manage resources in a Fabric network, access to a channel, perform chaincode related operations.
func NewClientFromConfigFile ¶
NewClientFromConfigFile returns a client instance from a config file.
func (*Client) Close ¶
func (client *Client) Close()
Close frees up caches and connections being maintained by the SDK.
func (*Client) InstallChaincode ¶
InstallChaincode allows administrators to install chaincode onto the filesystem of a peer.
func (*Client) InstantiateOrUpgradeChaincode ¶
InstantiateOrUpgradeChaincode instantiates or upgrades chaincode.
func (*Client) Invoke ¶
func (client *Client) Invoke(request *ChaincodeRequest, opts ...Option) (*TransactionResponse, error)
Invoke prepares and executes transaction using request and optional request options.
func (*Client) IsChaincodeInstalled ¶
IsChaincodeInstalled returns whether the given chaincode has been installed or not.
func (*Client) IsChaincodeInstantiated ¶
func (client *Client) IsChaincodeInstantiated(channelID, chaincodeName, chaincodeVersion string) bool
IsChaincodeInstantiated returns whether the given chaincode has been instantiated or not.
func (*Client) JoinChannel ¶
JoinChannel allows for peers to join existing channel.
func (*Client) Query ¶
func (client *Client) Query(request *ChaincodeRequest, opts ...Option) (*TransactionResponse, error)
Query chaincode using request and optional request options.
func (*Client) QueryBlock ¶
QueryBlock queries the ledger for Block by block number.
func (*Client) QueryBlockByHash ¶
QueryBlockByHash queries the ledger for block by block hash.
func (*Client) QueryBlockByTxID ¶
QueryBlockByTxID queries for block which contains a transaction.
func (*Client) QueryInfo ¶
func (client *Client) QueryInfo(opts ...Option) (*BlockchainInfo, error)
QueryInfo queries for various useful blockchain information on this channel such as block height and current block hash.
func (*Client) RegisterChaincodeEvent ¶
func (client *Client) RegisterChaincodeEvent(chaincodeID, eventFilter string, opts ...Option) (<-chan *ChaincodeEvent, error)
RegisterChaincodeEvent registers for chaincode events. Unregister must be called when the registration is no longer needed.
func (*Client) SaveChannel ¶
SaveChannel creates or updates channel.
type Config ¶
type Config struct { Chaincodes []Chaincode `json:"chaincodes" yaml:"chaincodes"` Channels []Channel `json:"channels" yaml:"channels"` ConnectionProfile string `json:"connectionProfile" yaml:"connectionProfile"` Identities struct { Admin Identity `json:"admin" yaml:"admin"` Users []Identity `json:"users" yaml:"users"` } `json:"identities" yaml:"identities"` Organization string `json:"organization" yaml:"organization"` }
Config holds the client configuration.
func NewConfigFromFile ¶
NewConfigFromFile returns a new client config.
type Identity ¶
type Identity struct { Certificate string `json:"certificate" yaml:"certificate"` PrivateKey string `json:"privateKey" yaml:"privateKey"` Username string `json:"username" yaml:"username"` }
Identity holds crypto material for creating a signing identity.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option describes a functional parameter for the client.
func WithChannelContext ¶
WithChannelContext allows to target a specific channel.
func WithOrdererResponseTimeout ¶
WithOrdererResponseTimeout allows to specify a timeout for orderer response.
func WithUserContext ¶
WithUserContext allows to specify a user context.
type TransactionResponse ¶
TransactionResponse contains response parameters for query and execute an invocation transaction.