- Hyperledger Cookbook
- Xun (Brian) Wu Chuanfeng Zhang Andrew Zhang
- 139字
- 2021-06-24 14:59:38
The Init function
The implementation of our Init function is as follows:
func (c *AssetMgr) Init(stub shim.ChaincodeStubInterface) pb.Response {
args := stub.GetStringArgs()
if len(args) != 3 {
return shim.Error("Incorrect arguments. Expecting a key and a value")
}
assetId := args[0]
assetType := args[1]
deviceId := args[2]
//create asset
assetData := OrgAsset{
Id: assetId,
AssetType: assetType,
Status: "START",
Location: "N/A",
DeviceId: deviceId,
Comment: "Initialized asset",
From: "N/A",
To: "N/A"}
assetBytes, _ := json.Marshal(assetData)
assetErr := stub.PutState(assetId, assetBytes)
if assetErr != nil {
return shim.Error(fmt.Sprintf("Failed to create asset: %s", args[0]))
}
return shim.Success(nil)
}
func (c *AssetMgr) Init(stub shim.ChaincodeStubInterface) pb.Response {
args := stub.GetStringArgs()
assetId := args[0] assetType := args[1] deviceId := args[2]
//create asset
assetData := OrgAsset{Id: assetId,AssetType:
assetType, Status: "START",Location: "N/A",DeviceId:
deviceId,Comment: "Initialized asset",From: "N/A", To: "N/A"}
assetBytes, _ := json.Marshal(assetData)
assetErr := stub.PutState(assetId, assetBytes)
…
return shim.Success(nil)
}
推薦閱讀
- 走進奇妙的數(shù)學(xué)世界(小學(xué)一二年級)
- 有限自動機理論
- The Modern C# Challenge
- 紅發(fā)克拉拉的數(shù)學(xué)奇想
- 別說你不懂?dāng)?shù)學(xué)
- 證明與布丁
- 線性代數(shù)同步精講及練習(xí)
- 高等數(shù)學(xué)習(xí)題全解與學(xué)習(xí)指導(dǎo)(下冊)
- 概率論與數(shù)理統(tǒng)計
- 黎曼猜想漫談:一場攀登數(shù)學(xué)高峰的天才盛宴
- 數(shù)學(xué)故事總動員
- 文化偉人代表作圖釋書系:幾何原本
- 數(shù)書九章
- 2019年管理類專業(yè)學(xué)位聯(lián)考綜合能力考試數(shù)學(xué)精選500題(20套全真試卷及詳解)
- 線性代數(shù)