In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
HyperLeger Fabric SDK development (4)-- channel 1, introduction to channel 1, introduction to channel
Pkg/client/channel supports access to channels on the Fabric network. The channel client instance provides handlers that interact with Peer nodes on the specified channel. The channel client can query the chain code on the specified channel, execute the chain code, and register or unregister the chain code event. If your application needs to interact with multiple channels of the Fabric network, you need to create a separate channel client instance for each channel.
Official documents:
Https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/channel
2. Channel usage process
The process for using channel is as follows:
A. prepare the channel client context
B. Create a tunnel client
C, execute chain code
D, query chain code
Examples of channel usage are as follows:
C, err: = New (mockChannelProvider ("mychannel")) if err! = nil {fmt.Println ("failed to create client")} response, err: = c.Query (Request {ChaincodeID: "testCC", Fcn: "invoke", Args: [] [] byte {[] byte ("query"), [] byte ("data")}) if err! = nil {fmt.Printf ("failed to query chaincode:% s\ n") Err)} fmt.Println (string (response.Payload)) / / output:// abc II, channel common interface 1, type definition / / Request contains query and execution of a transaction parameter type Request struct {ChaincodeID string Fcn string Args [] byte TransientMap map [string] [] byte / / InvocationChai contains metadata Some selection service implementations use metadata to select the endorsement node / / Each chaincode may also be associated with a set of private data collection names / / which are used by some Selection Services (e.g. Fabric Selection) to exclude endorsers / / that do NOT have read access to the collections that satisfies the endorsement / / policy of all chain codes in the calling chain. / / The invoked chaincode (specified by ChaincodeID) may optionally be added to the invocation / / chain along with any collections, otherwise it may be omitted. InvocationChain [] * fab.ChaincodeCall} / / Response contains the response parameters type Response struct {Proposal * fab.TransactionProposal Responses [] * fab.TransactionProposalResponse TransactionID fab.TransactionID TxValidationCode pb.TxValidationCode ChaincodeStatus int32 Payload [] byte} 2 to execute and query a calling transaction, and get the client instance type Client struct {context context.Channel membership fab.ChannelMembership eventService fab.EventService greylist * greylist.Filter clientTally / / nolint}.
The channel client supports access to channels on the Fabric network. In order to interact with the Peer node of a particular channel, the channel client instance provides a handler. If your application needs to interact with multiple channels, you should create a separate channel client instance for each channel. The channel client only supports non-administrative functions.
Type ClientOption func (* Client) errorfunc New (channelProvider context.ChannelProvider, opts... ClientOption) (* Client, error)
Returns the channel Client instance. The channel client can query the chain code on a specific channel, execute the chain code, and register / unregister the chain code event.
Examples of use:
Ctx: = mockChannelProvider ("mychannel") c, err: = New (ctx) if err! = nil {fmt.Println (err)} if c! = nil {fmt.Println ("channel client created")} else {fmt.Println ("channel client is nil")} / / output:// channel client created 3, execute the transaction
Func (cc * Client) Execute (request Request, options... RequestOption) (Response, error)
Prepare and execute the transaction using the request and optional request options.
Parameters:
Request contains information about necessary chain codes ID and functions
Options contains optional request options
Return Peer's reply to the proposal.
Examples of use:
C, err: = New (mockChannelProvider ("mychannel")) if err! = nil {fmt.Println ("failed to create client")} _, err = c.Execute (Request {ChaincodeID: "testCC", Fcn: "invoke", Args: [] [] byte {[] byte ("move"), [] byte ("a"), [] byte ("b") [] byte ("1")}}) if err! = nil {fmt.Println (err.Error ())} fmt.Println ("Chaincode transaction completed") / / output:// Chaincode transaction completed 4, call transaction processing
Func (cc * Client) InvokeHandler (handler invoke.Handler, request Request, options... RequestOption) (Response, error)
InvokeHandler invokes the handler using the provided request and optional request options
Parameters:
Handler is the handler to be called
Request contains the necessary chain code ID and information about functions
Options contains optional request options
Return Peer's reply to the proposal.
Examples of use:
C, err: = New (mockChannelProvider ("mychannel")) if err! = nil {fmt.Println ("failed to create client")} response, err: = c.InvokeHandler (& exampleHandler {}, Request {ChaincodeID: "testCC", Fcn: "invoke", Args: [] [] byte {[] byte ("query"), [] byte ("data")}) if err! = nil {fmt.Printf ("failed to query chaincode:% s\ n") Err)} fmt.Println (string (response.Payload)) / / output:// custom5, query
Func (cc * Client) Query (request Request, options... RequestOption) (Response, error)
Use request and the optional request option options to query the chain code.
Parameters:
Request contains information about necessary chain codes ID and functions
Options contains optional request options
Return value: Peer's reply to the proposal
Examples of use:
C, err: = New (mockChannelProvider ("mychannel")) if err! = nil {fmt.Println ("failed to create client")} response, err: = c.Query (Request {ChaincodeID: "testCC", Fcn: "invoke", Args: [] [] byte {[] byte ("query"), [] byte ("b")}) if err! = nil {fmt.Printf ("failed to query chaincode:% s\ n") Err)} if len (response.Payload) > 0 {fmt.Println ("chaincode query success")} / / output:// chaincode query success6, register chain code event
Func (cc * Client) RegisterChaincodeEvent (chainCodeID string, eventFilter string) (fab.Registration
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.