MetaForce佛薩奇系統開發技術流程(成熟程式碼)佛薩奇2.0原始碼部署教程
在Hyperledger Fabric中,鏈碼一般分為:
系統鏈碼
使用者鏈碼
系統鏈碼
系統鏈碼負責Fabric節點自身的處理邏輯,包括系統配置、背書、校驗等工作。系統鏈碼僅支援Go語言,在Peer節點啟動時會自動完成註冊和部署,所以安裝,例項化和升級不適用於系統鏈碼。
Init函式在鏈碼例項化以及升級的時候會被呼叫。在實現Init函式的過程中,可使用Go語言版本的合約API列表來對引數和分散式賬本進行操作。
func(t*SimpleChaincode)Init(stub shim.ChaincodeStubInterface)peer.Response{
fmt.Println("ex02 Init")
//呼叫GetFunctionAndParameters方法對引數進行解析
_,args:=stub.GetFunctionAndParameters()
var A,B string//Entities
var Aval,Bval int//Asset holdings
var err error
if len(args)!=4{
return shim.Error("Incorrect number of arguments.Expecting 4")
}
//初始化相關資料
A=args[0]
Aval,err=strconv.Atoi(args[1])
if err!=nil{
return shim.Error("Expecting integer value for asset holding")
}
B=args[2]
Bval,err=strconv.Atoi(args[3])
if err!=nil{
return shim.Error("Expecting integer value for asset holding")
}
fmt.Printf("Aval=%d,Bval=%dn",Aval,Bval)
//呼叫PutState方法將資料寫入賬本中
err=stub.PutState(A,[]byte(strconv.Itoa(Aval)))
if err!=nil{
return shim.Error(err.Error())
}
err=stub.PutState(B,[]byte(strconv.Itoa(Bval)))
if err!=nil{
return shim.Error(err.Error())
}
return shim.Success(nil)
}
本示例要求使用者輸入的引數為KEY1_NAME,VALUE1,KEY2_NAME,VALUE2,並初始化2個鍵值對,呼叫PutState將資料寫入分散式賬本中。
Invoke示例
Invoke函式是對使用者具體業務邏輯的實現,使用者可以根據不同的業務處理邏輯,呼叫不用的業務函式,如invoke,delete和query函式。
//Invoke把使用者呼叫的function細分到幾個子function,包含invoke,delete和query
func(t*SimpleChaincode)Invoke(stub shim.ChaincodeStubInterface)peer.Response{
fmt.Println("ex02 Invoke")
//呼叫GetFunctionAndParameters方法對引數進行解析
function,args:=stub.GetFunctionAndParameters()
if function=="invoke"{
//將A的資產轉移X個單位給B
return t.invoke(stub,args)
}else if function=="delete"{
//從狀態中刪除實體
return t.delete(stub,args)
}else if function=="query"{
//老的“Query”功能可以在呼叫中實現
return t.query(stub,args)
}
return shim.Error("Invalid invoke function name.Expecting"invoke""delete""query"")
}
系統鏈碼主要包括以下幾種:
生命週期系統鏈碼(LSCC):Lifecycle System Chaincode,負責對使用者鏈碼的生命週期進行管理。
配置系統鏈碼(CSCC):Configuration System Chaincode,負責處理Peer端的Channel配置。
查詢系統鏈碼(QSCC):Query System Chaincode,提供賬本查詢API,如獲取區塊和交易等資訊。
Go語言的鏈碼主要由以下方法組成:
//Chaincode interface must be implemented by all chaincodes.The fabric runs
//the transactions by calling these functions as specified.
type Chaincode interface{
//Init is called during Instantiate transaction after the chaincode container
//has been established for the first time,allowing the chaincode to
//initialize its internal data
Init(stub ChaincodeStubInterface)peer.Response
//Invoke is called to update or query the ledger in a proposal transaction.
//Updated state variables are not committed to the ledger until the
//transaction is committed.
Invoke(stub ChaincodeStubInterface)peer.Response
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70016646/viewspace-2933750/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CTO偷偷傳我的系統效能最佳化十大絕招(萬字乾貨)
- Python程式碼打包成可執行檔案的常用方法!
- 廣發證券基於分散式架構的新一代估值系統實踐
- Meta Force佛薩奇2.0版原始碼成熟系統開發詳細講解(技術說明)
- 帶您瞭解TRIZ理論解決問題的流程
- NFT數字藏品系統開發原始碼部署丨NFT鏈遊元宇宙遊戲系統開發原始碼搭建
- 區塊鏈專案技術開發(公鏈、礦機、交易所、DAPP)成熟技術系統開發
- 泰山眾籌商城開發、泰山眾籌DAPP系統開發、泰山眾籌原始碼部署開發
- 低程式碼開發平臺 開啟數字化轉型普惠之門
- SaaS CRM系統的四大優勢
- 實時渲染技術在VR/AR眼鏡中檢視CATIA3D模型
- 智勝空天·安全護航 | 無人機系統安全問題和防護技術
- wixtoolset visualstudio 2017打包流程(1)
- OMG&秒針系統:成年95後消費趨勢研究(附下載)
- 中國電信:6G願景與技術白皮書(附下載)
- 阿拉丁研究院:2022年度小程式網際網路發展白皮書(附下載)
- AARP報告:2023年技術趨勢和50歲以上成年人