Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

HyperLeger Fabric SDK Development (3)-- fabsdk

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

HyperLeger Fabric SDK development (3)-- fabsdk 1, introduction to fabsdk 1, introduction to fabsdk

Fabsdk is the main package for Fabric SDK, and fabsdk supports clients to use Hyperledger Fabric blockchain networks. Fabsdk creates a context based on the configuration, which is used in the client package.

Official documents:

Https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/fabsdk

2. The basic process of using fabsdk

The basic process for using Fabsdk is as follows:

Instantiate a fabsdk instance using configuration

B. Use fabsdk instances to create contexts based on organizations and users

C. Use the New function to create a client instance with the context as a parameter. You can create a client instance for each context you need.

D. use the functional functions provided by each client instance to write business logic and build a solution.

E, call the fsbsdk.Close () function to release resources and cache.

Second, fabsdk common interface 1, type definition

Var ErrAnonymousIdentity = errors.New ("missing credentials")

If the option to create an identity contains neither the user name nor the identity, return ErrAnonymousIdentity.

Type Option func (opts * options) error

Option is used to configure SDK.

2. Obtain FabricSDK instance type FabricSDK struct {opts options provider * context.Provider cryptoSuite core.CryptoSuite}

FabricSDK provides access (and context) to SDK-managed clients

Func New (configProvider core.ConfigProvider, opts... Option) (* FabricSDK, error)

New initializes the SDK based on the set of options provided. ConfigOptions provides application configuration.

Examples of use are as follows:

Sdk, err = fabsdk.New (config.FromFile (". / config.yaml"))

3. Get the channel context

Func (sdk * FabricSDK) ChannelContext (channelID string, options... ContextOption) contextApi.ChannelProvider

ChannelContext creates and returns the channel context.

4. Close the FabricSDK instance

Func (sdk * FabricSDK) Close ()

Release caches and connections maintained by SDK

5. Get the FabricSDK configuration backend

Func (sdk * FabricSDK) Config () (core.ConfigBackend, error)

Config returns the configuration backend used by all SDK configuration types

6. Create a context client

Func (sdk * FabricSDK) Context (options... ContextOption) contextApi.ClientProvider

Context creates and returns a contextual client containing all the required providers.

7. Option to build type identityOptions struct {signingIdentity msp.SigningIdentity orgName string username string} type ContextOption func (s * identityOptions) error

ContextOption provides parameters for creating a session

Func WithIdentity (signingIdentity msp.SigningIdentity) ContextOption

WithIdentity uses a pre-constructed identity object as the credential for the session

Func WithUser (username string) ContextOption

WithUser uses the specified user to load the identity / identity

Func WithOrg (org string) ContextOption

WithOrg uses the specified organization

Examples of use:

Var (sdk * fabsdk.FabricSDK org = "org1" user = "Admin") ctx: = sdk.Context (fabsdk.WithOrg (org), fabsdk.WithUser (user)) type Option func (opts * options) errorfunc WithCorePkg (core sdkApi.CoreProviderFactory) Option

Inject the core implementation into SDK

Func WithCryptoSuiteConfig (cryptoConfigs... interface {}) Option

WithCryptoSuiteConfig injects CryptoSuiteConfig interfaces into SDK, and SDK receives a full set of interfaces for each CryptoSuiteConfig implementation or a list of subinterfaces for each CryptoSuiteConfig implementation

Func WithEndpointConfig (endpointConfigs... interface {}) Option

WithEndpointConfig injects EndpointConfig interfaces into SDK, and SDK receives a full set of interfaces for each EndpointConfig implementation or a list of subinterfaces for each EndpointConfig implementation

Func WithIdentityConfig (identityConfigs... interface {}) Option

WithIdentityConfig injects IdentityConfig interfaces into SDK, and SDK receives a full set of interfaces for each IdentityConfig implementation or a list of subinterfaces for each IdentityConfig implementation

Func WithLoggerPkg (logger api.LoggerProvider) Option

WithLoggerPkg injects logger implementation into SDK

Func WithMSPPkg (msp sdkApi.MSPProviderFactory) Option

WithMSPPkg injects MSP implementation into SDK

Func WithServicePkg (service sdkApi.ServiceProviderFactory) Option

WithServicePkg injects service implementation into SDK

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report