Documentation

Overview

    Package ledger enables ledger queries on specified channel on a Fabric network. An application that requires ledger queries from multiple channels should create a separate instance of the ledger client for each channel. Ledger client supports the following queries: QueryInfo, QueryBlock, QueryBlockByHash, QueryBlockByTxID, QueryTransaction and QueryConfig.

    Basic Flow:
    1) Prepare channel context
    2) Create ledger client
    3) Query ledger
    
    Example
    Output:
    
    Retrieved block #1
    

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Client

    type Client struct {
    	// contains filtered or unexported fields
    }

      Client enables ledger queries on a Fabric network.

      func New

      func New(channelProvider context.ChannelProvider, opts ...ClientOption) (*Client, error)

        New returns a ledger client instance. A ledger client instance provides a handler to query various info on specified channel. An application that requires interaction with multiple channels should create a separate instance of the ledger client for each channel. Ledger client supports specific queries only.

        Example
        Output:
        
        ledger client created
        

        func (*Client) QueryBlock

        func (c *Client) QueryBlock(blockNumber uint64, options ...RequestOption) (*common.Block, error)

          QueryBlock queries the ledger for Block by block number.

          Parameters:
          blockNumber is required block number(ID)
          options hold optional request options
          
          Returns:
          block information
          
          Example
          Output:
          
          Retrieved block #1
          

          func (*Client) QueryBlockByHash

          func (c *Client) QueryBlockByHash(blockHash []byte, options ...RequestOption) (*common.Block, error)

            QueryBlockByHash queries the ledger for block by block hash.

            Parameters:
            blockHash is required block hash
            options hold optional request options
            
            Returns:
            block information
            
            Example
            Output:
            
            Retrieved block by hash
            

            func (*Client) QueryBlockByTxID

            func (c *Client) QueryBlockByTxID(txID fab.TransactionID, options ...RequestOption) (*common.Block, error)

              QueryBlockByTxID queries for block which contains a transaction.

              Parameters:
              txID is required transaction ID
              options hold optional request options
              
              Returns:
              block information
              
              Example
              Output:
              
              Retrieved block by transaction ID
              

              func (*Client) QueryConfig

              func (c *Client) QueryConfig(options ...RequestOption) (fab.ChannelCfg, error)

                QueryConfig queries for channel configuration.

                Parameters:
                options hold optional request options
                
                Returns:
                channel configuration information
                
                Example
                Output:
                
                Retrieved channel configuration
                

                func (*Client) QueryConfigBlock

                func (c *Client) QueryConfigBlock(options ...RequestOption) (*common.Block, error)

                  QueryConfigBlock returns the current configuration block for the specified channel.

                  func (*Client) QueryInfo

                  func (c *Client) QueryInfo(options ...RequestOption) (*fab.BlockchainInfoResponse, error)

                    QueryInfo queries for various useful blockchain information on this channel such as block height and current block hash.

                    Parameters:
                    options are optional request options
                    
                    Returns:
                    blockchain information
                    
                    Example
                    Output:
                    
                    Retrieved ledger info
                    

                    func (*Client) QueryTransaction

                    func (c *Client) QueryTransaction(transactionID fab.TransactionID, options ...RequestOption) (*pb.ProcessedTransaction, error)

                      QueryTransaction queries the ledger for processed transaction by transaction ID.

                      Parameters:
                      txID is required transaction ID
                      options hold optional request options
                      
                      Returns:
                      processed transaction information
                      
                      Example
                      Output:
                      
                      Retrieved transaction
                      

                      type ClientOption

                      type ClientOption func(*Client) error

                        ClientOption describes a functional parameter for the New constructor

                        func WithDefaultTargetFilter

                        func WithDefaultTargetFilter(filter fab.TargetFilter) ClientOption

                          WithDefaultTargetFilter option to configure new

                          Example
                          Output:
                          
                          ledger client created with url target filter
                          

                          type RequestOption

                          type RequestOption func(ctx context.Client, opts *requestOptions) error

                            RequestOption func for each requestOptions argument

                            func WithMaxTargets

                            func WithMaxTargets(maxTargets int) RequestOption

                              WithMaxTargets specifies maximum number of targets to select per request. Default value for maximum number of targets is 1.

                              func WithMinTargets

                              func WithMinTargets(minTargets int) RequestOption

                                WithMinTargets specifies minimum number of targets that have to respond with no error (or agree on result). Default value for minimum number of targets is 1.

                                func WithParentContext

                                func WithParentContext(parentContext reqContext.Context) RequestOption

                                  WithParentContext encapsulates grpc parent context

                                  Example
                                  Output:
                                  
                                  Retrieved blockchain info
                                  

                                  func WithTargetEndpoints

                                  func WithTargetEndpoints(keys ...string) RequestOption

                                    WithTargetEndpoints allows overriding of the target peers per request. Targets are specified by name or URL, and the SDK will create the underlying peer objects.

                                    func WithTargetFilter

                                    func WithTargetFilter(targetFilter fab.TargetFilter) RequestOption

                                      WithTargetFilter specifies a per-request target peer-filter.

                                      Example
                                      Output:
                                      
                                      Retrieved block #1 from example.com
                                      

                                      func WithTargets

                                      func WithTargets(targets ...fab.Peer) RequestOption

                                        WithTargets allows for overriding of the target peers per request.

                                        Example
                                        Output:
                                        
                                        Retrieved config from target peer
                                        

                                        func WithTimeout

                                        func WithTimeout(timeoutType fab.TimeoutType, timeout time.Duration) RequestOption

                                          WithTimeout encapsulates key value pairs of timeout type, timeout duration to Options for QueryInfo, QueryBlock, QueryBlockByHash, QueryBlockByTxID, QueryTransaction, QueryConfig functions

                                          Source Files