文件:n459.com/file/25127180-477419607

以下內(nèi)容無關(guān):

-------------------------------------------分割線------------------" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運營 > 超級漂亮的網(wǎng)上花店html靜態(tài)頁面

超級漂亮的網(wǎng)上花店html靜態(tài)頁面

時間:2023-06-10 19:24:01 | 來源:網(wǎng)站運營

時間:2023-06-10 19:24:01 來源:網(wǎng)站運營

超級漂亮的網(wǎng)上花店html靜態(tài)頁面:這是剛學(xué)習(xí)的時候使用dreamweaver設(shè)計的頁面,純css+js

文件:n459.com/file/25127180-477419607

以下內(nèi)容無關(guān):

-------------------------------------------分割線---------------------------------------------

1.1、目錄介紹

pkg目錄是fabric go sdk的主要實現(xiàn),doc文檔介紹了不同目錄所提供的功能,以及給出了接口調(diào)用樣例:



fabsdk包
client/channel包


client/event包


client/ledger包





1.2、一般步驟

1.3、config.yaml配置文件

client使用sdk與fabric網(wǎng)絡(luò)交互,需要告訴sdk兩類信息:

![](/home/liuhui/文檔/hyperledge Fabric/config-yaml.png)

1.4、使用go mod管理項目依賴

fabric go sdk目前本身使用go modules管理依賴,從go.mod可知,依賴的一些包指定了具體的版本, 如果你的項目依賴的版本和fabric go sdk依賴的版本不同,會產(chǎn)生編譯問題。

因此建議項目也使用go moudles管理依賴,然后相同的軟件包可以使用相同的版本,可以這樣操作:

1.5、創(chuàng)建fabric-SDK-GO入口實例

通過config.FromFile解析配置文件,然后通過fabsdk.New創(chuàng)建fabric go sdk的入口實例。

import "github.com/hyperledger/fabric go sdk/pkg/core/config"import "github.com/hyperledger/fabric go sdk/pkg/fabsdk"sdk, err := fabsdk.New(config.FromFile(c.ConfigPath))if err != nil { log.Panicf("failed to create fabric sdk: %s", err)}

1.6、創(chuàng)建fabric-SDK-GO的資源管理客戶端

管理員賬號才能進行Hyperledger fabric網(wǎng)絡(luò)的管理操作,所以創(chuàng)建資源管理客戶端一定要使用管理員賬號。

通過fabsdk.WithOrg("Org1")fabsdk.WithUser("Admin")指定Org1的Admin賬戶,使用sdk.Context創(chuàng)建clientProvider,然后通過resmgmt.New創(chuàng)建fabric-SDK-GO資源管理客戶端。

import "github.com/hyperledger/fabric go sdk/pkg/client/resmgmt"rcp := sdk.Context(fabsdk.WithUser("Admin"), fabsdk.WithOrg("Org1"))rc, err := resmgmt.New(rcp)if err != nil { log.Panicf("failed to create resource client: %s", err)}

1.7、創(chuàng)建fabric-SDK-GO的通道客戶端

使用用戶賬號創(chuàng)建fabric-SDK-GO的通道客戶端,以便進行fabric鏈碼的調(diào)用和查詢。使用sdk.ChannelContext創(chuàng)建channelProvider,需要指定channelID和用戶User1,然后通過channel.New創(chuàng)建通道客戶端,這個通道客戶端就是調(diào)用channelID對應(yīng)channel上鏈碼的channel client。

################兩種方法可以創(chuàng)建通道客戶端#####################

方法一:

import "github.com/hyperledger/fabric go sdk/pkg/client/channel"ccp := sdk.ChannelContext(ChannelID, fabsdk.WithUser("User1"))cc, err := channel.New(ccp)if err != nil { log.Panicf("failed to create channel client: %s", err)}方法二:

// New creates a new Client instance mspClient, err := mspclient.New(sdk.Context(), mspclient.WithOrg(info.OrgName)) if err != nil { return fmt.Errorf("根據(jù)指定的 OrgName 創(chuàng)建 Org MSP 客戶端實例失敗: %v", err) } // Returns: signing identity adminIdentity, err := mspClient.GetSigningIdentity(info.OrgAdmin) if err != nil { return fmt.Errorf("獲取指定id的簽名標(biāo)識失敗: %v", err) } // SaveChannelRequest holds parameters for save channel request channelReq := resmgmt.SaveChannelRequest{ChannelID:info.ChannelID, ChannelConfigPath:info.ChannelConfig, SigningIdentities:[]msp.SigningIdentity{adminIdentity}} // save channel response with transaction ID _, err = resMgmtClient.SaveChannel(channelReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint(info.OrdererOrgName)) if err != nil { return fmt.Errorf("創(chuàng)建應(yīng)用通道失敗: %v", err) } fmt.Println("通道已成功創(chuàng)建,")

1.8、peer節(jié)點加入通道

// allows for peers to join existing channel with optional custom options (specific peers, filtered peers). If peer(s) are not specified in options it will default to all peers that belong to client's MSP. err = info.OrgResMgmt.JoinChannel( info.ChannelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint(info.OrdererOrgName) ) if err != nil { return fmt.Errorf("Peers加入通道失敗: %v", err) } fmt.Println("peers 已成功加入通道.")

1.9、資源管理客戶端安裝鏈碼

安裝Fabric鏈碼使用資源管理客戶端的InstallCC接口,需要指定resmgmt.InstallCCRequest以及在哪些peers上面安裝。resmgmt.InstallCCRequest指明了鏈碼ID、鏈碼路徑、鏈碼版本以及打包后的鏈碼。

打包鏈碼需要使用到鏈碼路徑CCPath和GoPath,GoPath即本機的$GOPATH,CCPath是相對于GoPath的相對路徑,如果路徑設(shè)置不對,會造成sdk找不到鏈碼。

fmt.Println("開始安裝鏈碼......") // creates new go lang chaincode package ccPkg, err := gopackager.NewCCPackage(info.ChaincodePath, info.ChaincodeGoPath) if err != nil { return nil, fmt.Errorf("創(chuàng)建鏈碼包失敗: %v", err) } // contains install chaincode request parameters installCCReq := resmgmt.InstallCCRequest{Name: info.ChaincodeID, Path: info.ChaincodePath, Version: ChaincodeVersion, Package: ccPkg} /*可以制定安裝在哪個peer節(jié)點上 reqPeers := resmgmt.WithTargetEndpoints("peer0.org1.example.com") resps, err := rc.InstallCC(req, reqPeers) */ // allows administrators to install chaincode onto the filesystem of a peer _, err = info.OrgResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts)) if err != nil { return nil, fmt.Errorf("安裝鏈碼失敗: %v", err) } fmt.Println("指定的鏈碼安裝成功")

1.10、資源管理客戶端實例化鏈碼

實例化鏈碼需要使用fabric go sdk的資源管理客戶端的InstantiateCC接口,需要通過ChannelID、 resmgmt.InstantiateCCRequest和peers,指明在哪個channel上實例化鏈碼,請求包含了鏈碼的ID、路徑、版本,以及初始化參數(shù)和背書策略,背書策略可以通過cauthdsl.FromString生成。

方法一:

// endorser policyorg1OrOrg2 := "OR('Org1MSP.member','Org2MSP.member')"ccPolicy, err := cauthdsl.FromString(org1OrOrg2)if err != nil { return errors.WithMessage(err, "gen policy from string error")}// new requestargs := packArgs([]string{"init", "a", "100", "b", "200"})req := resmgmt.InstantiateCCRequest{ Name: c.CCID, Path: c.CCPath, Version: v, Args: args, Policy: ccPolicy,}// send request and handle responsereqPeers := resmgmt.WithTargetEndpoints("peer0.org1.example.com")resp, err := rc.InstantiateCC(ChannelID, req, reqPeers)if err != nil { return errors.WithMessage(err, "instantiate chaincode error")}方法二:

// returns a policy that requires one valid ccPolicy := policydsl.SignedByAnyMember([]string{"org1.kevin.kongyixueyuan.com"}) instantiateCCReq := resmgmt.InstantiateCCRequest{Name: info.ChaincodeID, Path: info.ChaincodePath, Version: ChaincodeVersion, Args: [][]byte{[]byte("init")}, Policy: ccPolicy} // instantiates chaincode with optional custom options (specific peers, filtered peers, timeout). If peer(s) are not specified _, err = info.OrgResMgmt.InstantiateCC(info.ChannelID, instantiateCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts)) if err != nil { return nil, fmt.Errorf("實例化鏈碼失敗: %v", err) } fmt.Println("鏈碼實例化成功")

1.11、資源管理客戶端升級鏈碼

升級鏈碼和實例化鏈碼是非常相似的,不同點只在請求是resmgmt.UpgradeCCRequest,調(diào)用的接口是rc.UpgradeCC:

// endorser policyorg1AndOrg2 := "AND('Org1MSP.member','Org2MSP.member')"ccPolicy, err := c.genPolicy(org1AndOrg2)if err != nil { return errors.WithMessage(err, "gen policy from string error")}// new requestargs := packArgs([]string{"init", "a", "100", "b", "200"})req := resmgmt.UpgradeCCRequest{ Name: c.CCID, Path: c.CCPath, Version: v, Args: args, Policy: ccPolicy,}// send request and handle responsereqPeers := resmgmt.WithTargetEndpoints("peer0.org1.example.com")resp, err := rc.UpgradeCC(ChannelID, req, reqPeers)if err != nil { return errors.WithMessage(err, "instantiate chaincode error")}

1.12、通道客戶端調(diào)用鏈碼

使用通道客戶端的Execute接口調(diào)用鏈碼,使用入?yún)hannel.Request和peers指明要讓哪些peer上執(zhí)行鏈碼,進行背書。channel.Request指明了要調(diào)用的鏈碼,以及鏈碼內(nèi)要Invoke的函數(shù)args,args是序列化的結(jié)果,序列化是自定義的,只要鏈碼能夠按相同的規(guī)則進行反序列化即可。

// new channel request for invokeargs := packArgs([]string{"a", "b", "10"})req := channel.Request{ ChaincodeID: c.CCID, Fcn: "invoke", Args: args,}// send request and handle response// peers is neededreqPeers := channel.WithTargetEndpoints("peer0.org1.example.com")resp, err := cc.Execute(req, reqPeers)if err != nil { return errors.WithMessage(err, "invoke chaincode error")}log.Printf("invoke chaincode tx: %s", resp.TransactionID)

1.13、通道客戶端查詢鏈碼

查詢和調(diào)用鏈碼是非常相似的,使用相同的channel.Request,指明了Invoke鏈碼中的query函數(shù),然后調(diào)用cc.Query進行查詢操作,這樣節(jié)點不會對請求進行背書:

// new channel request for queryreq := channel.Request{ ChaincodeID: c.CCID, Fcn: "query", Args: packArgs([]string{keys}),}// send request and handle responsereqPeers := channel.WithTargetEndpoints(peer)resp, err := cc.Query(req, reqPeers)if err != nil { return errors.WithMessage(err, "query chaincode error")}log.Printf("query chaincode tx: %s", resp.TransactionID)log.Printf("result: %v", string(resp.Payload))

1.14、綜合示例

(1)客戶端實現(xiàn)

/** author: liuhui*/package sdkInitimport ( "fmt" "github.com/astaxie/beego/logs" mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp" "github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt" "github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp" "github.com/hyperledger/fabric-sdk-go/pkg/core/config" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" "github.com/hyperledger/fabric-sdk-go/pkg/client/channel" "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/policydsl")const ChaincodeVersion = "1.0"//initialized fabric sdkfunc SetupSDK(ConfigFile string, initialized bool) (*fabsdk.FabricSDK, error) { if initialized { //logs.Error("Fabric SDK has been initialized") return nil, fmt.Errorf("Fabric SDK has been initialized") } sdk, err := fabsdk.New(config.FromFile(ConfigFile)) if err != nil { //logs.Error("Instantiation Fabric SDK failed") return nil, fmt.Errorf("Instantiation Fabric SDK failed: %v", err) } logs.Informational("Fabric SDK is initialized successfully") return sdk, nil}// create channel and join peersfunc CreateChannel(sdk *fabsdk.FabricSDK, info *InitInfo) error { clientContext := sdk.Context(fabsdk.WithUser(info.OrgAdmin), fabsdk.WithOrg(info.OrgName)) if clientContext == nil { return fmt.Errorf("Failed to create client context based on organization name and administrator user") } // New returns a resource management client instance. resMgmtClient, err := resmgmt.New(clientContext) if err != nil { return fmt.Errorf("Failed to create resource management client by client context: %v", err) } // New creates a new Client instance mspClient, err := mspclient.New(sdk.Context(), mspclient.WithOrg(info.OrgName)) if err != nil { return fmt.Errorf("Failed to create Org MSP client by specified OrgName: %v", err) } // Returns: signing identity adminIdentity, err := mspClient.GetSigningIdentity(info.OrgAdmin) if err != nil { return fmt.Errorf("Failed to get the signature of the specified ID: %v", err) } // SaveChannelRequest holds parameters for save channel request channelReq := resmgmt.SaveChannelRequest{ChannelID: info.ChannelID, ChannelConfigPath: info.ChannelConfig, SigningIdentities: []msp.SigningIdentity{adminIdentity}} // save channel response with transaction ID _, err = resMgmtClient.SaveChannel(channelReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint(info.OrdererOrgName)) if err != nil { return fmt.Errorf("Failed to create channle: %v", err) } logs.Informational("Create channel successful") info.OrgResMgmt = resMgmtClient // allows for peers to join existing channel with optional custom options (specific peers, filtered peers). If peer(s) are not specified in options it will default to all peers that belong to client's MSP. err = info.OrgResMgmt.JoinChannel(info.ChannelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint(info.OrdererOrgName)) if err != nil { return fmt.Errorf("Peers failed to join channel: %v", err) } logs.Informational("Peers join channel successful") return nil}//install and instantiate chaincodefunc InstallAndInstantiateCC(sdk *fabsdk.FabricSDK, info *InitInfo) (*channel.Client, error) { logs.Informational("Start to install chaincode") // creates new go lang chaincode package ccPkg, err := gopackager.NewCCPackage(info.ChaincodePath, info.ChaincodeGoPath) if err != nil { return nil, fmt.Errorf("Failed to create chaincode package: %v", err) } // contains install chaincode request parameters installCCReq := resmgmt.InstallCCRequest{Name: info.ChaincodeID, Path: info.ChaincodePath, Version: ChaincodeVersion, Package: ccPkg} // allows administrators to install chaincode onto the filesystem of a peer _, err = info.OrgResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts)) if err != nil { return nil, fmt.Errorf("Failed to install chaincode: %v", err) } logs.Informational("Install chaincode successful") logs.Informational("Start to instantiate chaincode") // returns a policy that requires one valid ccPolicy := policydsl.SignedByAnyMember([]string{"org1.institution.com"}) instantiateCCReq := resmgmt.InstantiateCCRequest{Name: info.ChaincodeID, Path: info.ChaincodePath, Version: ChaincodeVersion, Args: [][]byte{[]byte("init")}, Policy: ccPolicy} // instantiates chaincode with optional custom options (specific peers, filtered peers, timeout). If peer(s) are not specified _, err = info.OrgResMgmt.InstantiateCC(info.ChannelID, instantiateCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts)) if err != nil { return nil, fmt.Errorf("Failed to instantiate chaincode: %v", err) } logs.Informational("Instantiate chaincode successful") clientChannelContext := sdk.ChannelContext(info.ChannelID, fabsdk.WithUser(info.UserName), fabsdk.WithOrg(info.OrgName)) // returns a Client instance. Channel client can query chaincode, execute chaincode and register/unregister for chaincode events on specific channel. channelClient, err := channel.New(clientChannelContext) if err != nil { return nil, fmt.Errorf("Failed to create channel context: %v", err) } logs.Informational("Create channel client successful ,you can use it to execute transactions.") return channelClient, nil}func ChannelClient(sdk *fabsdk.FabricSDK, info *InitInfo) (*channel.Client,error){ clientChannelContext := sdk.ChannelContext(info.ChannelID, fabsdk.WithUser(info.UserName), fabsdk.WithOrg(info.OrgName)) // returns a Client instance. Channel client can query chaincode, execute chaincode and register/unregister for chaincode events on specific channel. channelClient, err := channel.New(clientChannelContext) if err != nil { return nil, fmt.Errorf("Failed to create channel context: %v", err) } logs.Informational("Create channel client successful ,you can use it to execute transactions.") return channelClient, nil}(2)調(diào)用客戶端

package mainimport ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" _ "github.com/lib/pq" "jingjinjiapi/controllers" _ "jingjinjiapi/routers" "jingjinjiapi/sdkInit" "os")const ( //config of SDK configFile = "config.yaml" //mark whehter the client is initialized initialized = false //the chaincode id EduCC = "educc" DOC_TYPE = "insObj")func main() { //setting loggers level and location logs.SetLogger("file", `{"filename":"logs/jingjinji_beego.log"}`) logs.SetLevel(logs.LevelInformational) logs.Info("setting logs level : information") //initialized the information of sdk initInfo := &sdkInit.InitInfo{ ChannelID: "institutionchannel", ChannelConfig: os.Getenv("GOPATH") + "/src/jingjinjiapi/fixtures/artifacts/channel.tx", OrgAdmin: "Admin", OrgName: "Org1", OrdererOrgName: "orderer.institution.com", ChaincodeID: EduCC, ChaincodeGoPath: os.Getenv("GOPATH"), ChaincodePath: "jingjinjiapi/chaincode/", UserName: "User1", } var serviceSetup controllers.ServiceSetup //initialize SDK,use the function:fabsdk.new sdk, err := sdkInit.SetupSDK(configFile, initialized) if err != nil { logs.Error(err.Error()) return } //free the resource until the main program finish defer sdk.Close() flag := false if flag{ //create channel and add the peer node to the channel err = sdkInit.CreateChannel(sdk, initInfo) if err != nil { logs.Error(err.Error()) return } //install chaincode and instantiate chaincode channelClient, err := sdkInit.InstallAndInstantiateCC(sdk, initInfo) if err != nil { logs.Error(err.Error()) return } serviceSetup.ChaincodeID = EduCC serviceSetup.Client = channelClient }else{ channelClient, err := sdkInit.ChannelClient(sdk,initInfo) if err != nil { logs.Error(err.Error()) return } serviceSetup.ChaincodeID = EduCC serviceSetup.Client = channelClient } logs.Informational(serviceSetup) //===========================================// //start Testing ............................................. //start service beego.Router("/v1/institution", &controllers.InstitutionController{Setup: &serviceSetup})}

關(guān)鍵詞:靜態(tài),漂亮,超級

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點擊下載Chrome瀏覽器
關(guān)閉